code: def _materialize_meta_module(
      root_module: nn.Module,
      device_from_device_id: Optional[torch.device],
      ignored_modules: Set[nn.Module],
  ):
      # Run default meta device initialization
      materialization_device = device_from_device_id or torch.device(
          torch.cuda.current_device()
      )
      modules_to_materialize = _get_modules_to_materialize(
          root_module, ignored_modules
      )
      try:
          # Assume that each module's `reset_parameters()` only initializes its
          # own parameters and not those of its children
          with torch.no_grad():
              for module in modules_to_materialize:
                  # As a contract to the user, only call `reset_parameters()` if
                  # the module has directly managed parameters/buffers
                  module_state_iter = itertools.chain(
                      module.parameters(recurse=False),
                      module.buffers(recurse=False),
                  )
                  has_module_states = len(list(module_state_iter)) > 0
                  if has_module_states:
                      module.to_empty(
                          device=materialization_device, recurse=False
                      )
                      module.reset_parameters()  # type: ignore[operator]
      except BaseException as e:
          warnings.warn(
              "Unable to call `reset_parameters()` for module on meta "
              f"device with error {str(e)}. Please ensure that your module of"
              f"type {type(module)} implements a `reset_parameters()` method."
          )
          raise e
  
imports: import collections
  import itertools
  import os
  import warnings
  from typing import Any, Callable, Deque, Dict, Generator, Iterable, Iterator, List, no_type_check, Optional, Set, Tuple, Union
  import torch
  import torch.distributed
  import torch.distributed.fsdp._exec_order_utils
  import torch.distributed.fsdp._traversal_utils
  import torch.distributed.fsdp.fully_sharded_data_parallel
  import torch.nn
  from torch.distributed.algorithms._comm_hooks import default_hooks
  from torch.distributed.device_mesh import _mesh_resources, DeviceMesh
  from torch.distributed.distributed_c10d import _get_default_group
  from torch.distributed.fsdp._common_utils import _FSDPDeviceHandle, _FSDPState, _get_module_fsdp_state, _is_fsdp_flattened, _named_parameters_with_duplicates, clean_tensor_name, TrainingState
  from torch.distributed.fsdp._flat_param import _FSDP_USE_FULL_PREC_IN_EVAL, FlatParameter, FlatParamHandle, HandleShardingStrategy
  from torch.distributed.fsdp._limiter_utils import _FreeEventQueue
  from torch.distributed.fsdp.api import BackwardPrefetch, CPUOffload, FullOptimStateDictConfig, FullStateDictConfig, MixedPrecision, ShardingStrategy, StateDictConfig, StateDictType
  from torch.distributed.fsdp.wrap import _Policy
  from torch.distributed.tensor.parallel.fsdp import DTensorExtensions
  from torch.distributed.utils import _sync_params_and_buffers
  from torch.utils._python_dispatch import is_traceable_wrapper_subclass
  from torch.utils.hooks import RemovableHandle
label_desc: Use image node_id 27 for calling a global function with example usage: _materialize_meta_module(root_module, device_from_device_id, ignored_modules) without return types