code: def load_param_groups_into_optimizer(
      optimizer: Optimizer, param_group_path: str
  ) -> dict:
      """
      Load information of param_groups into an initialized optimizer.
      """
  
      # Load list of param_groups from given file path.
      # The params in saved_groups are in the form of integer indices.
      saved_groups = torch.load(
          param_group_path, map_location=torch.device("cpu")
      )
      if not isinstance(saved_groups, List):
          raise ValueError(
              f"The param_groups saved at {param_group_path} is not of List type"
          )
  
      # The params in param_groups are in the form of pytorch tensors.
      # For more details, please view source code of Optimizer class in pytorch.
      param_groups = optimizer.param_groups
  
      # Check the compatibility of saved_groups and param_groups.
      if len(param_groups) != len(saved_groups):
          raise ValueError(
              "loaded state dict has a different number of original parameter groups"
          )
      param_lens = (len(g["params"]) for g in param_groups)
      saved_lens = (len(g["params"]) for g in saved_groups)
      if any(
          p_len != s_len for p_len, s_len in zip(param_lens, saved_lens)
      ):
          raise ValueError(
              "loaded state dict contains a parameter group "
              "that doesn't match the size of optimizer's group"
          )
  
      # Creating mapping from id to parameters.
      id_map = {
          old_id: p
          for old_id, p in zip(
              chain.from_iterable((g["params"] for g in saved_groups)),
              chain.from_iterable((g["params"] for g in param_groups)),
          )
      }
  
      # Update parameter groups, setting their 'params' value.
      def update_group(group, new_group):
          new_group["params"] = group["params"]
          return new_group
  
      updated_groups = [
          update_group(g, ng)
          for g, ng in zip(param_groups, saved_groups)
      ]
  
      optimizer.__dict__.update({"param_groups": updated_groups})
      return id_map
  
imports: import os
  import re
  from collections import abc
  from collections import defaultdict
  from itertools import chain
  from pathlib import Path
  from typing import Iterator, List, Mapping, Optional, OrderedDict, Tuple
  import torch
  import torch.nn
  from packaging.version import Version
  from torch.optim import Optimizer
  from torch.utils._pytree import tree_map
  from colossalai.tensor.d_tensor import is_customized_distributed_tensor, is_distributed_tensor, to_global, to_global_for_customized_distributed_tensor
label_desc: Use image node_id 20 for calling a global function with example usage: load_param_groups_into_optimizer(optimizer, param_group_path) and returns: id_map, new_group