Repository navigation
[Fix]: Inline H2D during CUDA graph capture to avoid stream isolation in Offloader - #29166
Conversation
…isolation CPU weight offload prefetches parameters on alt_stream and synchronizes via CUDA events. During decode CUDA graph capture, waiting on events recorded on alt_stream (or prefetching there) creates a dependency on uncaptured work and aborts with cudaErrorStreamCaptureIsolation. When the current stream is capturing, materialize weights inline on the capture stream in start_onload and wait_and_get_device_tensors instead of using cross-stream prefetch/wait. Non-capture inference keeps the existing alt_stream overlap path unchanged. Signed-off-by: Shijin Zhang <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the offloader utility in python/sglang/srt/utils/offloader.py to support CUDA stream capturing. Specifically, it checks if the current stream is capturing during start_onload and wait_and_get_device_tensors to bypass asynchronous stream synchronization and instead load tensors synchronously. There are no review comments to address, and the changes appear correct.
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.
|
/tag-and-rerun-ci |
JustinTong0323
left a comment
There was a problem hiding this comment.
e2e on 4×GB300 with GLM-5.2-FP8 (--offload-group-size 4 --offload-mode cpu). Reproduced the decode graph cudaErrorStreamCaptureIsolation at wait_and_get_device_tensors (the self._load_event.wait() call); this fix resolves it and GSM8K is clean (100% stop rate, correct answers). Two caveats inline.
|
/rerun-failed-ci |
4 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
… in Offloader (sgl-project#29166) Signed-off-by: Shijin Zhang <[email protected]>
… in Offloader (sgl-project#29166) Signed-off-by: Shijin Zhang <[email protected]>
Summary
CPU weight offload prefetches parameters on alt_stream and synchronizes via CUDA events. During decode CUDA graph capture, waiting on events recorded on alt_stream (or prefetching there) creates a dependency on uncaptured work and aborts with cudaErrorStreamCaptureIsolation.
When the current stream is capturing, materialize weights inline on the capture stream in start_onload and
wait_and_get_device_tensorsinstead of using cross-stream prefetch/wait. Non-capture inference keeps the existing alt_stream overlap path unchanged.Root Cause
The CPU offloader pipeline is:
Nforward:start_onload()prefetches layerN + prefetch_stepweights onalt_streamand records a CUDA event.N + prefetch_stepforward:wait_and_get_device_tensors()waits on that event, then runsfunctional_callwith the GPU weights.CUDA graph capture only records work on the capture stream. The original code always used
alt_streamfor prefetch and always called_load_event.wait()on the capture stream. This violates stream-capture isolation when:alt_streamduring capture, orChanges
python/sglang/srt/utils/offloader.py
_ModuleOffloader.start_onload(): If the current stream is capturing a CUDA graph, load weights inline on the capture stream and skip alt_stream prefetch/event recording. Otherwise, keep the existing async prefetch on alt_stream.
_ModuleOffloader.wait_and_get_device_tensors(): If capturing, avoid waiting on _load_event; re-materialize weights inline when a stale pre-capture prefetch exists. Otherwise, wait on _load_event as before.
CI States
Latest PR Test (Base): ❌ Run #28215099371
Latest PR Test (Extra): ❌ Run #28215099338