class_docstr: Allows copying of DistributedModelParallel module to a target device.
  
  Example::
  
      # Copying model to CPU.
  
      m = DistributedModelParallel(m)
      with sharded_model_copy("cpu"):
          m_cpu = copy.deepcopy(m)
class_docstr_tok: ["Allows","copying","of","DistributedModelParallel","module","to","a","target","device",".","Example",":",":","#","Copying","model","to","CPU",".","m","=","DistributedModelParallel","(","m",")","with","sharded_model_copy","(","``","cpu","''",")",":","m_cpu","=","copy.deepcopy","(","m",")"]
code: def __enter__(self) -> None:
      # pyre-ignore [16]
      self.t_copy_save_ = torch.Tensor.__deepcopy__
      # pyre-ignore [16]
      self.p_copy_save_ = torch.nn.Parameter.__deepcopy__
  
      device = self.device
  
      # pyre-ignore [2, 3, 53]
      def _tensor_copy(tensor, memo):
          if tensor.device != device:
              return tensor.detach().to(device)
          else:
              return tensor.detach().clone()
  
      # pyre-ignore [2, 3]
      def _no_copy(obj, memo):
          return obj
  
      _copy_or_not = (
          _tensor_copy if self.device is not None else _no_copy
      )
  
      # pyre-ignore [2, 3, 53]
      def _param_copy(param, memo):
          return torch.nn.Parameter(
              _copy_or_not(param, memo),
              requires_grad=param.requires_grad,
          )
  
      torch.Tensor.__deepcopy__ = _copy_or_not
      torch.nn.Parameter.__deepcopy__ = _param_copy
      # pyre-fixme[16]: `Type` has no attribute `__deepcopy__`.
      torch._C._distributed_c10d.ProcessGroupNCCL.__deepcopy__ = (
          _no_copy
      )
      # pyre-fixme[16]: `Type` has no attribute `__deepcopy__`.
      torch._C._distributed_c10d.ProcessGroupGloo.__deepcopy__ = (
          _no_copy
      )
      # pyre-fixme[16]: `Type` has no attribute `__deepcopy__`.
      torch._C._distributed_c10d.Work.__deepcopy__ = _no_copy
      # pyre-ignore [16]
      torch.cuda.streams.Stream.__deepcopy__ = _no_copy
  
imports: import copy
  import logging
  from collections import OrderedDict
  from itertools import accumulate
  from typing import Any, Dict, List, Optional, Set, Type, TypeVar, Union
  import torch
  from fbgemm_gpu.split_embedding_configs import EmbOptimType
  from torch import nn
  from torchrec import optim
  from torchrec.distributed.embedding_types import EmbeddingComputeKernel
  from torchrec.distributed.types import DataType, ParameterSharding, ShardedModule, ShardingType
  from torchrec.modules.embedding_configs import data_type_to_sparse_type
  from torchrec.types import CopyMixIn
label_desc: Use image node_id 2 for calling the sharded_model_copy obj's underlying member method code with example usage: obj.__enter__() and returns: obj, torch, tensor, tensor