Skip to content

metal: one build opens every registered instance; the host's geometry is a value the open resolves - #850

Merged
midagedev merged 6 commits into
mainfrom
mac-hostlift
Oct 26, 2026
Merged

midagedev merged 6 commits into
mainfrom
mac-hostlift

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Before this change a Metal build was compiled for one host instance: the launch grids and buffer lengths read that instance's axes as constants, so a default build refused a Qwen3-30B-A3B file and the 30B needed the host-qwen3moe-a3b feature (#849).

Now the open resolves a Geometry (Geometry::of(&Instance), a const fn) from the file's instance:

  • Kernels::geom() and Session::geom() hold it; build.rs writes its MSL header from the same function.
  • The arch (check, arena, rows, session) reads it. open_as refuses a library whose geometry is not the checked file's.
  • The kernel gate runs every REGISTERED row in one build, each clause at its row's geometry. It refuses a row the table does not cover.

Four steps, one commit each (R1, R2a, R3, R2b), plus the removal of a shim nothing reads. The rest of the host shims, instance::HOST and the feature go in a follow-up (R4: the probes and the e2e gate).

Evidence (second M1 Pro, macOS 27.0.1). crates/metal here is byte-identical to the tree these ran on:

  • gate_metal_qwen35moe_kernels: PASS (2 instances) from one default build. --mutants-all: Qwen3.6 row 155 mutants, 30B row 29, each red on its clause.
  • clippy -D warnings rc 0: default, pipeline-scan,encode-trace, host-qwen3moe-a3b.
  • metal-compare against the 30B decode instance (metal: Qwen3-30B-A3B's decode as a second build-time instance #849): rc 0, 181 pipelines the same, encode trace equal at depth ~0 and 600, ids equal. No kernel and no launch moved.
  • FAIL-first (in scratch copies): every row given the first row's geometry turns 19 of the 30B row's 21 clauses red and 70 of Qwen3.6's 124; a library opened at the wrong instance is refused by name; each new const assert breaks the build (E0080).
  • orphan-tests ok, check-model-tax ok, check-comments ok.

A test that pinned the old refusal (a_file_of_another_instance_than_the_host_is_refused_by_name) is replaced by each_registered_instance_is_judged_at_its_own_geometry; the removal carries its date and reason.

just affected selects 0 of 247 gate recipes. 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 5 commits October 27, 2026 07:16
…), held by Kernels and written into build.rs's header; the kernels read it, not HOST

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ld, each clause at its row's geometry

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s Geometry, so one build opens every registered instance

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

@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 unneeded element (ExpertsGeom::folded_blocks); the behavior I traced is correct.

Must fix

1. ExpertsGeom::folded_blocks has no reader

crates/metal/src/kernels/geom.rs:102 adds a field that only its own test reads (geom.rs:298). No launch, no header #define and no gate uses it. The function behind it, experts_geom.rs:39, is only read by the assert at line 49. That assert states the function's own body (slots * (k / BLOCK_VALUES)), so it can never fail. The base's FOLDED_BLOCKS assert compared against a literal 256; this one does not.
Cost: the field and the function are two names, a test and an assert for a fact nothing consumes.
Fix: delete the field (geom.rs:102-103), its init (geom.rs:197), its test assert (geom.rs:298-302), the function (experts_geom.rs:36-41) and the assert line (experts_geom.rs:49). Keep the is_multiple_of and shared_slot asserts.

Non-blocking

⚠ Two names for one value in Geometry: geom.rs:175 delta.groups and delta.partials_stride are both value_heads * PARTIALS_PER_HEAD; delta.group_threads is head_cols; router.k is hidden; router.partials is rows. Each pair is pinned by a test that restates the definition. If you touch this again, keep one name per value where only one reader needs it. Do not add anything for it.

⚠ Removed test has no dated reason in the diff: the removal of a_file_of_another_instance_than_the_host_is_refused_by_name (check.rs) says "carries its date and reason" in the PR body, but I found no date in the diff. Confirm the commit message holds it. The behavior it pinned (host-only open) is gone, so the replacement test is the right owner.

Checked

  • Duplicates: about 60 new items checked (Geometry, four *Geom structs and their methods, sources_of, source_at, row_*, instance_named). One hit: folded_blocks above. Dryer's 3 pairs read: dequant_k_for/dequant_v_for and attn_f16/attn_q8 keep the shape the base already had (K vs V, f16 vs q8); refuse_slots/refuse_k guard two different facts. None is a duplicate. oracle_attention::scale_of is the oracle's own copy of the rule, as in the base.
  • Complexity: run_row (39) is the old main body moved, a flat run of early returns, not new branching. pair_weights_for (26) is pair_weights plus a geometry parameter. delta_bounds and metal_scan::run grew by 1: even growth.
  • Silent failure: 9 sites followed. geom? in check::read stays None only when an item is already pushed (clean is false), so no default reaches the arena. Session open compares checked.geom with kernels.geom() and refuses by name. The 30B has no shared expert, and Session already turns the rows arm off then (session.rs:794), so the prompt pass does not reach shared_of.
  • Hot path: decode and prefill launches read &self.geom.* (a Copy struct held in Kernels and Arena). No allocation, launch, copy or sync is added per token; no sum order or ptx-scan-class change.
  • Tests: each_registered_instance_is_judged_at_its_own_geometry. Mutant: check builds Geometry::of(HOST) for every file. The checked.geom == Geometry::of(inst) assert and the head-width refusal turn red on the non-host row. the_header_is_the_geometry catches a header #define that drifts from the struct. each_geometry_is_its_row mostly restates Geometry::of; the gqa, lane_dims and simd_groups asserts are independent.
  • Gates: no band, tolerance or KNOWN_DIVERGENCE moved; no PIN needed.
  • Escape catalog: no match (no shell changes).

Notes

  • gpu.json is false: the evidence is an M1 Pro run, not the nvidia-smi evidence list. This is a Metal-only change.
  • The session open of a 30B file on a default build is covered by unit tests only; the e2e gate is barred, as the PR says.

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

Comment thread crates/metal/src/kernels/geom.rs Outdated
Comment on lines +102 to +103
/// Blocks of K' of the fold.
pub folded_blocks: usize,

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.

Nothing reads this field except its own test; remove it (and its init and test assert).

Suggested change
/// Blocks of K' of the fold.
pub folded_blocks: usize,

Comment thread crates/metal/src/kernels/geom.rs Outdated
shared_slot: experts_geom::shared_slot(inst),
has_shared: slots > routed_ids,
k: key.moe.expert_ff as usize,
folded_blocks: experts_geom::folded_blocks(inst),

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.

Remove with the field.

Suggested change
folded_blocks: experts_geom::folded_blocks(inst),

@midagedev

Copy link
Copy Markdown
Owner Author

Fixed in ade0c5c: the field, its init, its test assert, experts_geom::folded_blocks and its assert line are gone (16 lines out); grep folded_blocks crates/metal is empty. The is_multiple_of and shared_slot asserts stay. Second M1 Pro: clippy -D warnings rc 0 (default and host-qwen3moe-a3b), cargo test -p bloomery-metal --lib 51 passed.

@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 new commit removes ExpertsGeom::folded_blocks as asked and adds nothing else.

Since the last review:

  • Must fix 1 (folded_blocks has no reader): fixed. The field, its init, its test assert, experts_geom::folded_blocks and the self-evident assert in holds are gone. Grep finds no remaining folded_blocks or FOLDED_BLOCKS in crates/.
  • ⚠ Two names for one value in Geometry: still open at geom.rs:175. It was advice only and the new commit does not touch it.
  • ⚠ Removed test has no dated reason in the diff: not answered in the PR text I can see. Keep the date and reason in the commit message that removes a_file_of_another_instance_than_the_host_is_refused_by_name.

Checked

  • Duplicates: the new commit adds no item. The dryer pairs were read in the first review; none lies on lines this commit adds.
  • Complexity: no function in the new commit changed in complexity. The holds function lost one assert.
  • Silent failure: no site added. holds still asserts is_multiple_of(BLOCK_VALUES) and the shared-slot relation. geometry and Instance are still used in experts_geom.rs, so no unused import.
  • Tests: the removed assert restated slots * (k / 256), the definition of the removed function. No contract is lost; no mutant escapes that another assert caught.
  • Gates: none moved. Escape catalog: no match.

Notes

  • gpu.json is false: the evidence is an M1 Pro run, not the nvidia-smi evidence list. This is a Metal-only change.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant