code: def test_from_local(self):
      device_mesh = DeviceMesh(
          self.device_type, list(range(self.world_size))
      )
      placements = [Shard(0)]
      local_tensor = torch.randn(3, 3)
      sharded_tensor = DTensor.from_local(
          local_tensor, device_mesh, placements
      )
      self.assertEqual(
          sharded_tensor.size(), torch.Size([self.world_size * 3, 3])
      )
  
      replica_spec = [Replicate()]
      ddp_tensor = DTensor.from_local(
          local_tensor, device_mesh, replica_spec
      )
      self.assertEqual(ddp_tensor.size(), local_tensor.size())
  
      partial_spec = [_Partial()]
      partial_tensor = DTensor.from_local(
          local_tensor, device_mesh, partial_spec
      )
      self.assertEqual(partial_tensor.size(), local_tensor.size())
  
      # test dist tensor works with torch.Tensor during backwards
      local_tensor_with_grad = torch.randn(3, 3, requires_grad=True)
      # do some operations on local tensor
      local_tensor_temp = local_tensor_with_grad * 3
      # create the dist tensor with non leaf local tensor, dist tensor created
      # should also be non leaf node
      dist_tensor = DTensor.from_local(
          local_tensor_temp, device_mesh, placements
      )
      self.assertFalse(dist_tensor.is_leaf)
      # do some random operations on dist tensor
      output = dist_tensor * 3
      self.assertIsInstance(output, DTensor)
      # trigger .backward() on dist tensor directly
      local_grad = torch.ones(3, 3)
      grad_output = DTensor.from_local(
          local_grad, device_mesh, placements
      )
      # run backward directly on dist tensor
      output.backward(grad_output)
      # check it gradients flow back to original torch.Tensor
      self.assertIsNotNone(local_tensor_with_grad.grad)
      expected_grad = torch.ones(3, 3) * 9
      self.assertEqual(local_tensor_with_grad.grad, expected_grad)
  
imports: import torch
  import torch.nn.functional
  from numpy.testing import assert_array_equal
  from torch.distributed._functional_collectives import AsyncCollectiveTensor
  from torch.distributed._tensor import DeviceMesh, distribute_tensor, DTensor, init_device_mesh
  from torch.distributed._tensor.placement_types import _Partial, Replicate, Shard
  from torch.distributed.tensor.parallel import ColwiseParallel, parallelize_module, RowwiseParallel
  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 5 for calling the DTensorTest obj's underlying member method code with example usage: obj.test_from_local() without return types