code: def _convert_to_coloparam(
      param: torch.nn.Parameter,
      device: torch.device,
      dtype=torch.float,
      default_pg: Optional[ProcessGroup] = None,
      default_dist_spec: Optional[Any] = None,
  ) -> ColoParameter:
      if type(param) is ColoParameter:
          return param
      # detaching tensor is necessary for optimizers.
      requires_grad = param.requires_grad
      # param is the global tensor.
  
      if param.device.type == "meta":
          colo_param = ColoParameter(param, requires_grad=requires_grad)
      else:
          colo_param = ColoParameter(
              param.to(device=device, dtype=dtype),
              requires_grad=requires_grad,
          )
  
      # if default_shard_plan exists, shard the param during initialization.
      # This can reduce the model size after initialization.
      # NOTE() embedding usually can not be correctly sharded. So I use except to handle
      # the param that can not be sharded by the default plan
      if default_pg is not None:
          colo_param.set_process_group(default_pg)
  
      if default_dist_spec is not None:
          try:
              colo_param.set_dist_spec(default_dist_spec)
          except:
              pass
      return colo_param
  
file_path: ColossalAI/colossalai/legacy/zero/gemini/colo_init_context.py
imports: from typing import Any, Iterator, Optional, Tuple, Union
  import torch
  from torch import nn
  from colossalai.legacy.tensor import ProcessGroup
  from colossalai.tensor import ColoParameter, ColoTensor
  from colossalai.utils.model.utils import InsertPostInitMethodToModuleSubClasses
label_desc: Use image node_id 2 for calling a global function with example usage: _convert_to_coloparam(param, device, dtype, default_pg, default_dist_spec) and returns: colo_param, param