code: def consume_prefix_in_state_dict_if_present_not_in_place(
      state_dict: Dict[str, Any], prefix: str
  ) -> Dict[str, Any]:
      """Strip the prefix in state_dict, if any and return a new dict.
  
      Adapted from https://github.com/pytorch/pytorch/blob/\
  c18da597e0bb1c1aecc97c77a73fed1849057fa4/torch/nn/modules/utils.py
      The original method modified the dict in-place.
  
      Args:
          state_dict: a state-dict to be loaded to the model.
          prefix: prefix.
  
      """
      copied = False
  
      for key in state_dict:
          if key.startswith(prefix):
              newkey = key[len(prefix) :]
              if not copied:
                  # We are doing shallow copies here, so the performance
                  # impact should be negligible anyway, but this is
                  # a simple optimization.
                  state_dict = state_dict.copy()
                  copied = True
              state_dict[newkey] = state_dict.pop(key)
  
      if "_metadata" in state_dict:
          state_dict["_metadata"] = state_dict["_metadata"].copy()
          metadata = state_dict["_metadata"]
          for key in metadata:
              if len(key) == 0:
                  continue
              newkey = key[len(prefix) :]
              metadata[newkey] = metadata.pop(key)
  
      return state_dict
  
file_path: ray/python/ray/air/_internal/torch_utils.py
imports: import os
  import warnings
  from typing import Dict, List, Optional, Union, Any
  import numpy
  import pandas
  import torch
  import ray
  from ray.air.util.data_batch_conversion import _unwrap_ndarray_object_type_if_needed
label_desc: Use image node_id 7 for calling a global function with example usage: consume_prefix_in_state_dict_if_present_not_in_place(state_dict, prefix) and returns: state_dict