code: def merge_global_slice_with_shape(global_slice, actual_shape, key):
      def _merge_slice(dim_slice, dim_size):
          if isinstance(dim_slice, slice):
              assert (
                  dim_slice.start < dim_size
              ), f"Got empty slice for ShardedTensor {key} ({dim_slice}, {dim_size})"
              if dim_slice.stop > dim_size:
                  dim_slice = slice(
                      dim_slice.start, dim_size, dim_slice.step
                  )
          return dim_slice
  
      assert len(global_slice) == len(actual_shape), (
          global_slice,
          actual_shape,
          key,
      )
      return tuple(
          starmap(_merge_slice, zip(global_slice, actual_shape))
      )
  
imports: from functools import partial
  from itertools import starmap
  from logging import getLogger
  from pathlib import Path
  import tensorstore
  import torch
  from ..core import CheckpointingException
  from ..dict_utils import dict_list_map_inplace
  from ..mapping import ShardedStateDict, ShardedTensor
  from .base import LoadShardedStrategy, StrategyAction, default_strategies
  from .zarr import load_zarr_based_sharded_metadata, numpy_to_torch_dtype_dict, postprocess_numpy_array
label_desc: Use image node_id 1 for calling a global function with example usage: merge_global_slice_with_shape(global_slice, actual_shape, key) and returns: tuple, dim_slice