[Feature][Intel XPU] Add memory saver support for Intel XPU via upstream torch_memory_saver - #29935
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for the experimental Memory Saver feature on Intel XPU, allowing the engine to temporarily release and reclaim GPU memory. The changes include updating the Dockerfile to install torch_memory_saver from source, adding documentation, adapting the TorchMemorySaverAdapter for XPU specifics (such as using the in-process pluggable allocator), updating memory utility functions, and introducing a comprehensive suite of unit tests. The reviewer feedback suggests pinning the torch_memory_saver repository to a specific commit hash in the Dockerfile to ensure reproducible builds, and removing an unused variable cur in the test setup.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Addresses review on PR sgl-project#29935: torch.xpu.current_device() was assigned to 'cur' but never used (mem_get_info(i) reads a specific device without changing the current one). Drop it and correct the comment.
| return _memory_saver.region(tag=tag, enable_cpu_backup=enable_cpu_backup) | ||
|
|
||
| def cuda_graph(self, **kwargs): | ||
| if is_xpu(): |
There was a problem hiding this comment.
why can't we support this ?
Addresses review on PR sgl-project#29935: torch.xpu.current_device() was assigned to 'cur' but never used (mem_get_info(i) reads a specific device without changing the current one). Drop it and correct the comment.
64d10f5 to
6150746
Compare
Addresses review on PR sgl-project#29935: torch.xpu.current_device() was assigned to 'cur' but never used (mem_get_info(i) reads a specific device without changing the current one). Drop it and correct the comment.
|
/tag-run-ci-label |
|
https://github.com/sgl-project/sglang/actions/runs/32100083362/job/95598837541 xpu ci failed. seems to be related to this pr, where please check. |
Enable release/resume_memory_occupation on Intel XPU using the upstream
torch_memory_saver package (Level Zero VMM backend). Replaces in-repo
implementation with pip-installable upstream dependency.
Features:
- Pause/resume physical GPU memory while preserving virtual addresses
- Tag-based selective memory management (kv_cache, weights, cuda_graph)
- Optional CPU backup for content preservation
- Multi-device support (verified via the package's multi-device test)
- Sysman-based memory verification (torch accounting doesn't reflect unmapped pages)
Changes:
- Add TorchMemorySaverAdapter for unified memory saver API
- XPU uses hook_mode='torch' (in-process pluggable allocator, not LD_PRELOAD)
- configure_subprocess() and cuda_graph() are no-ops on XPU
- Update Dockerfile to build the upstream package for XPU
- Add test suite (10 tests, all passing)
Installation (XPU builds from source; TMS_PLATFORM=xpu forces the XPU backend
and --no-build-isolation lets the build match libsycl to the installed torch):
source /opt/intel/oneapi/setvars.sh
TMS_PLATFORM=xpu pip install --no-build-isolation \
git+https://github.com/fzyzcjy/torch_memory_saver.git
Usage:
python -m sglang.launch_server --model-path <model> --device xpu --enable-memory-saver
Depends on: fzyzcjy/torch_memory_saver#78
Addresses review on PR sgl-project#29935: torch.xpu.current_device() was assigned to 'cur' but never used (mem_get_info(i) reads a specific device without changing the current one). Drop it and correct the comment.
torch_memory_saver was installed from the tip of master, so an upstream change could break the XPU image and the documented setup without any change here. Pin to a5c99f11b18ebb8e9fda71a68812e476ae49e417 (tag v0.0.10b2). XPU still has to build from source -- the published wheels are CUDA-only -- so pinning the ref is what makes the build reproducible. The Dockerfile exposes it as the TORCH_MEMORY_SAVER_REF build arg so the ref can be bumped with --build-arg.
The test asserted physical release through the saver's sysman-backed tms_xpu_device_free_bytes, which newer Intel drivers report frozen: it stayed constant across alloc/pause/resume, so 5 of the 10 cases read a 0.0 GiB delta and failed even though pause/resume worked correctly. Use tms_xpu_committed_bytes instead — the physical bytes the saver holds ACTIVE, which it only decrements after zeVirtualMemUnmap and zePhysicalMemDestroy succeed. That keeps the assertions tied to real Level Zero release while being driver-independent. Also pin the install ref quoted in the docstring and skip message, and refresh the moved docs path.
0cbf21c to
f3f91f3
Compare
…-ops Revert python/sglang/test/test_utils.py to main. get_gpu_memory_gb() is a pre-existing helper with no callers in the tree, and switching its XPU branch to torch.xpu.mem_get_info() also cut against the platform layer, which deliberately uses memory_allocated() until mem_get_info is adopted there (platforms/xpu.py:get_available_memory). Out of scope for this PR either way. torch_memory_saver_adapter: state why the XPU paths are no-ops rather than just that they are. Pauseable graph capture is gated on hook_mode="preload" upstream while XPU requires hook_mode="torch", and configure_subprocess() LD_PRELOADs a binary upstream's setup.py does not build for XPU. cuda_graph() is unreachable on XPU today (runner_backend routes XPU to FullXPUGraphBackend, which takes no memory saver), so warn once instead of raising: a future XPU graph backend that does route here surfaces that graph memory is not pauseable instead of failing to launch. Docs: mem_get_info() is also unusable for confirming a release -- it stays flat because torch keeps the freed block cached (measured: free unchanged across pause while sysman moved 1.00 GiB) -- so name it alongside memory_allocated().
…eam torch_memory_saver (sgl-project#29935)
Motivation
Enable release/resume_memory_occupation on Intel XPU using the upstream torch_memory_saver package (Level Zero VMM backend). Replaces in-repo implementation with pip-installable upstream dependency.
Features:
Modifications
Changes:
Installation (XPU builds from source; TMS_PLATFORM=xpu forces the XPU backend and --no-build-isolation lets the build match libsycl to the installed torch):
source /opt/intel/oneapi/setvars.sh
TMS_PLATFORM=xpu pip install --no-build-isolation
git+https://github.com/fzyzcjy/torch_memory_saver.git
Usage:
python -m sglang.launch_server --model-path --device xpu --enable-memory-saver
Depends on: fzyzcjy/torch_memory_saver#78
Accuracy Tests
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-cicc @mingfeima @fzyzcjy @habaohaba @yueming-yuan @jianan-gu @hnyls2002 @merrymercy
CI States
Latest PR Test (Base): ❌ Run #34083643346
Latest PR Test (Extra): ❌ Run #34083643187
Latest PR Test (AMD ROCm 7.2): ❌ Run #34083643322