Skip to content

metal: generate_metal --plan, every open refusal from the header - #806

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

midagedev merged 3 commits into
mainfrom
mac-plan

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Part of #593 (Phase 1a in docs/research/metal-all-models.md, #802).

The Metal open checked a file inside the loader and stopped at the first refusal, after mapping the weights. The checks move to one pure function over the header and tensor table (arch/qwen3moe/check.rs). It returns every refusal in the open's order, or the layout the loader copies. The open stops at the first item with the same text as before. generate_metal --plan [--ctx C] reads only the header (a truncated data section is fine), prints every item, the bytes the open would allocate, the device's working set and the host's free memory, and exits 0 (opens), 3 (refused) or 64 (unreadable header).

Evidence (lead M1 Pro 32 GB):

  • just lab-metal: PASS, 38 lib tests, 125 mutants each red on its clause. just lab-metal-e2e: PASS. r_resident now also pins the plan's buffer count and byte bounds against the live residency set.
  • Open errors byte-identical to the base on six faulted copies of the fixture.
  • --plan on 24 MB header cuts of Hub files: MiniCPM-V Q4_K_M and Ornith Q4_K_M plan: opens; Qwen3.6 UD-Q4_K_XL plan: refused, 350 items (every Q8_0, Q5_K and F32 site); Qwen3-30B-A3B refused at the architecture.

Written with AI help (Claude Code).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q5zTV27LbaVZFTjnkdmTjJ

@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: no behavior bug found, but the diff adds a duplicate --ctx parser, a duplicate PAGE constant and three unneeded elements.

Must fix

1. --ctx is parsed twice

generate_metal.rs:797 in plan_run repeats the parse and the "a cache of no rows" rule that parse already holds at generate_metal.rs:284. A change to one rule will miss the other. One function removes about 16 lines from plan_run and 10 from parse.
Fix: add this next to default_ctx, use let ctx = ctx_flag()?; in parse, and in plan_run replace the whole let ctx = match flag("--ctx") {…}; with let ctx = match ctx_flag() { Ok(c) => c, Err(e) => { eprintln!("generate_metal: {e}"); return ExitCode::from(2); } };

/// The `--ctx` value: absent, or a count of at least one row.
fn ctx_flag() -> Result<Option<usize>, String> {
    match flag("--ctx")? {
        None => Ok(None),
        Some(s) => {
            let c: usize = s.parse().map_err(|e| format!("--ctx {s}: {e}"))?;
            if c == 0 {
                return Err(format!("--ctx {s}: a cache of no rows"));
            }
            Ok(Some(c))
        }
    }
}

2. PAGE has two owners

check.rs:52 adds pub const PAGE: u64 = 16 * 1024. The gate already has the same constant at resident.rs:47, and this PR makes the same file compare against the plan's paged bytes. Two page sizes can drift, and then the gate's bound and the plan's bound disagree.
Fix: delete const PAGE in resident.rs and write buffers as u64 * check::PAGE at line 52. check is already imported there.

3. Unneeded elements in check.rs

  • check.rs:1159 Checked::ctx() has no caller (Grep over the repo).
  • check.rs:1152 Checked::mixers() is called only by one test assertion (line 1477).
  • check.rs:408 session_shape wraps super::session::refuse and has two callers.
    Fix: delete ctx() and mixers() and the mixers() assertion. Replace session_shape(x) with super::session::refuse(x) at lines 386 and 530, then delete session_shape. Keep delta_heads; bytes() uses it.

Non-blocking

⚠ The buffer list in Checked::bytes (check.rs:1166) mirrors Arena::open by hand. No lib test pins the kv, state, scratch or rows classes. Mutant: drop one 1 from the scratch list. Lib tests stay green. Only r_resident on a Mac turns red, through the buffer count.

⚠ check::read (complexity 18, new function) does the summary, the plans, the head, the layers and the final assembly in one body (check.rs:512). Moving the Summary build into fn summarize(split, &spec) -> Summary would be a cheap first cut.

Checked

  • Duplicates: 38 new items checked. Hits: --ctx parse, PAGE. Three refuse copies exist already in arena, rows and session; a fourth in check.rs has its own what, so it is left alone. Dryer pairs: refuse x3 is the same shape with a different what, not a finding. delta against attention in arena.rs shares only a shape.
  • Complexity: RowsLens::of 26 is even growth, a flat field list. plan_run 19 is a flag-check chain, and its duplicate is finding 1. read 18 is a new function (⚠ above). ffn_checks 18 and render 16 are new and flat. r_resident 19→22 adds one comparison.
  • Silent failure: 9 sites followed (unwrap_or, map_or). refused_sites shape defaults only feed the type check. The Summary defaults are display only. checked_or_first names its empty case.
  • Order of refusals: read against the old Arena::open and layer order; it matches.
  • Tests: the old_plan_error comparisons turn red if an item's text or order changes. No lib test covers n_v, the rope base, the experts shape or MAX_SEGMENTS. The PR body says the lab mutants cover them; I could not run the lab.
  • Gates: no pins moved. r_resident gains a clause.
  • Escape catalog: no match (no shell changes).

Notes

  • The PR body names an M1 Pro but gives no commit hashes and no command output. I did not judge it on the author's card. No CUDA evidence is needed; the diff is Metal only.

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

midagedev and others added 2 commits October 26, 2026 15:51
The open's checks ran inside the loader and stopped at the first
refusal, after the weights were mapped. They move to one pure function
over the header and tensor table (arch/qwen3moe/check.rs) that returns
every refusal in the open's order, or the layout the loader copies. The
open stops at its first item with the same text as before; generate_metal
--plan [--ctx C] reads only the header (a truncated data section is
fine), prints every item, the bytes the open would allocate, the
device's working set and the host's free memory, and exits 0 (opens),
3 (refused) or 64 (unreadable header).

r_resident also pins the plan's buffer count and byte bounds against the
live residency set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q5zTV27LbaVZFTjnkdmTjJ
github-actions[bot]
github-actions Bot previously approved these changes 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.

Since the last review:

  • Duplicate --ctx parsing: fixed by generate_metal.rs:370, used by both modes.
  • Duplicate PAGE: fixed at resident.rs:49, which uses the existing owner.
  • Unneeded elements: fixed. Checked::ctx, Checked::mixers, and session_shape were removed.
  • Buffer-class coverage: fixed by check.rs:1486.
  • Summary extraction advisory: fixed by check.rs:508.

Verdict: CLEAN: The earlier must-fix items are resolved, and the new commit preserves validation and refusal behavior.

Checked

  • Duplicates: 6 new functions/constants checked; no actionable duplication. All 5 dryer pairs read: refusal constructors and distinct mixer loaders, unchanged by this interdiff.
  • Complexity: read is now 16 after extracting the summary. RowsLens::of 26, ffn_checks 18, render 16 and r_resident 19→22 belong to the already reviewed patch; no new branch growth in this commit.
  • Silent failure: 3 sites followed. The two summary defaults reach display only; an empty refusal list still returns a named error.
  • Tests: static mutation checks. Removing the cache tally at check.rs:1186 fails the new KV equality; dropping scratch's ticket at check.rs:1216 fails its scratch equality. Removing a weight addition at check.rs:1159 fails the modified clean-table test's weight-byte equality.
  • Adversarial checks: zero, malformed and missing context values retain their error paths. Header errors return before summary construction. The empty-refusal fallback remains an error.
  • Gates: no thresholds moved; the residency tolerance uses the same page size. The removed accessor assertion was replaced by class accounting assertions.
  • Performance: load-time checks, CLI parsing and test accounting only; no decode or prefill work added.
  • Escape catalog: no matching pattern.

Notes

Metal tests were not run here; the gates require Apple Silicon and macOS. The PR reports an M1 Pro run but supplies neither commit hashes nor captured command output.

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

…del-path reader); model-tax row lowered to 2

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.

Since the last review:

Verdict: CLEAN: The incremental changes preserve model-path validation, error text and exit codes.

Checked

  • Duplicates: 1 new function checked. model_path replaces two copies; existing fixture and GPU gate readers have different contracts. All 5 dryer pairs read: four short refusal-constructor pairs and two distinct mixer loaders; unchanged by these commits.
  • Complexity: crapper flags RowsLens::of (26), ffn_checks (18), read (16), render (16), and r_resident (19→22) belong to the previously reviewed patch. None changes in this incremental diff.
  • Silent failure: 1 model-path match followed through 2 callers. Missing or empty values produce the same named error and exit 2.
  • Tests: no new or changed tests; no new mutation check applies.
  • Adversarial checks: absent, empty, non-Unicode and nonexistent paths retain their previous handling. Both callers propagate the helper's error. The non-macOS refusal remains outside the changed module.
  • Gates: no runtime thresholds or tests moved; the model-tax count decreases with the grouped imports and shared error text.
  • Performance: CLI setup only; no decode or prefill work changes.
  • Escape catalog: no matching pattern.

Notes

Metal gates were not run; they require Apple Silicon and macOS. The PR reports an M1 Pro run without both commit hashes or captured command output. It does not meet the GPU evidence requirements.

🔨 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