code: def set_per_process_memory_fraction(
      fraction, device: Union[Device, int] = None
  ) -> None:
      r"""Set memory fraction for a process.
  
      The fraction is used to limit an caching allocator to allocated memory on a CUDA device.
      The allowed value equals the total visible memory multiplied fraction.
      If trying to allocate more than the allowed value in a process, will raise an out of
      memory error in allocator.
  
      Args:
          fraction(float): Range: 0~1. Allowed memory equals total_memory * fraction.
          device (torch.device or int, optional): selected device. If it is
              ``None`` the default CUDA device is used.
      .. note::
          In general, the total available free memory is less than the total capacity.
      """
      _lazy_init()
      if device is None:
          device = torch.cuda.current_device()
      device = _get_device_index(device)
      if not isinstance(fraction, float):
          raise TypeError(
              "Invalid type for fraction argument, must be `float`"
          )
      if fraction < 0 or fraction > 1:
          raise ValueError(
              f"Invalid fraction value: {fraction}. Allowed range: 0~1"
          )
  
      torch._C._cuda_setMemoryFraction(fraction, device)
  
imports: import collections
  import contextlib
  import ctypes
  import pickle
  import sys
  import warnings
  from inspect import signature
  from typing import Any, Dict, Optional, Tuple, Union
  import torch
  from torch import _C
  from torch.types import Device
  from .None import _get_device_index, _get_nvml_device_index, _lazy_init, is_initialized
  from ._memory_viz import memory, segments
  from ._utils import _dummy_type
label_desc: Use image node_id 5 for calling a global function with example usage: set_per_process_memory_fraction(fraction, device) without return types