Repository navigation
Conversation
SGLang's default `retract_decode` stably sorts the batch by output length descending and then prompt length ascending, pops victims from the end (shortest output, then longest prompt, the latest exact tie first), and keeps the survivors in that sorted order through `filter_batch(keep_indices=sorted_indices)`. After each release, `release_req` evicts cached pages toward `SGLANG_RETRACT_DECODE_STEPS` (20) tokens per remaining request, while only the next decode step's demand decides whether to retract again (python/sglang/srt/managers/schedule_batch.py L2191-L2194, L3168-L3245 and L3289-L3292, and mem_cache/common.py L184-L191, at v0.5.20). The simulator retracted the earliest request with the shortest output, kept the original batch order, and evicted only for the next step. Sort once per retraction pass, retract the last row that is not a host-loop ghost, and evict toward the reserve after each retraction. Ghost rows stay in the sorted batch but are never retracted. The pressure-event test's three-page pool now also loses its unprotected cached page to that eviction. Signed-off-by: Rudy Pei <yanrpei@gmail.com> Co-authored-by: Isaac <no-reply@databricks.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📜 Recent review details
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
|
Superseded by #583, which now contains this change together with the related SGLang cache lifecycle, eviction, reporting, and KV-event corrections. The consolidated branch has passed local core and public-API validation. |
Why and what changed
SGLang decode retraction currently selects the first shortest-output request and preserves the original survivor order. Native SGLang's length policy uses a stable output/prompt-length ordering, pops the last tie, and evicts newly released cache toward a per-survivor reserve. These differences change victims and subsequent reuse under KV pressure.
Sort once by descending output length then ascending prompt length, retract from the end, retain ordered survivors, and evict toward 20 tokens per survivor after each release. Terminal ghost rows remain in the batch but cannot be retracted. The reserve does not itself cause further retraction.
Review map
crates/core/src/engine/scheduler/sglang/decode.rs, then thedecode_retractionregressions.Evidence
cargo test -p aisimulate-core— 2,431 passed, zero failures, 1 ignored. This full suite ran before the final comment/legal-only changes; final-head focused results follow.cargo test -p aisimulate-core --lib -- engine::scheduler::sglang— 95 passed, zero failures. Nightly formatting and packaged legal-file checks passed.Modeling or data provenance
Matches SGLang v0.5.20's length-policy order and release reserve. Synthetic fixtures; this does not add native priority or beam scheduling.
Tracking
None.
This pull request and its description were written by Isaac.