code: def _verify_checkpoint_and_load_strategy(
      checkpoint_dir: str,
      sharded_strategy: Optional[LoadShardedStrategy] = None,
  ) -> LoadShardedStrategy:
      """Verifies if checkpoint metadata exists and matches given strategy.
  
      Args:
          checkpoint_dir (str): checkpoint directory
          sharded_strategy (LoadShardedStrategy, optional): load strategy to be verified
              if compatible with the checkpoint content. If None, the default load strategy
              for the checkpoint backend will be returned.
      """
      if not Path(checkpoint_dir).exists():
          raise CheckpointingException(
              f"Checkpoint directory {checkpoint_dir} does not exist"
          )
  
      saved_config = maybe_load_config(checkpoint_dir)
      if saved_config is None:
          raise CheckpointingException(
              f"{checkpoint_dir} is not a distributed checkpoint"
          )
  
      if sharded_strategy is None:
          sharded_strategy = get_default_strategy(
              StrategyAction.LOAD_SHARDED,
              saved_config.sharded_backend,
              saved_config.sharded_backend_version,
          )
      else:
          # TODO: implement consistency checks here
          pass
  
      return sharded_strategy
  
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 2 for calling a global function with example usage: _verify_checkpoint_and_load_strategy(checkpoint_dir, sharded_strategy) and returns: sharded_strategy