code: def save(
      sharded_state_dict: ShardedStateDict,
      checkpoint_dir: str,
      sharded_strategy: Union[SaveShardedStrategy, None] = None,
      common_strategy: Union[SaveCommonStrategy, None] = None,
      validate_access_integrity: bool = True,
  ):
      """Saving entrypoint.
  
      Extracts ShardedTensors from the given state dict. Rank 0 saves the
      "regular" part of the checkpoint to common torch file.
      The ShardedTensors are saved according to a strategy specified by the
      config.
  
      Arguments:
          sharded_state_dict (ShardedStateDict): state dict of the populated with
              ShardedTensors. Used as a mapping to determine how local tensors
              should be saved as global tensors in the checkpoint.
          checkpoint_dir (str): directory to save the checkpoint to
          sharded_strategy (SaveShardedStrategy, optional): configures sharded tensors saving behavior and backend
          common_strategy (SaveCommonStrategy, optional): configures common data saving behavior and backend
          validate_access_integrity (bool default = True): checks if each tensor shard is accessed
              exactly once (as main replica) by some process
      """
      checkpoint_dir = Path(checkpoint_dir)
  
      if torch.distributed.get_rank() == 0:
          if not checkpoint_dir.exists():
              raise CheckpointingException(
                  f"Checkpoint destination directory does not exist: {checkpoint_dir}"
              )
  
          if next(checkpoint_dir.iterdir(), None) is not None:
              raise CheckpointingException(
                  f"Checkpoint destination directory ({checkpoint_dir}) is not empty"
              )
  
      if common_strategy is not None:
          raise NotImplementedError(
              "The only supported common strategy is torch"
          )
  
      if sharded_strategy is None:
          sharded_strategy = get_default_strategy(
              StrategyAction.SAVE_SHARDED, "zarr", 1
          )
  
      apply_factories(sharded_state_dict)
      (
          sharded_state_dict,
          state_dict,
      ) = extract_sharded_tensors_or_nonpersistent(sharded_state_dict)
      sharded_state_dict, _ = extract_sharded_tensors(
          sharded_state_dict
      )
      sharded_tensors = list(nested_values(sharded_state_dict))
      if validate_access_integrity:
          validate_sharding_integrity(sharded_tensors)
  
      _save_common_dict(state_dict, checkpoint_dir, True)
  
      sharded_strategy.save(sharded_tensors, checkpoint_dir)
      save_config(
          CheckpointingConfig(
              sharded_strategy.backend, sharded_strategy.version
          ),
          checkpoint_dir,
      )
  
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 7 for calling a global function with example usage: save(sharded_state_dict, checkpoint_dir, sharded_strategy, common_strategy, validate_access_integrity) without return types