fix(rollout): drain generation before offload memory release#2015
Open
EazyReal wants to merge 1 commit into
Open
fix(rollout): drain generation before offload memory release#2015EazyReal wants to merge 1 commit into
EazyReal wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RolloutServer.offload()currently releases SGLang engine memory by callingrelease_memory_occupation()directly on each offloaded engine group.SGLangEngine.release_memory_occupation()does callflush_cache()internally, but that flush is engine-local. It does not first stop generation from accepting or advancing requests. Under high concurrency, memory release can therefore overlap with in-flight generation work, so offload may run before the rollout server has reached a stable drained state.For rollout offload, the desired lifecycle is:
This is also the lifecycle shape already used by the rollout weight-update path before mutating engine state:
pause_generation->flush_cache-> update ->continue_generation.Fix
This PR makes rollout offload a server-level three-phase transition:
pause_generation()for every offloaded SGLang engine in the server;flush_cache()on every offloaded engine;release_memory_occupation()only after the server has reached the drained state.Generation resumes at the matching safe boundary: after
onload_kv()restores KV-cache and CUDA-graph memory, the rollout server issues and waits forcontinue_generation().Rationale
I kept the coordination in
RolloutServerbecause that is the layer that can see all server groups and preserve the phase ordering across the whole rollout server. This lets every offloaded group pause before any group proceeds to flush or release memory.This keeps the lower-level shape close to the existing code:
ServerGroupmethods remain non-blocking and return Ray ObjectRefs, preserving the batching direction from refactor: make EngineGroup ops non-blocking and batch ray.get at RolloutServer level #1613.release_memory_occupation()keeps its internal flush for direct callers such as recovery.onload_kv()matches the normal restore order: weights are restored/updated first, then KV-cache and CUDA-graph memory are restored, then generation can continue.A few alternatives seemed less precise:
flush_cache()leaves generation unpaused before release;SGLangEnginewould make it harder to coordinate all rollout groups in one server.Tests
Adds a CPU unit test that imports the real rollout dataclasses with lightweight Ray/SGLang stubs and verifies:
pause_generation, and all pause refs are waited before any flush starts;needs_offload=Falseare skipped;onload_kv()restores KV/CUDA-graph memory before resuming generation.The new test is registered in the CPU CI matrix through
.github/workflows/pr-test.yml.j2, and the generated workflow is refreshed.Validation
uv run --with pytest --with pyyaml python tests/test_rollout_offload_coordination.pyuv run --with ruff ruff check slime/ray/rollout.py tests/test_rollout_offload_coordination.pypython3 .github/workflows/generate_github_workflows.pygit diff --check HEAD~1..HEAD