code: def module_shape_inference_hook(
      module: nn.Module,
      input: Any,
      output: Any,
      is_leaf: Callable[[nn.Module], bool] | None = None,
      save_io_callback: Callable[..., None] | None = None,
  ) -> Any:
      """
      A hook that runs the shape inference on the module.
      The hook can't process keyword arguments due to the limitation of PyTorch.
      But I think it will be resolved `soon <https://github.com/pytorch/pytorch/pull/89389>`__.
      """
      result = _module_shape_inference_impl(
          module, output, *input, is_leaf=is_leaf
      )
  
      if save_io_callback is not None:
          save_io_callback(
              extract_shape_info(input), extract_shape_info(result)
          )
  
      return result
  
imports: from __future__ import annotations
  import functools
  import logging
  import traceback
  from typing import Union, Tuple, Callable, Iterable, Any, NamedTuple, Dict, cast, overload
  import torch
  from torch import nn
  from torch.utils.hooks import RemovableHandle
  from nni.mutable import MutableExpression, Mutable, LabeledMutable, Sample, SampleValidationError
  from nni.mutable.mutable import _mutable_equal
  from .misc import is_leaf_module, argument_in_spec
label_desc: Use image node_id 6 for calling a global function with example usage: module_shape_inference_hook(module, input, output, is_leaf, save_io_callback) and returns: result