{"record":{"id":"0f4da3f0150338c2","repo":"vllm-project/vllm","slug":"torch-xpu-memory-mempool-apis-are-not-available-n","errorCode":null,"errorMessage":"torch.xpu.memory MemPool APIs are not available (need MemPool and use_mem_pool).","messagePattern":"torch\\.xpu\\.memory MemPool APIs are not available \\(need MemPool and use_mem_pool\\)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"vllm/device_allocator/xpumem.py","lineNumber":102,"sourceCode":"    if not xpumem_available or xpumem_allocator is None:\n        raise RuntimeError(\"xpumem allocator extension is not available\")\n    xpumem_allocator.python_create_and_allocate(*allocation_handle)\n\n\ndef unmap_and_release(allocation_handle: HandleType) -> None:\n    if not xpumem_available or xpumem_allocator is None:\n        raise RuntimeError(\"xpumem allocator extension is not available\")\n    xpumem_allocator.python_unmap_and_release(*allocation_handle)\n\n\n@contextmanager\ndef use_memory_pool_with_allocator(\n    python_malloc_fn: Callable[[HandleType], None],\n    python_free_func: Callable[[int], HandleType],\n) -> Iterator[tuple[Any, Any]]:\n    mem_mod = _xpu_memory_module()\n    if not _supports_xpu_mem_pool(mem_mod):\n        raise RuntimeError(\n            \"torch.xpu.memory MemPool APIs are not available \"\n            \"(need MemPool and use_mem_pool).\"\n        )\n    new_alloc = get_pluggable_allocator(python_malloc_fn, python_free_func)\n    mem_pool = mem_mod.MemPool(new_alloc._allocator)\n    with mem_mod.use_mem_pool(mem_pool):\n        yield mem_pool, new_alloc\n\n\nclass XpuMemAllocator:\n    \"\"\"A singleton pluggable allocator helper for XPU.\n\n    Note:\n    Sleep will offload selected payloads to CPU or discard and unmap XPU\n    physical memory. Wake-up remaps physical memory back to the same\n    reserved virtual address and restores payload.\n    \"\"\"\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/device_allocator/xpumem.py#L84-L120","documentation":"Raised by use_memory_pool_with_allocator in xpumem.py when torch.xpu.memory exists but is missing MemPool or use_mem_pool. The context manager swaps the XPU allocator via these pool APIs; a torch XPU build without them cannot host the pluggable allocator, so the guard fails before any allocation happens.","triggerScenarios":"Entering the XpuMemAllocator memory-pool context (XPU sleep mode allocation phase) with a torch whose xpu.memory module lacks MemPool/use_mem_pool — usually an older or trimmed torch-XPU build.","commonSituations":"Version skew between vLLM and Intel torch: vLLM expects the MemPool APIs added in a given torch release, the deployed image has an older one; a custom torch build compiled without those bindings.","solutions":["Upgrade to the torch XPU version pinned by your vLLM release.","Preflight the APIs: python -c \"import torch; m=torch.xpu.memory; print(hasattr(m,'MemPool'), hasattr(m,'use_mem_pool'))\" — both must be True.","If upgrading is impossible, disable XPU sleep mode on this stack."],"exampleFix":"# before: torch without MemPool APIs -> RuntimeError\n# after\npip install --index-url https://download.pytorch.org/whl/xpu torch==<pinned>\npython -c \"import torch; m=torch.xpu.memory; print(hasattr(m,'MemPool') and hasattr(m,'use_mem_pool'))\"  # True","handlingStrategy":"type-guard","validationCode":"import torch\n\nmem = getattr(torch.xpu, \"memory\", None)\nok = mem is not None and hasattr(mem, \"MemPool\") and hasattr(mem, \"use_mem_pool\")\nif not ok:\n    raise SystemExit(\"torch.xpu.memory MemPool/use_mem_pool missing; upgrade torch-XPU\")","typeGuard":"def xpu_mempool_api_present() -> bool:\n    import torch\n    mem = getattr(torch.xpu, \"memory\", None)\n    return mem is not None and hasattr(mem, \"MemPool\") and hasattr(mem, \"use_mem_pool\")","tryCatchPattern":"try:\n    with use_memory_pool_with_allocator(malloc, free) as (pool, alloc):\n        ...\nexcept RuntimeError as e:\n    if \"MemPool APIs\" in str(e):\n        abort_with_torch_upgrade_guidance()\n    raise","preventionTips":["Assert MemPool/use_mem_pool presence during image build for XPU sleep-mode deployments.","Track the torch-XPU release notes: the MemPool APIs are version-gated."],"tags":["vllm","xpu","torch","mempool","version-mismatch"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}