code: def extract_module_or_tensor_callable(
      module_or_callable: Union[
          Callable[[], torch.nn.Module],
          torch.nn.Module,
          Callable[[torch.Tensor], torch.Tensor],
      ]
  ) -> Union[torch.nn.Module, Callable[[torch.Tensor], torch.Tensor]]:
      try:
          # pyre-ignore[20]: PositionalOnly call expects argument in position 0
          module = module_or_callable()
          if isinstance(module, torch.nn.Module):
              return module
          else:
              raise ValueError(
                  "Expected callable that takes no input to return "
                  "a torch.nn.Module, but got: {}".format(type(module))
              )
      except TypeError as e:
          if "required positional argument" in str(e):
              # pyre-ignore[7]: Expected `Union[typing.Callable[[torch.Tensor], torch.Tensor], torch.nn.Module]`
              return module_or_callable
          raise
  
file_path: torchrec/torchrec/modules/utils.py
imports: import copy
  from typing import Callable, Iterable, Tuple, Union
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: extract_module_or_tensor_callable(module_or_callable) and returns: module, module_or_callable