Skip to content

qwen38: validate completed target rows and own draft input - #980

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q1a-mtp-input
Oct 29, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q1a-mtp-input

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 MTP가 마지막 층이 끝내지 않은 hidden 행이나 오래된 Own 입력을 읽지 않고 거부하도록 고쳤습니다.

What and why

The Qwen3.8 MTP draft reads two inputs from shared arenas: the target's final hidden rows and its own row. Neither input was checked for validity before the draft ran.

  • A launch that skipped the last layer for a row (a Gemm read suffix, or a Pass without head or finals) left that row selectable as a final hidden row, so the draft could start from a row the target never completed.
  • After a slot swap (A to B to A) or a cut, the draft's own row still looked usable, although a walk had run since it was written and its Rows refresh was missing.

Wrote38 in body38.rs keeps the positions the last layer completed. launch updates it for Gemm and for a Pass without head or finals, and the MTP copy and the checkpoint hidden-row access consult it. mtp38.rs records the position of the next own input. A slot swap, a cut, a reset, a store walk, a state adoption or a new walk invalidates it, and a successful Rows refresh renews it. A request for a row that is not complete, or for an own row at the wrong position or before a Rows refresh, is a named error. GPU kernels, launch counts and the work done for valid input are unchanged.

Release notes: Fixed: Qwen3.8 MTP rejects hidden rows the target has not completed and own draft rows that are stale or at the wrong position.

Code shape

  • No second copy. The existing Held bookkeeping, the plain and drafted greedy runners and the slot owner are reused.
  • Model code holds only architecture facts. The change is in the Qwen3.8 files and adds no branch to a common owner.
  • Dead code is gone. Nothing I made unused is left behind.
  • No silent failure. Each rejected input is a named error that says which positions are held and which were requested.
  • Comments state what is true now. No dates, issue numbers or how a bug was found.
  • No relaxed gate. No band, tolerance or lint moved; the new gate clauses were first shown to fail (below).
  • 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.

What I ran

The new hw_mtp_input_validity gate in crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs loads Qwen3.8-Flash-Next-FP4-Local once (ctx 64, ubatch 8, two planned slots) and checks every boundary above, plus that the first 8 drafted greedy ids equal the plain ids.

Command (card runs of this PR's two commits):

BLOOMERY_REF_MODEL=<Qwen3.8-Flash-Next-FP4-Local checkpoint b9ce18a6887e18c089fdea8509a33e63429a3300> \
  bash tools/gate.sh --oxide -p bloomery-gpu-gates --release --features gpu,checkpoint \
  --bin gate_qwen4exp_mtp -- --ignored hw_mtp_input_validity --nocapture

Before the fix (the test commit alone), excerpt of the output, test result: FAILED. 0 passed; 1 failed, rc 101:

(f) Ubatch unfinished first hidden row: ran FAIL
(f) Pass unfinished first hidden row: ran FAIL
(f) Ubatch headed but unfinished first hidden row: ran FAIL
(f) own row at the wrong position: ran FAIL
(f) own row after A to B to A: ran FAIL
(f) own row after a cut: ran FAIL

After the fix, with the fix commit applied:

(f) Ubatch unfinished first hidden row: qwen4exp Mtp38: the Ubatch arena's final hidden rows hold no position, requested positions 0..1 PASS
(f) Pass unfinished first hidden row: qwen4exp Mtp38: the Pass arena's final hidden rows hold no position, requested positions 0..1 PASS
(f) Ubatch headed but unfinished first hidden row: qwen4exp Mtp38: the Ubatch arena's final hidden rows hold positions 3..4, requested positions 0..1 PASS
(iv) Ubatch sink completed first hidden row PASS
(iv) Pass sink completed first hidden row PASS
(iv) Ubatch completed last hidden row PASS
(iv) first 8 drafted greedy ids = plain ids PASS; draft kept 11 ids
(f) own row at the wrong position: qwen4exp Mtp38: the draft's own row is for position 1, requested position 0 PASS
(f) own row after A to B to A: qwen4exp Mtp38: a walk before the draft's own row (Rows refresh required) PASS
(iv) own row after Rows refresh PASS
(f) own row after a cut: qwen4exp Mtp38: a walk before the draft's own row (Rows refresh required) PASS
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 42.59s

No speed claim is made: valid input takes the same kernels and launches as before.

Hardware (if the change is for a machine)

  • Card and driver: NVIDIA GB10, 595.84
  • Model: Qwen3.8-Flash-Next-FP4-Local, checkpoint b9ce18a6887e18c089fdea8509a33e63429a3300
  • Build: --features gpu,checkpoint, release

AI help

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

@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 needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo 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: MUST_FIX: the new GPU gate runs without the shared card and model-load locks.

Must fix

1. Run the input gate under the GPU runner

justfile:1785 calls gate.sh without --gpu. Its GPU=0 path runs Cargo's test directly, so BLOOMERY_GATE_V41_LOAD=1 takes no lock. Start it beside another gate holding the selected card: both loads run together and can exhaust card memory. box.sh:1247 permits this overlap because it expects gpu-gate.sh to wait. This is a kind A concurrency failure.

Fixing this caller now prevents every later batch from repeating the overlap. Extend the existing runner to accept binary test targets, then replace the recipe. Its capture-count check still requires exactly one executable.

--- a/tools/gate.sh
+++ b/tools/gate.sh
@@ -21,3 +21,3 @@
 # cargo refuses --no-run with --doc). A build that runs out ends 124 and says it was the build phase; the run never starts.
-# --gpu before --oxide selects one native --lib test target. Its bounded Cargo call compiles
+# --gpu before --oxide selects one native --lib or --bin test target. Its bounded Cargo call compiles
 # outside the card lock and invokes a capture-only target runner, never the test. Cargo owns the
@@ -134,3 +134,3 @@
   BUILD_ARGS=()
-  LIB=0
+  TEST_TARGET=0
   ARGS=()
@@ -144,5 +144,5 @@
       case "$a" in
-        --lib) LIB=1 ;;
+        --lib | --bin | --bin=*) TEST_TARGET=1 ;;
         --target | --target=* | --doc)
-          echo "gate.sh --gpu: only native library tests are supported; '$a' is not allowed" >&2
+          echo "gate.sh --gpu: only native tests are supported; '$a' is not allowed" >&2
           exit 64 ;;
@@ -152,3 +152,3 @@
   done
-  [ "$LIB" = 1 ] || { echo "gate.sh --gpu: select a library test with --lib" >&2; exit 64; }
+  [ "$TEST_TARGET" = 1 ] || { echo "gate.sh --gpu: select a test with --lib or --bin" >&2; exit 64; }
   SELF=$(cd "${BASH_SOURCE[0]%/*}" && pwd -P)/gate.sh
@@ -244,3 +244,3 @@
 if len(captures) != 1:
-    print("gate.sh --gpu: select exactly one library test; got " + str(len(captures)), file=sys.stderr)
+    print("gate.sh --gpu: select exactly one test target; got " + str(len(captures)), file=sys.stderr)
     sys.exit(64)
gate-gpu-qwen4exp-mtp-input:
    BLOOMERY_MODEL=qwen4exp ./tools/box.sh 'bash tools/ref/needs-env.sh gate-gpu-qwen4exp-mtp-input BLOOMERY_QWEN38_FOLDER && export BLOOMERY_GATE_V41_LOAD=1 && bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --release --features gpu,checkpoint --bin gate_qwen4exp_mtp -- --ignored hw_mtp_input_validity --nocapture'

Non-blocking

⚠ Complete the card evidence: crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs:2573 reads BLOOMERY_QWEN38_FOLDER, but the reported command sets BLOOMERY_REF_MODEL.
Provide the command for the current head with the required variable, its output, the nvidia-smi card/driver line and both tested commit hashes.

Checked

Runner: the non-GPU branch invokes Cargo directly; GPU mode replays exactly one captured executable through gpu-gate.sh. Its current selector requires --lib.
Test: hw_mtp_input_validity reads BLOOMERY_QWEN38_FOLDER and loads onto the first visible card.
Fix: all five proposed patch hunks match the source; the patched runner and replacement recipe pass bash syntax checks.
Rules: no active ledger lessons; no C1–C4 pattern matches these findings. Existing recipe checks do not enforce GPU mode here.

Notes

No GPU build or gate was run during this review.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/mtp38.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
juliankang4 force-pushed the dgx-spark-q38-sa-q1a-mtp-input branch from 53bf8c4 to cfc8cef Compare October 29, 2026 17:54
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label 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.

Since the last review:

  • Must-fix 1 remains open in fixture mode (justfile:1785); real-tier locking is fixed.
  • The card-evidence request remains open; see Non-blocking.

Verdict: MUST_FIX: fixture mode still permits the checkpoint gate to bypass the shared model-load lock.

Must fix

1. Give the runner the checkpoint's actual model identity

justfile:1785 preserves the fixture's BLOOMERY_REF_MODEL. In fixture mode, when it equals BLOOMERY_FIXTURE_MODEL, gpu-gate.sh:2183 clears V41, although the test opens BLOOMERY_QWEN38_FOLDER. With that folder configured, a sufficient card budget and a free card, the checkpoint load can start while another tree holds the model-load lock. The new regression cases clear the fixture inputs, so they miss this path. This is a kind A lock bypass.

Binding the identity now prevents later fixture batches from repeating concurrent whole-model loads. Replace the recipe below and extend its held-load-lock regression case to include fixture mode with matching reference/fixture paths.

gate-gpu-qwen4exp-mtp-input:
    BLOOMERY_MODEL=qwen4exp ./tools/box.sh 'bash tools/ref/needs-env.sh gate-gpu-qwen4exp-mtp-input BLOOMERY_QWEN38_FOLDER && export BLOOMERY_GATE_V41_LOAD=1 && BLOOMERY_REF_MODEL="$BLOOMERY_QWEN38_FOLDER" bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --release --features gpu,checkpoint --bin gate_qwen4exp_mtp -- --ignored hw_mtp_input_validity --nocapture'

Non-blocking

⚠ Complete the card evidence: gate_qwen4exp_mtp.rs:2573 reads BLOOMERY_QWEN38_FOLDER, but the reported command sets BLOOMERY_REF_MODEL.
Provide the current-head gate command with the required variable, its output, the nvidia-smi card/driver line and both tested commit hashes.

Checked

Duplicates: 0 new function/type/constant definitions in the interdiff; existing capture and lock owners are reused. Dryer reports no pairs.
Complexity: crapper's completed_rows, own_row, hw_mtp_input_validity, Mtp38::checked and slots_windows are unchanged by the interdiff.
Silent failure: all 5 added command-status capture sites feed judge_all; zero/multiple captures remain named refusals.
Tests: the new assertions cover binary selectors, held locks and capture-count refusals, but omit fixture identity. Replaying the production fixture condition produced V41=0; binding the checkpoint identity produced V41=1. Both shell files and the inline replacement pass bash -n.
Gates: no pins or thresholds moved.
Escape catalog: no C1–C4 pattern matched the interdiff; no active ledger lessons.

Notes

Dryer excluded crates/gpu-gates. No GPU build, hardware gate or complete runner self-test was run during this review.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/mtp38.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)

Comment thread justfile Outdated
# without BLOOMERY_QWEN38_FOLDER a batch defers it by name (needs-env).
[group('v41-load')]
gate-gpu-qwen4exp-mtp-input:
BLOOMERY_MODEL=qwen4exp ./tools/box.sh 'bash tools/ref/needs-env.sh gate-gpu-qwen4exp-mtp-input BLOOMERY_QWEN38_FOLDER && export BLOOMERY_GATE_V41_LOAD=1 && bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --release --features gpu,checkpoint --bin gate_qwen4exp_mtp -- --ignored hw_mtp_input_validity --nocapture'

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.

Fixture mode drops the model-load lock when BLOOMERY_REF_MODEL matches BLOOMERY_FIXTURE_MODEL, while this test loads BLOOMERY_QWEN38_FOLDER. Bind the runner's model identity to the checkpoint.

Suggested change
BLOOMERY_MODEL=qwen4exp ./tools/box.sh 'bash tools/ref/needs-env.sh gate-gpu-qwen4exp-mtp-input BLOOMERY_QWEN38_FOLDER && export BLOOMERY_GATE_V41_LOAD=1 && bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --release --features gpu,checkpoint --bin gate_qwen4exp_mtp -- --ignored hw_mtp_input_validity --nocapture'
BLOOMERY_MODEL=qwen4exp ./tools/box.sh 'bash tools/ref/needs-env.sh gate-gpu-qwen4exp-mtp-input BLOOMERY_QWEN38_FOLDER && export BLOOMERY_GATE_V41_LOAD=1 && BLOOMERY_REF_MODEL="$BLOOMERY_QWEN38_FOLDER" bash tools/gate.sh --gpu --oxide -p bloomery-gpu-gates --release --features gpu,checkpoint --bin gate_qwen4exp_mtp -- --ignored hw_mtp_input_validity --nocapture'

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-sa-q1a-mtp-input branch from cfc8cef to 47d37a3 Compare October 29, 2026 18:14

@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.

Since the last review:

  • Must-fix 1 is fixed: the recipe binds the runner to the checkpoint folder, and the held-load-lock regression covers real and fixture modes.
  • The card-evidence request remains open; see Non-blocking.

Verdict: CLEAN: the interdiff closes the fixture-mode lock bypass and introduces no proven defect.

Non-blocking

⚠ Complete the card evidence: gate_qwen4exp_mtp.rs:2573 reads BLOOMERY_QWEN38_FOLDER, but the reported command sets BLOOMERY_REF_MODEL.
Provide the current-head gate command with the required variable, its output, the nvidia-smi card/driver line and both tested commit hashes.

Checked

Duplicates: 0 new function/type/constant definitions in the interdiff. The recipe reuses the existing lock owner. Dryer reports no pairs.
Complexity: crapper flags completed_rows, own_row, hw_mtp_input_validity, Mtp38::checked and slots_windows. Their control flow is unchanged by this interdiff; hw_mtp_input_validity adapts its planner argument to the base API.
Silent failure: 2 changed shell status/sentinel sites reach judge_all. An absent checkpoint folder stops the recipe with 67 before the runner.
Tests: removing the justfile:1785 identity binding makes fixture policy skip the load lock; the new held-lock case requires exit 75 and no child, so it rejects that mutant. Both shell files pass bash -n. The planner receives context 64 and ubatch 8, matching the base API and model load.
Gates: no pins, thresholds or cases removed or relaxed.
Escape catalog: no C1–C4 pattern matches the interdiff; no active ledger lessons.

Notes

Dryer excluded crates/gpu-gates. No GPU build, hardware gate or complete runner self-test was run during this review.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen4exp_mtp.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/mtp38.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 33f00dd 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

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant