Skip to content

fix(scheduler): bound the memory-pressure requeue store and let aborts stop it - #5542

Open
zviratko wants to merge 1 commit into
jundot:mainfrom
zviratko:fix/memory-requeue-store-budget
Open

zviratko wants to merge 1 commit into
jundot:mainfrom
zviratko:fix/memory-requeue-store-budget

Conversation

@zviratko

Copy link
Copy Markdown
Contributor

Problem

At hard memory pressure, ProcessMemoryEnforcer asks the scheduler to store and requeue the live requests instead of aborting them (#4509). _process_pending_memory_requeue writes each request's KV to the paged SSD cache on the inference thread, under bounded_pending_writes, so the store runs at the write speed of the SSD cache drive. While it runs:

  • every other request stops decoding,
  • aborts are not processed: _pending_abort_ids is checked only between requests, not between blocks.

On a slow drive this looks like a deadlock. Measured with the SSD cache on an SD card (about 21 MB/s write): two 150k-token requests on Qwen3.8-Flash-Next (8192-token blocks of 216 MB) froze the engine for about 3 minutes and were still storing; client aborts had no effect and the server had to be killed. The enforcer repeated "Hard memory pressure: storing and requeueing 2 request(s)" every second for the whole time. On a fast internal SSD the same store takes seconds, so the problem shows only with slow or throttling cache drives.

Approach

  • BlockAwarePrefixCache.store_cache gets an optional should_stop callback. It is checked before each new block is allocated; when it returns True the store ends through the same exit as a failed block allocation, so the blocks stored so far stay a valid prefix. Callers that do not pass it are unchanged.
  • The memory requeue passes should_stop = pending abort or time budget spent. The budget is _MEMORY_REQUEUE_STORE_BUDGET_S = 30.0, override with OMLX_MEMORY_REQUEUE_STORE_BUDGET_S (0 = no limit, the old behavior). Requests not reached within the budget are requeued without a stored prefix and recompute; requests stopped mid-store resume from the blocks they kept.
  • The requeue log line now reports the tokens actually kept (40960/73728), not the tokens it tried to store.

The freeze can exceed the budget by at most one block write, because the check runs between blocks.

Validation

  • New tests/test_memory_requeue_store_budget.py (6 tests) on the existing _chunked_scheduler_rig (tiny hybrid GDN and rotating models, real paged SSD cache):
    • store stopped mid-request keeps a valid prefix: the restored cache matches a cold prefill, and both requests then stream all their tokens once (gdn, rotating);
    • spent budget requeues without a store and the requests still complete correctly (gdn, rotating);
    • an abort that arrives during the store stops it at the next block;
    • env parsing.
      With the should_stop check in store_cache removed, the two partial-prefix tests and the abort test fail; with the deadline removed, the two spent-budget tests fail.
  • Related suites (test_scheduler_boundary_completion, test_process_memory_enforcer, test_prefill_oom_graceful, test_scheduler_prompt_boundary_store): 360 passed.
  • Default suite (python -m pytest): 19,804 passed, 6 failed; the same 6 fail on main without this change (test_glm5_next_mtp split-K x2, test_hy_v4 NAX paths, test_install_detection x2, test_mcp_client SSE headers).
  • Real model (MacBook Pro M5, 128 GB, Qwen3.8-Flash-Next oQ4h, SSD cache on an SD card): two 150k-token prompts, requeue triggered while both were prefilling. The store stopped after 5 blocks: "requeued 2 request(s) in 36.3s; tokens kept in the SSD cache: 40960/73728, 0 (budget)". The first request resumed from the 40,960 stored tokens (Prefix cache restore ... cached=40960), and both completed with all 64 output tokens. Without the change the same situation stored block after block for minutes.

Not tested: the hard-pressure trigger itself with the fix on real hardware. I could not reproduce it reliably by load (the chunk sizer usually throttles first), so the live run triggered request_memory_requeue() directly through a temporary test hook (not part of this PR). The real-model runs (the hang and the fix) used a local build of an earlier main with other local patches; none of them touch the requeue or store path, and this diff applies unchanged on current main. The default budget of 30 s is a judgment call; it is long enough that a normal SSD never reaches it.

…s stop it

The hard-pressure requeue writes every live request's KV to the paged SSD cache on the inference thread at the cache drive's write speed. On a slow drive this froze all decoding for minutes and aborts were not processed until the whole store ended. store_cache now takes an optional should_stop callback checked between blocks; the requeue stops on a pending abort or after OMLX_MEMORY_REQUEUE_STORE_BUDGET_S (default 30 s, 0 = no limit). Stored blocks stay a valid prefix; the rest is recomputed.
zviratko added a commit to zviratko/omlx-uplift that referenced this pull request Nov 22, 2026
A memory-pressure requeue stored every running request's KV on the inference thread at the cache drive's write speed; on an SD-card cache that froze decoding for minutes and ignored aborts. The PR stops the store between blocks on a pending abort or after OMLX_MEMORY_REQUEUE_STORE_BUDGET_S (30 s). Linked as github_pr per the catalog rule; notes file with the analysis, verification and the uplift autopatch pitfall found while testing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant