code: def _validate_sharding_for_key(
      rank_sharding: List[Tuple[int, ShardedTensor]]
  ):
      some_rank_shard = rank_sharding[0][1]
      global_shape = some_rank_shard.global_shape
      local_shape = some_rank_shard.local_shape
      dtype = some_rank_shard.dtype
      has_flattened_range = some_rank_shard.flattened_range is not None
      for rank, sharding in rank_sharding:
          assert sharding.dtype == dtype, (
              sharding.dtype,
              dtype,
              some_rank_shard,
          )
          assert sharding.global_shape == global_shape, (
              sharding.global_shape,
              global_shape,
              some_rank_shard,
          )
          assert sharding.local_shape == local_shape, (
              sharding.local_shape,
              local_shape,
              some_rank_shard,
          )
          assert (
              sharding.flattened_range is not None
          ) == has_flattened_range, (
              (sharding.flattened_range is not None),
              has_flattened_range,
              some_rank_shard,
          )
  
      shard_access_cnt = _compute_shards_access(rank_sharding)
      if has_flattened_range:
          map_reduce(
              rank_sharding,
              lambda x: x[1].global_offset,
              lambda x: x[1],
              _validate_sharding_for_key_flattened,
          )
      else:
          if not torch.all(shard_access_cnt == 1):
              logger.error(
                  f"Invalid access pattern for {rank_sharding[0][1]}: {shard_access_cnt}"
              )
              raise CheckpointingException(
                  f"Invalid access pattern for {rank_sharding[0][1]}"
              )
  
imports: import logging
  import os
  from collections import Counter, defaultdict
  from itertools import chain
  from pathlib import Path
  from typing import Iterable, List, Optional, Tuple, Union
  import numpy
  import torch
  from .core import CheckpointingConfig, maybe_load_config, save_config
  from .dict_utils import dict_list_map_inplace, diff, extract_matching_values, map_reduce, merge, nested_values
  from .mapping import CheckpointingException, ShardedObject, ShardedStateDict, ShardedTensor, ShardedTensorFactory, StateDict, apply_factories, apply_factory_merges, is_main_replica
  from .strategies.base import LoadCommonStrategy, LoadShardedStrategy, SaveCommonStrategy, SaveShardedStrategy, StrategyAction, get_default_strategy
  from .utils import extract_sharded_tensors, extract_sharded_tensors_or_nonpersistent
label_desc: Use image node_id 11 for calling a global function with example usage: _validate_sharding_for_key(rank_sharding) without return types