Skip to content

metal: Qwen3-30B-A3B's decode as a second build-time instance - #849

Merged
midagedev merged 3 commits into
mainfrom
mac-q30c-r2
Oct 26, 2026
Merged

midagedev merged 3 commits into
mainfrom
mac-q30c-r2

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Adds Qwen3-30B-A3B (qwen3moe_a3b) as the second Metal instance next to Qwen3.6-35B-A3B. The attention kernels become head-generic (head dim 128 or 256), the router runs without a shared expert, and the open checks a 30B file against its instance.

A host build picks the 30B instance only with the cargo feature host-qwen3moe-a3b. A default build refuses a 30B file by name, also under --plan. This is a stepping stone: the host lift (follow-up PRs) makes one build open both, and removes the feature. The 30B is not claimed as supported until then.

Evidence (second M1 Pro, macOS 27.0.1, on ac7647b):

just affected selects 0 of 247 gate recipes (the Metal crate builds on macOS only). The e2e gate is not run: it is barred on the maintainers' Macs.

AI use: written and checked with Claude Code.

🤖 Generated with Claude Code

midagedev and others added 2 commits October 27, 2026 05:34
…ntion, a router without a shared expert, the 30B fixture's kernel clauses and mutants, the open's checks for the instance

The host build picks one instance by the host-qwen3moe-a3b feature at one
point (instance.rs's HOST); a default build refuses a 30B file by name at
open and in --plan. The rows arm stays refused for the 30B instance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 26, 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: one fact ("the host's experts run a shared slot") has two owners in this diff; the kernels and the head-generic attention otherwise hold up.

Must fix

1. HAS_SHARED is defined twice, and router::SHARED already owns the fact

experts.rs:21 defines EXPERT_SLOTS > ROUTED_IDS. clauses_experts.rs:29 defines SHARED_SLOT < EXPERT_SLOTS. Both read router.rule.gated through different expressions, and router_geom::SHARED (router_geom.rs:19) is a third spelling. If one changes (for example a shared expert with no gate), the launch check and the gate disagree and the gate no longer tests what the launch accepts.
Cost: the gate is where a drift would show, so it must not carry its own copy.
Fix: one owner next to SHARED_SLOT, two deletions (net minus one const).

// crates/metal/src/kernels/experts_geom.rs, after SHARED_SLOT
/// Whether the host instance's experts run a shared expert's slot after the routed ones.
pub const HAS_SHARED: bool = SHARED_SLOT < EXPERT_SLOTS;

In kernels/mod.rs:67 add HAS_SHARED to the experts_geom re-export. In experts.rs import it from super::experts_geom and delete lines 19 to 21 (they also sit between two use lines). In clauses_experts.rs import it from bloomery_metal::kernels and delete lines 28 and 29.

Non-blocking

⚠ GATED in the gate is a second spelling of key.attn.q_gate: clauses_attention.rs:48 derives it from QG_STRIDE == 2 * HEAD_DIM, while build.rs (agated) reads HOST.key.attn.q_gate. HOST is already imported in the gate's mac.rs; HOST.key.attn.q_gate removes the inference.

⚠ Fourteen tests end at once in a host-qwen3moe-a3b build: check.rs:1530 and the same if !judged_here() { return; } in 13 more. cargo test reports them green with no assertion run. Prefer #[cfg(not(feature = "host-qwen3moe-a3b"))] on the test so the report does not count them, or say in the PR body that they are skipped by design.

⚠ The 30B session takes its prompt in PrefillMode::Steps (session.rs:786), one decode step per prompt token, because the rows arm needs a shared expert (rows.rs:654). The PR body says it is a stepping stone, so this is a question: is the rows arm without a shared expert the follow-up PR?

Checked

  • Duplicates: about 30 new items checked; hits are HAS_SHARED (item 1) and GATED (⚠). dryer pair clauses_attention.rs:553-570 ~ 572-589 is dequant_k and dequant_v: two short K/V mirrors, only the Q8 constants changed, no fix asked.
  • Complexity: ffn_checks 18 to 24 is the joined decision added in its one owner (fine). check_pair, check_fold, router::check grow by match arms for the no-shared case (even growth). The other flagged functions grow by 1 to 3 branches. No #[kernel] or #[target_feature] body is split.
  • Silent failure: 8 sites followed. shared.unwrap_or(p.down) and p.shared.unwrap_or(&p.routed) are reached only when HAS_SHARED / SHARED is false, and the checks refuse the mismatch by name first. cut with no store refuses n past the position; SnapBufs::open and shared_of return named errors. select_f32's unwrap_or(0) is unchanged code.
  • Performance: hot path is the decode attention kernel. At head 256 the diff adds no launch, copy, allocation or sync, and the sum order (warp sums, fold) is unchanged. metal-compare in the PR body covers the changed pipelines.
  • Kernel shapes at head 128, read by hand: shared block 16 KB (factors 32 heads x 64 segments x 2 floats; tiles 8 KB), q8 tile offsets 8 and 12 and 16 words a row fit it, the fold is 8 threads a head x 32 heads = 256, and the prefill stage fills 2 * PF_TILE_HALVES exactly (the assert holds).
  • Tests (mutation): q30_target_folded_within_64 (a dropped Q6 second dispatch gives 313, red); each_shape_selects_its_instance (a 30B row with q_gate: true selects no instance, red); the four Q30_MUTANTS each edit a line only the 30B geometry exercises.
  • Gates: no band or tolerance moved. model-tax.tsv count 4 to 13 stays under its existing PIN(2026-10-27) row.
  • Escape catalog: no match (no shell script in the diff).

Notes

The evidence is an Apple M1 Pro run, not the nvidia-smi list in CONTRIBUTING.md; this change has no CUDA path.

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

…her and the gate read it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@midagedev

Copy link
Copy Markdown
Owner Author

Fixed in 13a28bb: HAS_SHARED is one pub const in experts_geom.rs next to SHARED_SLOT, re-exported from kernels; the two local copies are gone. Second M1 Pro: clippy -D warnings rc 0 (default and host-qwen3moe-a3b); just lab-metal PASS (155 mutants); the 30B build's kernel gate PASS (29 mutants).

@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 one must-fix from the last review is fixed, and the new commit adds no new defect.

Since the last review:

  • Must fix 1 (HAS_SHARED defined twice): fixed. experts_geom.rs:28 is now the only definition. experts.rs and clauses_experts.rs import it. The value is the same as before: SHARED_SLOT is top_k, which equals ROUTED_IDS, so SHARED_SLOT < EXPERT_SLOTS equals the old EXPERT_SLOTS > ROUTED_IDS.
  • ⚠ GATED second spelling (clauses_attention.rs:48): still open, not blocking.
  • ⚠ Fourteen judged_here() tests that end at once in a 30B build: still open, not blocking.
  • ⚠ 30B prompt in PrefillMode::Steps (question): no answer yet.

Checked

  • Duplicates: 1 new item checked (HAS_SHARED), Grep finds one definition. The dryer pair was read in the last review (dequant_k and dequant_v, no fix asked).
  • Complexity: the new commit adds no function. The earlier crapper outcome stands.
  • Silent failure: no new site. The commit removes two consts and adds one re-export.
  • Tests: no test added or changed. ROUTED_IDS and EXPERT_SLOTS are still used in experts.rs, so no unused import under -D warnings.
  • Gates: no pin moved.
  • Escape catalog: no match.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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