code: def test_distribute_tensor(self):
      device_mesh = DeviceMesh(
          self.device_type, list(range(self.world_size))
      )
      shard_spec = [Shard(0)]
  
      for requires_grad in [True, False]:
          tensor_to_shard = torch.randn(
              3 * self.world_size, 3, requires_grad=requires_grad
          )
          dist_tensor = distribute_tensor(
              tensor_to_shard, device_mesh, shard_spec
          )
          self.assertEqual(
              dist_tensor.size(), torch.Size([3 * self.world_size, 3])
          )
          local_tensor = dist_tensor.to_local()
          self.assertEqual(local_tensor.size(), torch.Size([3, 3]))
          if requires_grad:
              self.assertTrue(dist_tensor.requires_grad)
              self.assertTrue(dist_tensor.is_leaf)
  
      # test negative dim
      shard_minus_spec = [Shard(-1)]
      tensor_to_shard = torch.randn(3, 3 * self.world_size)
      dist_tensor = distribute_tensor(
          tensor_to_shard, device_mesh, shard_minus_spec
      )
      self.assertEqual(dist_tensor.placements[0].dim, 1)
  
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 2 for calling the DTensorAPITest obj's underlying member method code with example usage: obj.test_distribute_tensor() without return types