Skip to content

model: count the Qwen3.8 ubatch arena's rows by the arena's own allocation - #889

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-ubatch-qreserve
Oct 27, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fix-ubatch-qreserve

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 ubatch 구간의 card 예약량을 실제 arena 할당량에 맞춰, planner가 position마다 27,008 B를 더 잡던 과예약을 바로잡습니다.

What and why

The planner reserved 644,345 B of card memory for each position of a Qwen3.8 ubatch walk. The walk's arena holds 496,448 B of that (124,100 f32 and 12 u32 per position), while the planner's derivation counted 523,456 B for it. The arena holds no query rows, no separate β and α rows and no one-row indexer queries, so the plan was 27,008 B per position too high. At the 4,096-position ubatch that is 110,624,768 B of card the planner kept empty, so placement put fewer experts on the card than it could.

UBATCH_ARENA_TOKEN_BYTES now names the arena's share (496,448 B) and UBATCH_TOKEN_BYTES is that plus the walk's own buffers, 617,337 B per position. The model crate cannot depend on the gpu crate, so the number stays a constant in the model crate and a new GPU test ties it to the arena: it allocates the real arena at 2,048 and at 4,096 rows and requires the growth per row to equal the constant, so a count that is too high or too low is caught. Every pin that reads the planner (card plans, the Q3 host and need bytes, the two-slot boundary, the derived context limits) is re-pinned with a PIN(2026-10-28) line and its reason.

Release notes: Fixed: the Qwen3.8 planner no longer over-reserves 27,008 B of card memory per ubatch position, so more experts stay on the card.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. The arena's share is one constant, UBATCH_ARENA_TOKEN_BYTES, read by UBATCH_TOKEN_BYTES and by the GPU test that checks it against the arena's allocation.
  • Model code holds only architecture facts. The change is a byte count and a test; no per-model branch was added to a common owner.
  • Dead code is gone. Nothing I made unused is left behind.
  • No silent failure. The new test names its failure; no error path was added.
  • Comments state what is true now. The PIN(YYYY-MM-DD) lines are the re-pin form the template asks for.
  • No relaxed gate. No band, tolerance or lint moved; each moved pin carries PIN(2026-10-28): and its reason.
  • cargo fmt and cargo clippy are clean on what I touched. cargo fmt --check and check-arch were clean on the head; cargo clippy was clean on bloomery-model and bloomery-placement and was not run for bloomery-gpu, which needs CUDA.

Duplication found or removed (path:line): crates/placement/src/placement/qwen38_cards.rs:269 keeps a hand-copied stage scratch value (scratch_bytes) that follows the model crate's derivation. It was already there; I re-pinned it and did not lift it, because that is a separate change.

What I ran

The change is one commit on upstream main e009acd4f93e930ae906572acbdcc0c92345d666, head 6e2c57c370b5c9a41ee8046611cceb6297c45246. The GPU gates ran on the same change before upstream main moved to this base; the later main commits touch none of its files.

On the RTX 5090 machine, the new arena test measures the arena's growth between 2,048 and 4,096 rows: 1,016,725,504 B over 2,048 rows, which is 496,448 B a row, equal to the plan's constant:

bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- --include-ignored hw_a_ubatch_arena_holds_a_position --nocapture
ubatch arena: 1016725504 B over 2048 rows, the plan counts 496448 B a row
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 436 filtered out; finished in 15.26s

The Qwen3.8 reserve, meta, host and plan gates on the same machine, with the Q4 file Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf and the MTP file mtp-Qwen3.8-Flash-Next-Q8_0.gguf:

just gate-qwen4exp-meta
gate-qwen4exp-meta rc: lib 0 reserve 0 meta 0 mtp 0 host 0 bp 0
cargo test --release -p bloomery-placement --lib qwen38_cards
test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 179 filtered out; finished in 0.46s

The derived context limits that the MTP pins now carry were measured by that gate:

A6000 with the draft holds ctx 1220191 (true; predicted 1220190 + 1) and breaks with CardOver at 1220192 (true): PASS
3090 with the draft holds ctx 386791 (true; predicted 386790 + 1) and breaks with CardOver at 386792 (true): PASS

The recorded fixture budget for Qwen3.8 is lower under the new reservation, so a fixture written under the old one is refused as not the least. I regenerated the fixture with fixture fetch as docs/contrib/local-check.md describes, and the budget gate on this head then ran:

just gate-fixture-budget
qwen38: budget 9327083520, experts a layer [256, 256, 256, 256]
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 12 filtered out; finished in 0.14s

Not run: a timed A/B, since no kernel or launch changed, and cargo clippy for bloomery-gpu.

Hardware

An RTX 5090 machine (this is a host-side planner change with a GPU allocation test):

| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
|   0  NVIDIA GeForce RTX 5090        Off |   00000000:01:00.0 Off |                  N/A |

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…ation

The plan counted 130,852 f32 and 12 u32 a position for the ubatch walk's
arena (523,456 B), but the arena Arena38::wide allocates holds 124,100 f32
and 12 u32 (496,448 B): it has held no query rows since the prefill flash
norms and turns the queries in its staging (6,144 f32), and no separate
beta and alpha rows or one-row indexer queries since those joined one
buffer each (96 and 512 f32). Every Qwen3.8 plan set aside 27,008 B a
ubatch position the load never uses, 110,624,768 B at 4,096 positions.

place::UBATCH_ARENA_TOKEN_BYTES now names the arena's share at 496,448 B,
and UBATCH_TOKEN_BYTES is it plus the walk's own buffers, the record and
the host sums (617,337 B, was 644,345). The ignored GPU test
hw_a_ubatch_arena_holds_a_position_the_bytes_the_plan_counts allocates
the arena at 2,048 and 4,096 rows and holds the growth a row to that
constant, both ways.

The card-experts plans gain that room: every pinned A6000 and 3090 plan
row holds more routed experts on the card (2 to 76 a row for the Q4 file),
and the pins of qwen4exp_meta, qwen4exp_mtp_meta and placement's
qwen38_cards move with dated PIN lines. A plan that already holds every
routed expert on the card (one GB10 at the default context) places the
same experts with a smaller card need.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement labels Oct 27, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: CLEAN: the plan constant now equals the arena's measured growth per row, and every re-pinned value follows from the 27,008 B change.

Checked

  • Duplicates: 3 new items (UBATCH_ARENA_TOKEN_BYTES, the new test, the 120_889 term) checked; no second owner. dryer: 0 pairs.
  • Complexity: crapper flagged nothing.
  • Silent failure: 0 new defaults or swallowed errors. The new test uses expect and assert_eq, so a wrong count fails by name.
  • Arithmetic [derived]: 523,456 − 496,448 = 27,008 = (6,144 + 96 + 512) · 4. 496,448 + 120,889 = 617,337 and 644,345 − 523,456 = 120,889. CARD_SCRATCH, CARD_ROUTE_SCRATCH, both max-context pins and the Q3 host bytes (−196,300,800) recompute from 4,096 · 27,008 = 110,624,768.
  • Tests: the test is hw_-prefixed and #[ignore]d. Mutants: a new per-row buffer in Arena38::alloc or a changed UBATCH_ARENA_TOKEN_BYTES turns assert_eq!(grown / rows, plan) red. A buffer that does not grow with rows is not checked, which is right, because UBATCH_FIXED_BYTES covers it. bytes() lists every field of the arena, and select_run and the router rows are equal at 2,048 and 4,096 rows at ctx 8,192.
  • Gates: seven pins moved, each with a dated PIN(2026-10-28):, its reason and its derivation. The PR body shows the gate output on the contributor's card.
  • Hot path: none changed (planner constants and a test), so no performance term. Escape catalog: no match.

Card check: gpu-evidence. This pull request changes crates/gpu/src/arch/qwen3moe/scratch38.rs and carries a gate run on the author's card, which counts as verified.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 27, 2026
@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit a42fa24 into midagedev:main Oct 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app gpu-evidence Verified on the author's card: the pull request carries the gate run and its output model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja placement Placement planning: crates/placement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant