Skip to content

[Fix] scheduler: Reap HiCache events while the engine is paused - #46502

Open
sohom-cs wants to merge 3 commits into
sgl-project:mainfrom
sohom-cs:fix/reap-hicache-events-while-paused
Open

sohom-cs wants to merge 3 commits into
sgl-project:mainfrom
sohom-cs:fix/reap-hicache-events-while-paused

Conversation

@sohom-cs

@sohom-cs sohom-cs commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

With HiCache on (--enable-hierarchical-cache, default write_through), an RL weight sync runs pause_generation(mode="retract"), then update_weights_from_disk(flush_cache=True). The update returns success=False: "Weights were updated, but the cache was not flushed because requests are still running or queued. Retract or finish them, then call /flush_cache." The requests are already retracted, and /flush_cache fails on every paused iteration, so the only way out is continue_generation, which serves the new weights over the old weights' cache.

The blocker is not the requests: #40779's paused gate already ignores the requeued ones. It is a HiCache write-through still in ongoing_write_through and, with an L3 backend, the prefetch the retract requeue starts for a request with 256 or more uncached tokens. Only check_hicache_events retires them, and it runs from the batch getters and process_decode_queue, which every paused branch skips. #43758 turned the old assert into this message: the update fails cleanly but cannot succeed while paused.

Modifications

All seven paused branches call _record_scheduler_state_for_paused_engine() on each iteration. It now first calls _process_hicache_events(should_retry_storage_prefetch=False): pending acks are reaped before the idle/active record, and no new L3 attempt starts. PD decode reaps only with the decode radix cache, as process_decode_queue does. No loop body changes.

Considered and rejected: a blocking drain at pause entry, as #30899 and #43282 do. It cannot retire the prefetch the requeue issues after the retract, and it blocks the control path.

Edits the same helper as #46334 and #46307.

Accuracy Tests

New file test/registered/unit/managers/test_scheduler_paused_hicache_events.py, because #43910/#43911 and #46334 edit the neighbouring test files:

  • a paused iteration reaps once, before recording state, and retries no storage prefetch;
  • no reap without HiCache, or on PD decode without the decode radix cache;
  • real event_loop_normal, retract pause, one pending write-through: after one paused iteration the update and flush_cache() succeed;
  • L3 storage, 300 generated tokens: the requeue starts one prefetch, and one paused iteration retires it.

The tree cache, forward, retract_all and weight load are stubbed. On CPU:

  • main: 5 failed, 2 passed (the first case's three subtests; both loop cases return the message above)
  • this PR: 4 passed, 5 subtests passed; test_scheduler_pause_generation.py and test_scheduler_hicache_events.py still pass

Not run: a GPU job with a real HiCache backend, or several ranks. Every rank receives pause and resume through the same broadcast, so I expect the all-reduce inside check_hicache_events to line up as on an idle running loop.

Speed Tests and Profiling

N/A: the same check_hicache_events call an idle iteration makes.

Checklist

Developed with AI assistance (Claude); every changed line was reviewed and the tests were run locally by me.


CI States

Latest PR Test (Base): ❌ Run #41538484740
Latest PR Test (Extra): ❌ Run #41538484759
Latest PR Test (AMD ROCm 10): ❌ Run #41538484752

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

With HiCache on, an RL weight sync that runs pause_generation(retract)
and then update_weights_*(flush_cache=True) gets success=False ("Weights
were updated, but the cache was not flushed ..."), and /flush_cache keeps
failing for as long as the engine stays paused.

A write-through still in flight at the pause, or an L3 prefetch started
when the retracted request is requeued, is retired only by
check_hicache_events, which runs from the batch getters and
process_decode_queue. Every paused branch continues before those, so the
entry stays in ongoing_write_through or ongoing_prefetch and
is_fully_idle stays false.

Reap HiCache events in _record_scheduler_state_for_paused_engine, which
all paused branches call, without retrying storage prefetches. A PD
decode worker reaps only with the decode radix cache, as
process_decode_queue does.

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
@github-actions github-actions Bot added the hicache Hierarchical Caching for SGLang label Oct 26, 2026
@sohom-cs
sohom-cs marked this pull request as ready for review November 2, 2026 04:47
@sohom-cs
sohom-cs requested a review from merrymercy as a code owner November 2, 2026 04:47

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T04:51:41.225919Z 56a5c79 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…ts-while-paused

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
Main now reads deferred_responses, running_reqs, prefill_launched_reqs and
request_receiver on the paused and running paths, and
_process_hicache_events reads enable_unified_cache_external_linker, so the
bare test schedulers set them. The pause test's scheduler sets the linker
flag too, since the paused path now reaps HiCache events.

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant