code: def check_for_gpu(
      device: Union[int, torch.device, List[Union[int, torch.device]]]
  ):
      if isinstance(device, list):
          for did in device:
              check_for_gpu(did)
      elif device is None:
          return
      else:
          from allennlp.common.util import int_to_device
  
          device = int_to_device(device)
          if device != torch.device("cpu"):
              num_devices_available = cuda.device_count()
              if num_devices_available == 0:
                  raise ConfigurationError(
                      "Experiment specified a GPU but none is available;"
                      " if you want to run on CPU use the override"
                      " 'trainer.cuda_device=-1' in the json config file."
                  )
              elif device.index >= num_devices_available:
                  raise ConfigurationError(
                      f"Experiment specified GPU device {device.index}"
                      f" but there are only {num_devices_available} devices "
                      f" available."
                  )
  
file_path: allennlp/allennlp/common/checks.py
imports: import logging
  import re
  import subprocess
  from typing import Any, List, Tuple, Union
  import torch
  from torch import cuda
label_desc: Use image node_id 4 for calling a global function with example usage: check_for_gpu(device) without return types