code: def get_paddle_device_id(device: Union[str, int]) -> int:
      """
      获得 ``device`` 的设备编号::
  
          >>> get_paddle_device_id("gpu:1")
          1
          >>> get_paddle_device_id("gpu")
          0
  
      请注意不要向这个函数中传入 ``cpu``。
  
      :param: device: 设备编号或设备名；
      :return: 设备对应的编号；
      """
      if isinstance(device, int):
          return device
  
      device = device.lower()
      if device == "cpu":
          raise ValueError("Cannot get device id from `cpu`.")
      elif device == "gpu":
          return 0
  
      match_res = re.match(r"gpu:\d+", device)
      if not match_res:
          raise ValueError(
              "The device must be a string which is like 'cpu', 'gpu', 'gpu:x', "
              f"not '{device}'"
          )
      device_id = device.split(":", 1)[1]
      device_id = int(device_id)
  
      return device_id
  
file_path: fastNLP/fastNLP/core/utils/paddle_utils.py
imports: import os
  import re
  from typing import Any, Optional, Union
  from fastNLP.envs.imports import _NEED_IMPORT_PADDLE
  from fastNLP.envs import FASTNLP_DISTRIBUTED_CHECK, FASTNLP_BACKEND_LAUNCH, USER_CUDA_VISIBLE_DEVICES
  from .utils import apply_to_collection
label_desc: Use image node_id 4 for calling a global function with example usage: get_paddle_device_id(device) and returns: device_id, device, int