Skip to content

Error message: XPU out of memory. Tried to allocate 4.00 GiB (GPU 0; 15.11 GiB total capacity; 0 bytes already allocated; 0 bytes reserved in total by PyTorch) #41150

@fablevi

Description

@fablevi

System Info

Soo the problem is simple:
If i only install xpu torch and intel_extension_for_pytorch then all my 16gbvram is ready but if i install transformers its only 4gb vram is aviable.
With this the 16gb vram works:

The code:

  import torch
  from torch import xpu
  import os
  import intel_extension_for_pytorch
  
  os.environ['UR_L0_USE_RELAXED_ALLOCATION_LIMITS'] = '1'
  os.environ['IGC_ExtraOCLOptions'] = "-cl-intel-greater-than-4GB-buffer-required"
  
  
  def xpu_memory_test():
      if not xpu.is_available():
          print("XPU not available!")
          return
  
  device = torch.device("xpu")
  print(f"\n=== XPU Memory Test ===")
  
  try:
      print(f"Device Name: {torch.xpu.get_device_name(device)}")
  
      max_alloc = torch.xpu.max_memory_allocated(device) / (1024**3)
      total_mem = torch.xpu.get_device_properties(device).total_memory / (1024**3)
      
      print(f"\nDevice Memory: {total_mem:.2f}GB total")
      print(f"Max allocated during session: {max_alloc:.2f}GB")
  
      size_step = 0.1
      current_size = 1.0
      last_success = 0
      
      while current_size <= total_mem:
          tensor_size = int(current_size * (1024**3 / 4))
          print(f"\nAttempting to allocate {current_size}GB tensor...")
          
          try:
              test_tensor = torch.empty(tensor_size, dtype=torch.float32, device=device)
              torch.xpu.synchronize(device)
  
              allocated = torch.xpu.memory_allocated(device) / (1024**3)
              print(f"Success! Current allocated: {allocated:.2f}GB")
              os.system("free -h")
              
              del test_tensor
              torch.xpu.empty_cache()
              last_success = current_size
              current_size += size_step
              
          except RuntimeError as e:
              print(f"\nAllocation failed at {current_size}GB (last success: {last_success}GB)")
              print(f"Error message: {str(e)}")
              os.system("free -h")
              break
              
  except Exception as e:
      print(f"\nError during memory test: {str(e)}")
      
  finally:
      allocated = torch.xpu.memory_allocated(device) / (1024**3)
      print(f"\n! Final allocated memory: {allocated:.2f}GB")
      print("Test completed.")
  
  if __name__ == "__main__":
      xpu_memory_test()
      torch.xpu.empty_cache()

pip list (no transformers)

  Package                     Version
  --------------------------- ----------
  accelerate                  1.10.1
  certifi                     2025.8.3
  charset-normalizer          3.4.3
  dpcpp-cpp-rt                2025.0.4
  filelock                    3.13.1
  fsspec                      2024.6.1
  hf-xet                      1.1.10
  huggingface-hub             0.35.1
  idna                        3.10
  impi-devel                  2021.14.1
  impi-rt                     2021.14.1
  intel-cmplr-lib-rt          2025.0.4
  intel-cmplr-lib-ur          2025.0.4
  intel-cmplr-lic-rt          2025.0.4
  intel_extension_for_pytorch 2.7.10+xpu
  intel-opencl-rt             2025.0.4
  intel-openmp                2025.0.4
  intel-pti                   0.10.1
  intel-sycl-rt               2025.0.4
  Jinja2                      3.1.4
  MarkupSafe                  2.1.5
  mkl                         2025.0.1
  mkl-dpcpp                   2025.0.1
  mpmath                      1.3.0
  networkx                    3.3
  numpy                       2.1.2
  oneccl                      2021.14.1
  oneccl-bind-pt              2.7.0+xpu
  oneccl-devel                2021.14.1
  onemkl-sycl-blas            2025.0.1
  onemkl-sycl-datafitting     2025.0.1
  onemkl-sycl-dft             2025.0.1
  onemkl-sycl-lapack          2025.0.1
  onemkl-sycl-rng             2025.0.1
  onemkl-sycl-sparse          2025.0.1
  onemkl-sycl-stats           2025.0.1
  onemkl-sycl-vm              2025.0.1
  packaging                   25.0
  pillow                      11.0.0
  pip                         24.0
  psutil                      7.1.0
  pytorch-triton-xpu          3.3.0
  PyYAML                      6.0.2
  regex                       2025.9.18
  requests                    2.32.5
  ruamel.yaml                 0.18.15
  ruamel.yaml.clib            0.2.14
  safetensors                 0.6.2
  setuptools                  65.5.0
  sympy                       1.13.3
  tbb                         2022.2.0
  tcmlib                      1.2.0
  tokenizers                  0.22.1
  torch                       2.7.0+xpu
  torchaudio                  2.7.0+xpu
  torchvision                 0.22.0+xpu
  tqdm                        4.67.1
  typing_extensions           4.12.2
  umf                         0.9.1
  urllib3                     2.5.0

But if i install transformers its go back to 4gb vram:

pip list (with transformers)

  Package                     Version
  --------------------------- ----------
  accelerate                  1.10.1
  certifi                     2025.8.3
  charset-normalizer          3.4.3
  dpcpp-cpp-rt                2025.0.4
  filelock                    3.13.1
  fsspec                      2024.6.1
  hf-xet                      1.1.10
  huggingface-hub             0.35.1
  idna                        3.10
  impi-devel                  2021.14.1
  impi-rt                     2021.14.1
  intel-cmplr-lib-rt          2025.0.4
  intel-cmplr-lib-ur          2025.0.4
  intel-cmplr-lic-rt          2025.0.4
  intel_extension_for_pytorch 2.7.10+xpu
  intel-opencl-rt             2025.0.4
  intel-openmp                2025.0.4
  intel-pti                   0.10.1
  intel-sycl-rt               2025.0.4
  Jinja2                      3.1.4
  MarkupSafe                  2.1.5
  mkl                         2025.0.1
  mkl-dpcpp                   2025.0.1
  mpmath                      1.3.0
  networkx                    3.3
  numpy                       2.1.2
  oneccl                      2021.14.1
  oneccl-bind-pt              2.7.0+xpu
  oneccl-devel                2021.14.1
  onemkl-sycl-blas            2025.0.1
  onemkl-sycl-datafitting     2025.0.1
  onemkl-sycl-dft             2025.0.1
  onemkl-sycl-lapack          2025.0.1
  onemkl-sycl-rng             2025.0.1
  onemkl-sycl-sparse          2025.0.1
  onemkl-sycl-stats           2025.0.1
  onemkl-sycl-vm              2025.0.1
  packaging                   25.0
  pillow                      11.0.0
  pip                         24.0
  psutil                      7.1.0
  pytorch-triton-xpu          3.3.0
  PyYAML                      6.0.2
  regex                       2025.9.18
  requests                    2.32.5
  ruamel.yaml                 0.18.15
  ruamel.yaml.clib            0.2.14
  safetensors                 0.6.2
  setuptools                  65.5.0
  sympy                       1.13.3
  tbb                         2022.2.0
  tcmlib                      1.2.0
  tokenizers                  0.22.1
  torch                       2.7.0+xpu
  torchaudio                  2.7.0+xpu
  torchvision                 0.22.0+xpu
  tqdm                        4.67.1
  transformers                4.56.2
  typing_extensions           4.12.2
  umf                         0.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions