code: def test_distribute_module_meta(self):
      # If  the model is too big, the user may first the create entire model on the meta device and then initialize
      # it on the device in the partition function.
      device_mesh = DeviceMesh(
          self.device_type, list(range(self.world_size))
      )
  
      # fully shard all parameters on dim 0
      module_to_shard = MyModel(5 * self.world_size, 20, device="meta")
  
      shard_spec = [Shard(0)]
  
      def shard_fn(name, module, device_mesh):
          for param_name, param in module._parameters.items():
              dist_param = distribute_tensor(
                  param, device_mesh, shard_spec
              )
              dist_param = torch.empty_like(
                  dist_param, device=device_mesh.device_type
              )
              module.register_parameter(
                  param_name, torch.nn.Parameter(dist_param)
              )
  
      sharded_module = distribute_module(
          module_to_shard, device_mesh, shard_fn
      )
      for param in sharded_module.parameters():
          self.assertIsInstance(param, DTensor)
          self.assertFalse(param.is_meta)
          self.assertTrue(param.device.type == device_mesh.device_type)
  
file_path: pytorch/test/distributed/_tensor/test_api.py
imports: import torch
  import torch.nn
  from torch.distributed._tensor import DeviceMesh, distribute_module, distribute_tensor, DTensor, Replicate, Shard
  from torch.testing._internal.common_utils import run_tests
  from torch.testing._internal.distributed._tensor.common_dtensor import DTensorTestBase, with_comms
label_desc: Use image node_id 7 for calling the DTensorAPITest obj's underlying member method code with example usage: obj.test_distribute_module_meta() without return types