code: def test_global_plan(self):
      def create_data(rank):
          with with_dist(rank=rank, world_size=4):
              tensor = torch.rand(10)
              val = [1, 2, 3]
              st = create_sharded_tensor(
                  rank=rank, world_size=4, shards_per_rank=1
              )
              state_dict = {"tensor": tensor, "value": val, "st": st}
              return create_default_local_save_plan(
                  state_dict, rank == 0
              )
  
      all_plans = [
          create_data(0),
          create_data(1),
          create_data(2),
          create_data(3),
      ]
      all_plans = dedup_tensors(all_plans)
      final_plans, metadata = create_default_global_save_plan(
          all_plans=all_plans
      )
  
      # The default global plan updates all indexes to include hints
      for new_plan, old_plan in zip(final_plans, all_plans):
          for new_item, old_item in zip(new_plan.items, old_plan.items):
              self.assertEqual(new_item.index, old_item.index)
              self.assertEqual(new_item.type, old_item.type)
              self.assertEqual(
                  new_item.tensor_data, old_item.tensor_data
              )
              self.assertIn(
                  new_item.index.fqn, metadata.state_dict_metadata
              )
  
              item_md = metadata.state_dict_metadata[new_item.index.fqn]
              if new_item.type == WriteItemType.BYTE_IO:
                  self.assertTrue(
                      isinstance(item_md, BytesStorageMetadata)
                  )
              else:
                  self.assertTrue(
                      isinstance(item_md, TensorStorageMetadata)
                  )
                  self.assertEqual(
                      item_md.size, old_item.tensor_data.size
                  )
                  self.assertEqual(
                      item_md.properties,
                      old_item.tensor_data.properties,
                  )
  
                  self.assertIsNotNone(new_item.index.index)
                  # Make sure the hint is correct
                  self.assertEqual(
                      item_md.chunks[new_item.index.index],
                      old_item.tensor_data.chunk,
                  )
  
imports: import sys
  import torch
  from torch.distributed._shard.sharded_tensor import Shard, ShardedTensor, ShardedTensorMetadata, ShardMetadata
  from torch.distributed._shard.sharded_tensor.metadata import TensorProperties
  from torch.distributed.checkpoint._dedup_tensors import dedup_tensors
  from torch.distributed.checkpoint.default_planner import _create_default_local_metadata, create_default_global_save_plan, create_default_local_load_plan, create_default_local_save_plan
  from torch.distributed.checkpoint.metadata import BytesStorageMetadata, ChunkStorageMetadata, MetadataIndex, TensorStorageMetadata
  from torch.distributed.checkpoint.planner import LoadItemType, WriteItemType
  from torch.distributed.checkpoint.planner_helpers import create_read_items_for_chunk_list
  from torch.testing._internal.common_utils import run_tests, TEST_WITH_DEV_DBG_ASAN, TestCase
  from torch.testing._internal.distributed.distributed_utils import with_dist, with_fake_comms
label_desc: Use image node_id 2 for calling the TestSavePlan obj's underlying member method code with example usage: obj.test_global_plan() and returns: create_default_local_save_plan