code: def least_used_cuda_device() -> Generator:
      """Contextmanager for automatically selecting the cuda device
      with the least allocated memory"""
      try:
          mem_allocs = get_cuda_max_memory_allocations()
          least_used_device = torch.argmin(mem_allocs).item()
      except RuntimeError:  # raised if cuda has not been initialized
          # here we can just randomize
          least_used_device = random.randint(
              0, torch.cuda.device_count() - 1
          )
      with torch.cuda.device(least_used_device):
          yield
  
imports: import random
  from contextlib import contextmanager
  from typing import Generator
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: least_used_cuda_device() without return types