Skip to content

qwen38: a selecting layer keeps its raw indexer keys in a ring of eleven rows, not a plane of the context - #969

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-opt-qsa-rawkey-ring
Oct 29, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-opt-qsa-rawkey-ring

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8의 선택 레이어가 원시 인덱서 키를 컨텍스트 길이만큼 쌓지 않고 11행 링에만 두어, 컨텍스트 262,144에서 슬롯당 768 MiB를 줄이고 출력은 그대로입니다.

What and why

A Qwen3.8 selecting layer used to keep every raw indexer key of the context in a plane (ctx × 128 f16 values), although the pool kernel reads only the last three keys before a launch. The layer now keeps those keys in a ring of eleven rows (3 keys of a pool not yet complete plus an 8-row pass) and the pool kernel reads the launch's own keys from the key projection. Store38 is the one store of both seats (FP4-Local and NVFP4 folders, and the GGUF file), so all of them get it.

Per slot and selecting layer the store loses ctx × 256 bytes and gains 11 × 128 × 2 = 2,816 bytes. With 12 selecting layers a slot saves 12 × 256 × (ctx − 11) bytes: 805,272,576 bytes (768 MiB) at the default context of 262,144. Decode and prefill speed and the generated text do not change.

Release notes: Changed: Qwen3.8 uses 768 MiB less GPU memory per slot at the default context, with identical output.

Code shape

  • No second copy. The ring size has one owner, runtime::stores::index_ring_rows, and qsa::RING_ROWS is held to it by a const assertion in scratch38, the same pattern as the conv ring and the PLE ring.
  • Model code holds only architecture facts. No common owner gained a per-model branch, flag or trait method.
  • Dead code is gone. The by-position raw key span (Spans::by_position(raw, ..)) and the raw term of seq_positional_bytes are removed.
  • No silent failure. A pool launch whose counts are not consecutive raises PoolSelect and writes no pool; every appended key is still checked for a non-finite value.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved; the gate clauses read the new kr and ring arguments.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none added. Existing, unchanged by this PR: slot_digest in crates/gpu-gates/src/bin/gate_qwen38_twocard.rs:1148 and crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs:4624.

What I ran

All runs: NVIDIA GB10, driver 595.84, CUDA 13.3.1 (nvidia-smi). Memory, output equality, speed and gate_qwen4exp_e2e: base 5e743ada812e7377054e4d8a8756b7c466c833ae, head 9f1286a122a552d27936db5b7e665aab2ca3e593. gate_qwen35moe_attn: base 686e8cc5ffb0cb20027fe315bd0dfb2863b17c0b, head 69387e07f0d16dd9a950655bd5e06836559d5cac.

Memory. Real bloomery-serve, default flags, context 262,144, one slot, MTP draft on, base and head, FP4-Local and NVFP4 folders. The saving equals the formula above.

metric base head difference
FP4-Local store_bytes 7,936,888,448 7,131,615,872 −805,272,576
FP4-Local resident_bytes 87,743,927,080 86,938,654,504 −805,272,576
NVFP4 store_bytes 7,936,888,448 7,131,615,872 −805,272,576
NVFP4 resident_bytes 91,748,229,928 90,942,957,352 −805,272,576

Output equality. The same serve run sends short and 12,123-token prompts, a live-slot cut and a saved-state restore to the base and the head build:

fp4l head text equals base for every request: True
fp4l every long reply (fresh, live-slot cut, saved-state restore) one text: True
nvfp4 head text equals base for every request: True
nvfp4 every long reply (fresh, live-slot cut, saved-state restore) one text: True
serve A/B PASS

Speed. run.py short --item opt-qsa-rawkey-ring --select fp4l-off,fp4l-mtp, three rounds a side, FP4-Local folder, base against head, greedy output equal (greedy_equal: True). No difference is measurable: each one is below the run-to-run resolution and the round ranges overlap.

metric base head difference ranges overlap
fp4l-off / code-fn decode tok/s 32.5644 32.4789 −0.262% yes
fp4l-mtp / code-fn decode tok/s 59.1681 59.1163 −0.087% yes
fp4l-mtp / prose-en decode tok/s 43.0169 42.619 −0.925% yes

Gates. Both on the same card, through tools/box.sh:

cargo oxide build ... --bin gate_qwen35moe_attn && bash tools/gpu-gate.sh gate_qwen35moe_attn
qsa pool counts 1..=8193 ctx=8200: 2048 pools bit_exact_host=true ... seven-row and one-row launches the same plane=true
qsa pool fault: counts 4 and 13 in one launch, layer 13: ... pool 0 written true, the other pools unwritten true PASS
qsa pool fault: counts 1, 9, 3 and 4 in one launch, layer 13: ... every pool unwritten true PASS
qsa pool PASS
gate_qwen35moe_attn: PASS
gate_qwen35moe_attn: clauses: 24 ran, 0 left to the real tier

The pool clause feeds the current launch's keys as f32 values between two f16 values. With the pool kernel's f16 round-trip removed, the same gate fails:

qsa pool counts 1..=8193 ctx=8200: 2048 pools bit_exact_host=false ... seven-row and one-row launches the same plane=false
gate_qwen35moe_attn: FAIL
FAIL-FIRST CONFIRMED: mutant rc=1; pool bit_exact_host=false FAIL
BLOOMERY_TIER=fixture BLOOMERY_MODEL=qwen4exp gate_qwen4exp_e2e (qwen3.8-next-q4-1 fixture)
clauses: 26 ran, 8 left to the real tier
gpu-gate.sh: gate_qwen4exp_e2e ran 381 s (exit 0)

The kernel gate's counts 4 and 13 in one launch clause and the one-row launch clause are new, and gate_qwen4exp_e2e checks the ring's live slots and the (kp) prefix restore, so the new key ring is exercised through the pool kernel, the checkpoint cut and restore, and the store byte formula.

AI help

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

…ven rows, not a plane of the context

The pool pass reads a launch's own keys from the key projection and the
keys before it from the ring, and runs before the append, which writes the
launch's last eleven keys. The ring is a checkpoint store beside the conv
and PLE rings, so a cut or a resume to a point finds the keys of its
incomplete pool; a saved state no longer carries the raw keys by position.
runtime::stores counts the ring (index_ring_rows) and the plan, the
checkpoint price and the gates follow it.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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 29, 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: No must-fix findings remain; the two evidence requests are advisory.

Non-blocking

⚠ Complete the prefill performance proof: crates/gpu/src/qsa.rs:604.
For a pool wholly inside a prefill launch, key-input reads rise from 1,024 to 2,048 B and add 512 f32-to-f16 conversions [derived: four rows of 128 values]. The reported decode A/B does not time this path. Supply same-card prefill A/B at P=512 and 4096 and base/head PTX register/shared-memory columns to check occupancy.

⚠ Complete the reproducible GPU evidence: crates/gpu/src/arch/qwen3moe/wide38.rs:2705.
The gate build command contains ...; the body gives card details in prose and omits exact model paths. Attach the complete build/gate commands and output, literal nvidia-smi line, model paths, and corresponding base/head hashes. These make the reported runs reproducible; the supplied excerpt does not satisfy the GPU evidence list.

Checked

Duplicates: dryer's conv/index-ring pair shares short sizing arithmetic for different stores; a shared wrapper would add an element.
Complexity: supplied diagnostics report pool_check 28→68, qsa_pool 8→13 and sel_flash_check 107→111. The pool kernel adds count guards.
Silent failure: pool count guards raise PoolSelect and return before writing an invalid pool.
Tests: pool_check checks host equality, one-row/seven-row equivalence and count/position-gap faults. The PR reports an f16-rounding FAIL-first.
Gates: the diff adds dated reasons for changed memory, placement and unsafe-count pins.
Escape catalog: neither advisory finding matches C1–C4.

Notes

Validation was static and used the supplied diagnostics. Rust builds and GPU gates were not run during validation.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen35moe_attn.rs, crates/gpu-gates/src/bin/gate_qwen38_serve.rs, crates/gpu-gates/src/bin/gate_qwen38_twocard.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

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

@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 336e222 into midagedev:main Oct 29, 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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant