Skip to content

fix: refused GDN rungs stay bounded per sequence; portable prefill pieces and q offset views - #380

Merged
Brooooooklyn merged 6 commits into
mainfrom
fix/portable-prefill-and-refused-rungs
Nov 13, 2026
Merged

Brooooooklyn merged 6 commits into
mainfrom
fix/portable-prefill-and-refused-rungs

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #377. Fixes the Codex findings on #377 and the gaps found while fixing them.

host short of spare memory (7 GB runner): #374 governor refuses Optional claims
  GDN ladder rung refused ──► #377: kept for the turn's cold sidecar capture
                             this PR: at most TWO held rungs per scheduled sequence — the deepest, and the
                                      deepest within the reach this turn's K/V capture walk can get —
                                      cleared at that sequence's turn end; MoE gets the same fix
GPU without MPP prefill pipelines ──► portable varlen prefill
  bf16 rows in pieces ──► each piece is evaluated before the next (workspaces no longer overlap)
  piece = q view at an offset ──► paged reads accept a q view at a whole-head offset (all callers)

Changes

  • qwen3_5 / qwen3_5_moe gdn_prefix.rs: a refused rung is held in gdn_unclaimed_rungs: HashMap<Option<SeqId>, Vec<_>> (key = active_scheduled_seq, None = serial lane). hold_refused_rung keeps at most two per key: the deepest, and the deepest at or below the predicted capture reach. The reach comes from ColdTierWalk::capture_reach, which probes the same K/V chain keys and per-turn block budget as capture_chain (blocks already on disk are free); with no cold tier only the deepest is held. The capture reads only the finishing sequence's rung; its turn end removes only that entry; release_scheduled_recurrent_for(seq) drops a vacated sequence's rung; clear_reuse_state drops all. The bound is two extra rungs per live sequence (was: every refused rung of the ladder, held through decode, outside reclaim). Deepest-only failed the e2e on the runner: the harness captures 12 blocks per turn, so the reach (192–768 tokens) was below the deepest rung (1248) and no sidecar was written.
  • MoE: a refused rung was dropped, so no MoE rung reached the cold tier on such a host; it now follows the dense rule.
  • paged_kv_cache_adapter.rs portable_prefill_attention: every bf16 piece but the last is evaluated before the next is built. Measured on 16 pieces: peak growth 293.7 MB → 34.3 MB (one piece's partials 17.0 MB).
  • mlx_paged_ops.cpp: PagedAttention, PagedAttentionVarlen and PagedPrefillAttention accept a row-contiguous q at a non-zero offset that is a whole number of heads. Every kernel binds q through CommandEncoder::set_input_array, which adds a.offset(); no host code does pointer math on q. Pools, scales, block tables, seq lens, cu_seqlens and workspace keep the zero-offset rule. A copy in the FFI could not work: the alias appears only inside Contiguous::eval_gpu.

Tests

  • qwen3_5_cold_tier_restart_parity under a local runner simulation (portable prefill, 5,010,305,024 B working set, 7 GiB host with 2.5 GiB spare): FAIL before this fix (boundary_skips=2, anchored at 0, as CI run 43378257889), PASS after (cached 64 / 304 / 304, installed=2, anchored at 304), PASS without the simulation.
  • a_refused_rung_within_the_capture_reach_reaches_the_cold_tier (+ MoE twin), a_rung_refused_ram_still_reaches_the_cold_tier, moe_rung_refused_ram_still_reaches_the_cold_tier, overlapped_sequences_each_send_their_refused_rung_to_the_cold_tier (+ MoE twin), portable_prefill_pieces_do_not_hold_their_partials_together, portable_verify_pieces_at_long_context_attend (8 rows at 131,072 tokens, piece 2 at offset 14,336), paged_q_offset_view (decode v1/v2, varlen v1/v2, int8 tiled, MPP prefill, off-head-boundary refusal).
  • One mutation per defect, each red when on and green when off, then removed: f1, f2, f3 (now q_offset), f4, H1, q_align, deepest-only.
  • cargo +1.100.0 clippy --workspace --all-targets with warnings denied: clean. Touched modules' tests green.

Not in this PR

  • The scheduler sets active_cache_owner_id only at admission, so an overlapped sequence's capture can filter by the wrong owner. S13 replaces this capture path.

🤖 Generated with Claude Code

@Brooooooklyn Brooooooklyn added the model-e2e Run the heavy Model E2E workflow (per-family real-checkpoint tests) on this PR label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0de5fa74-4164-4f06-b6e6-6034c41192e9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T07:16:00.445520Z 2f37a38 New commits
ℹ️ 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.

Brooooooklyn and others added 6 commits November 13, 2026 15:13
A host that refused RAM for ladder rungs kept every refused rung as live
MLX state until the turn ended, outside the governor's reclaim units:
up to one rung per ladder step through decode. The sidecar capture
anchors on the deepest checkpoint the persisted chain reaches, so the
turn now keeps one refused rung, the deepest, and a deeper refusal
replaces it. A reference impl of the lineage trait is now generic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he cold tier

MoE dropped a ladder rung the #374 governor refused, so on a host short
of spare memory no MoE recurrent state reached the cold tier. Mirrors
the dense fix (Splash publishStateToDisk): the deepest refused rung is
held for this turn's sidecar capture and dropped at every turn end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… one at a time

Two defects in the bf16 piece loop of the portable prefill:

- A piece past the first was a query view at a nonzero offset. When the
  parent buffer is within 16 KiB of the piece, MLX `contiguous` keeps the
  view, and the varlen primitive refuses it ("q must have offset 0; got
  offset 14336" for an 8-row verify block at 131,072 tokens). Each piece
  now takes a deep copy when the chunk has more than one piece.
- Every piece allocates its own partials and frees them only when its
  command buffer completes, so a lazily built chunk held all pieces'
  partials at once (293 MB peak for 16 pieces at 16K tokens vs 34 MB).
  Each piece but the last is now evaluated before the next is built.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The held refused rung was one slot for the whole model. Under continuous
batching two sequences overlap: B's deeper refused rung replaced A's, and
A's turn end emptied the slot before B's capture, so either sequence could
lose its cold-tier sidecar (Splash publishStateToDisk). Dense and MoE now
hold the deepest refused rung per scheduled sequence; a turn end captures
and drops only its own, and releasing a sequence drops its rung. The key
is the sequence, not active_cache_owner_id, which the scheduler sets only
at admission. Session reset and invalidation still drop every rung.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PagedAttention, PagedAttentionVarlen and PagedPrefillAttention refused
any q at a nonzero byte offset. The FFI's lazy contiguous(q) aliases a
row-contiguous view when its parent buffer is within 16 KiB of it, so a
sliced q reached eval_gpu at an offset and aborted ("q must have offset
0; got offset 14336"). Every kernel binds q through set_input_array,
which adds the array's offset, and no host code reads q, so the offset
is safe: q (and the prefill's staged q) now only needs row contiguity
and an offset of whole heads, the q alignment the kernels already
address. Pools, scales, metadata and workspace keep the zero-offset
rule.

The portable bf16 prefill's per-piece deep copy, which worked around
this for its 1-row piece at 131,072 tokens, is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The turn-end sidecar capture anchors only at or below the K/V chain the
turn's capture walk persists, and that walk adds at most its per-turn
block budget past the chain already on disk. Holding only the deepest
refused rung lost every usable rung when that rung sat past the walk's
reach: on a host short of spare memory the qwen3_5 restart parity e2e
wrote no sidecar (boundary_skips=2, restore anchored at 0).

Each sequence now holds at most two refused rungs: the deepest, and the
deepest at or below the reach predicted from the walk's own inputs (the
blocks on disk plus the per-turn block budget). Dense and MoE.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn force-pushed the fix/portable-prefill-and-refused-rungs branch from 940c091 to 2f37a38 Compare November 13, 2026 07:14
@Brooooooklyn
Brooooooklyn merged commit 9ba79a1 into main Nov 13, 2026
25 of 27 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/portable-prefill-and-refused-rungs branch November 13, 2026 08:48
Brooooooklyn added a commit that referenced this pull request Nov 13, 2026
…ts (#381)

`lfm2_paged_vs_flat_greedy_token_parity` failed once on the CI VM (run
43384271735, PR #380) and passed on rerun of the same commit:

```
prompt #1 "What is 2 + 3? Answer with just the number."
  FLAT  (32 tokens) "The sum of 2 and 3 is"
  PAGED (32 tokens) ""
```

A bisect under a local runner simulation could not reproduce it (main →
#380 head: 9/9, byte-identical output; 12/12 under a two-process
stress), and #380's code does not reach LFM2 (instrumented: 0 portable
prefill calls, all 16,001 `q` checks at offset 0). The failing VM run
was 2–6× slower than its siblings from the bridge test on.

The panic message could not tell the two candidate causes apart:
- NaN logits collapsing to the pad token (a real defect),
- a thinking block that never closed within 32 tokens (a near-tie on the
VM's numerics).

It now prints, for both paths: `raw_text`, `thinking`,
`reasoning_tokens`, `prompt_tokens`, `cached_tokens`. Test-only change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model-e2e Run the heavy Model E2E workflow (per-family real-checkpoint tests) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant