class_docstr: Test DCP reshard for DTensor with placements changes and without world_size change and mesh_tensor change.
class_docstr_tok: ["Test","DCP","reshard","for","DTensor","with","placements","changes","and","without","world_size","change","and","mesh_tensor","change","."]
code: def test_2d_to_2d_reshard_placement_change(self) -> None:
      CHECKPOINT_DIR = self.temp_dir
      for two_d_to_two_d_placements in TWO_D_TO_TWO_D_PLACEMENTS:
          original_placement, new_placement = two_d_to_two_d_placements
  
          global_tensor = torch.arange(16, dtype=torch.float).view(4, 4)
          mesh_shape = (2, self.world_size // 2)
          mesh_2d = init_device_mesh(self.device_type, mesh_shape)
          dtensor = distribute_tensor(
              global_tensor,
              mesh_2d,
              placements=original_placement,
          )
          state_dict_to_save = {"dtensor": dtensor}
  
          dist_cp.save_state_dict(
              state_dict=state_dict_to_save,
              storage_writer=dist_cp.FileSystemWriter(
                  path=CHECKPOINT_DIR
              ),
              planner=dist_cp.DefaultSavePlanner(),
          )
  
          zero_dtensor = zeros(
              [4, 4], device_mesh=mesh_2d, placements=new_placement
          )
          state_dict_to_load = {"dtensor": zero_dtensor}
  
          dist_cp.load_state_dict(
              state_dict=state_dict_to_load,
              storage_reader=dist_cp.FileSystemReader(CHECKPOINT_DIR),
              planner=dist_cp.DefaultLoadPlanner(),
          )
  
          state_dict_to_load["dtensor"] = state_dict_to_load[
              "dtensor"
          ].redistribute(
              mesh_2d,
              placements=[Replicate(), Replicate()],
          )
          self.assertEqual(
              global_tensor, state_dict_to_load["dtensor"].to_local()
          )
  
          state_dict_to_load["dtensor"] = state_dict_to_load[
              "dtensor"
          ].redistribute(
              mesh_2d,
              placements=original_placement,
          )
          self.assertEqual(
              state_dict_to_save["dtensor"].to_local(),
              state_dict_to_load["dtensor"].to_local(),
          )
  
file_path: pytorch/test/distributed/checkpoint/test_dtensor_resharding.py
imports: import torch
  import torch.distributed.checkpoint
  from torch.distributed._tensor import distribute_tensor, init_device_mesh, Replicate, Shard, zeros
  from torch.testing._internal.common_utils import run_tests
  from torch.testing._internal.distributed._tensor.common_dtensor import DTensorTestBase, skip_if_lt_x_gpu, with_comms
  from torch.testing._internal.distributed.checkpoint_utils import with_temp_dir
label_desc: Use image node_id 2 for calling the TestDTensorReshardPlacementChange obj's underlying member method code with example usage: obj.test_2d_to_2d_reshard_placement_change() without return types