{"record":{"id":"ff62dc439e7bffc1","repo":"vllm-project/vllm","slug":"torch-xpu-memory-is-not-available","errorCode":null,"errorMessage":"torch.xpu.memory is not available","messagePattern":"torch\\.xpu\\.memory is not available","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"vllm/device_allocator/xpumem.py","lineNumber":37,"sourceCode":"MEMCPY_DEVICE_TO_HOST = 1\nMEMCPY_DEVICE_TO_DEVICE = 2\n\nxpumem_available = False\nxpumem_allocator: Any = None\n\ntry:\n    from vllm_xpu_kernels import xpumem_allocator as _xpumem_allocator\n\n    xpumem_allocator = _xpumem_allocator\n    xpumem_available = True\nexcept ImportError:\n    xpumem_allocator = None\n\n\ndef _xpu_memory_module() -> Any:\n    mem_mod = getattr(torch.xpu, \"memory\", None)\n    if mem_mod is None:\n        raise RuntimeError(\"torch.xpu.memory is not available\")\n    return mem_mod\n\n\ndef _supports_xpu_mem_pool(mem_mod: Any) -> bool:\n    return hasattr(mem_mod, \"MemPool\") and hasattr(mem_mod, \"use_mem_pool\")\n\n\ndef _xpu_memcpy_sync(\n    dst_ptr: int,\n    src_ptr: int,\n    n_bytes: int,\n    kind: int,\n    device: int,\n) -> None:\n    def _to_i64_ptr(ptr: int) -> int:\n        # torch custom-op `int` arguments are signed int64.\n        # data_ptr() may return a uint64 value above 2^63-1, so normalize it.\n        return ptr if ptr < (1 << 63) else ptr - (1 << 64)","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/device_allocator/xpumem.py#L19-L55","documentation":"Raised by _xpu_memory_module in vllm/device_allocator/xpumem.py when torch.xpu.memory is absent. The XPU sleep-mode allocator needs torch's XPU memory APIs (MemPool/use_mem_pool/XPUPluggableAllocator); if the attribute is missing, the installed torch either has no XPU support or predates these APIs.","triggerScenarios":"XpuMemAllocator code paths (sleep mode on XPU) call _xpu_memory_module(); it fails when getattr(torch.xpu, \"memory\", None) is None — a torch build without XPU support, an old torch, or a non-XPU machine reaching this code.","commonSituations":"Using a stock PyPI torch (no XPU) with an XPU-enabled vLLM; torch version older than the one that introduced torch.xpu.memory.MemPool; misconfigured environment where XPUs exist but the wrong torch is active.","solutions":["Install an Intel XPU build of PyTorch that exposes torch.xpu.memory (check torch.xpu.is_available() and hasattr(torch.xpu, 'memory')).","Verify the vLLM XPU requirements (requirements/xpu.txt or docs) and match the pinned torch version.","Confirm the process actually sees the XPU devices (oneAPI level-zero/GPU drivers loaded)."],"exampleFix":"# before: stock torch, torch.xpu.memory is None\n# after\npip install --index-url https://download.pytorch.org/whl/xpu torch  # XPU-enabled build\npython -c \"import torch; print(hasattr(torch.xpu, 'memory'))\"  # True","handlingStrategy":"type-guard","validationCode":"import torch\n\nif torch.xpu.is_available() and getattr(torch.xpu, \"memory\", None) is None:\n    raise SystemExit(\"torch build lacks torch.xpu.memory; install an XPU-enabled torch\")","typeGuard":"def xpu_memory_api_present() -> bool:\n    import torch\n    return getattr(torch.xpu, \"memory\", None) is not None","tryCatchPattern":"try:\n    allocator = XpuMemAllocator.get_instance()\nexcept RuntimeError as e:\n    if \"torch.xpu.memory is not available\" in str(e):\n        report_torch_xpu_version_and_abort()\n    raise","preventionTips":["Preflight torch XPU capabilities (xpu.memory present) in the container entrypoint.","Pin the torch-XPU wheel version from vLLM's XPU requirements in images."],"tags":["vllm","xpu","torch","sleep-mode","environment"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}