code: def generate_cuda_mapping(
      placement: Dict[Node, Device]
  ) -> Dict[Device, int]:
      """
      Since CUDA_VISIBLE_DEVICES will be set to the list of real GPU ID,
      we need to remap the GPU ID when generating code to match them correctly.
      For example, when CUDA_VISIBLE_DEVICES="0,3", we need to use "cuda:0", "cuda:1" in the generated code.
      """
      unique_devices = sorted(
          list(
              set(
                  [
                      e
                      for e in placement.values()
                      if isinstance(e, GPUDevice)
                  ]
              )
          )
      )
      node_gpu_cnt = {}
      cuda_remapped_id = {}
      for d in unique_devices:
          if d.node_id not in node_gpu_cnt:
              node_gpu_cnt[d.node_id] = 0
          node_gpu_cnt[d.node_id] += 1
          cuda_remapped_id[d] = node_gpu_cnt[d.node_id] - 1
  
      return cuda_remapped_id
  
file_path: nni/nni/nas/space/pytorch/codegen.py
imports: import logging
  import re
  from typing import Dict, List, Tuple, Any, cast
  from nni.common.device import Device, GPUDevice
  from nni.nas.space.graph import IllegalGraphError, Edge, Graph, Node, GraphModelSpace
  from nni.nas.space.graph_op import PyTorchOperation
  from nni.nas.utils import STATE_DICT_PY_MAPPING
  from .op_def import ToDevice
label_desc: Use image node_id 5 for calling a global function with example usage: generate_cuda_mapping(placement) and returns: cuda_remapped_id