code: def get_module_name(cls_or_func):
      module_name = cls_or_func.__module__
      if module_name == "__main__":
          # infer the module name with inspect
          for frm in inspect.stack():
              module = inspect.getmodule(frm[0])
              if module is not None and module.__name__ == "__main__":
                  # main module found
                  main_file_path = Path(
                      cast(str, inspect.getsourcefile(frm[0]))
                  )
                  if not Path().samefile(main_file_path.parent):
                      raise RuntimeError(
                          f'You are using "{main_file_path}" to launch your experiment, '
                          f'please launch the experiment under the directory where "{main_file_path.name}" is located.'
                      )
                  module_name = main_file_path.stem
                  break
      if module_name == "__main__":
          warnings.warn(
              "Callstack exhausted but main module still not found. This will probably cause issues that the "
              "function/class cannot be imported."
          )
  
      # NOTE: this is hacky. As torchscript retrieves LSTM's source code to do something.
      # to make LSTM's source code can be found, we should assign original LSTM's __module__ to
      # the wrapped LSTM's __module__
      # TODO: find out all the modules that have the same requirement as LSTM
      if (
          f"{cls_or_func.__module__}.{cls_or_func.__name__}"
          == "torch.nn.modules.rnn.LSTM"
      ):
          module_name = cls_or_func.__module__
  
      return module_name
  
file_path: nni/nni/nas/utils/misc.py
imports: import inspect
  import itertools
  import warnings
  from collections import defaultdict
  from contextlib import contextmanager
  from typing import Any, List, cast
  from pathlib import Path
label_desc: Use image node_id 2 for calling a global function with example usage: get_module_name(cls_or_func) and returns: module_name