code: def replicate(
      module: nn.Module,
      ignored_modules: Optional[Iterable[torch.nn.Module]] = None,
      **kwargs,
  ) -> nn.Module:
      r"""Replicates a module
  
      Args:
          module (torch.nn.Module): module to replicate
  
      Example::
          >>> # xdoctest: +REQUIRES(module:torch._C._distributed_c10d)
          >>> module = nn.Linear(3, 3)
          >>> replicate(module)
      """
      torch._C._log_api_usage_once("torch.distributed.replicate")
  
      # TODO(fegin): using kwargs is not a good idea if we would like to make
      # replicate a formal API to replace DDP.
      if "device_id" in kwargs:
          if not isinstance(kwargs["device_id"], (int, torch.device)):
              raise RuntimeError(
                  "Expected device_id to be int or torch.device, "
                  f"but got {type(kwargs['device_id'])}"
              )
  
      if ignored_modules is None:
          ignored_modules = {}
      else:
          ignored_modules = set(ignored_modules)
      replicate.state(module).init(module, ignored_modules, **kwargs)
  
      return module
  
file_path: pytorch/torch/distributed/_composable/replicate.py
imports: import weakref
  from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
  import torch
  import torch.nn
  from torch.distributed._composable_state import _State
  from torch.nn.parallel import DistributedDataParallel
  from .contract import _get_registry, contract
label_desc: Use image node_id 1 for calling a global function with example usage: replicate(module, ignored_modules) and returns: module