Skip to content

metal: MLX 8-bit and F16-scaled folders open on Apple Silicon - #1057

Merged
midagedev merged 7 commits into
mainfrom
mac-f16-r2
Oct 31, 2026
Merged

midagedev merged 7 commits into
mainfrom
mac-f16-r2

Conversation

@midagedev

@midagedev midagedev commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Supersedes #1050: the same change, rebased on main after #1047, with #1050's review fixes. It also names the <q>_norm_next entries #1047 added for A8, A4H and A8H.

What and why

The Metal backend opened only MLX folders quantized to 4 bits with BF16 scales (MLX_A4). Many MLX folders hold other
kinds:

  • 8-bit weights: LFM3-1.7B-MLX-8bit; the routers and some layers of mixed DWQ folders such as Qwen3.6-35B-A3B-4bit-DWQ.
  • F16 scales and biases: every mlx-community Llama and Mistral folder.

This adds MLX_A8 on every launch kind MLX_A4 has. It also adds MLX_A4H/MLX_A8H (ids 2006/2007, F16 scale and bias),
and opens a session on all four kinds. A4 and A8 are each one template owner over the scale pair (A4T<Pair>,
A8T<Pair>, Pair = AffineBf16 or AffineF16). Two config keys are now read:

  • a Qwen3.6 folder's rope_parameters.type;
  • a tokenizer's tool_parser_type.

Release notes: Added — Apple Silicon opens MLX 8-bit folders, mixed 4/8-bit (DWQ) folders, and folders with F16 scales.

Code shape

  • No second copy. The BF16 and F16 kinds share one A4 and one A8 owner. Only the scale pair's widen differs.
  • Model code holds only architecture facts.
  • Dead code is gone.
  • No silent failure. These are refused by name:
    • a weight whose two companions differ in dtype, or are F32;
    • a non-finite F16 scale;
    • a 4-bit router, which the open dequantizes on the host;
    • an F16 embedding or head.
  • Comments state what is true now.
  • No relaxed gate.
  • cargo fmt and clippy are clean; the lint count did not go up.

Duplication found or removed: none.

What I ran

All on an M1 Pro (32 GB, macOS 27.0), the second maintainer Mac.

Gates, on the rebased head:

  • cargo test -p bloomery-metal --lib: 115 passed. One test fails the same way on main and is skipped:
    model_arg::tests::a_cached_checkpoint_repo_is_its_folder_with_nothing_fetched.
  • model-hf lib: 121 passed. hf lib: 165 passed.
  • gate_metal_device: PASS. gate_metal_qwen35moe_kernels: PASS on all 6 instances.
  • gate_metal_qwen35moe_kernels --mutants-all: PASS (qwen35moe_a3b 226, qwen3moe_a3b 98, gdn48 24, gqa6 34, gqa4 34,
    lfm3_attn 20). It includes three new mutants: half_scale_as_bf16, half_bias_as_scale, half_widen_as_bf16.
  • gate_metal_qwen35moe_e2e: PASS on 4 rows. e2e --mutants-all: PASS (qwen35moe 12, qwen38d 3, lfm3 3).
  • just mac-static origin/main: green after tools/hf-arch-check.py learned to read the new or-pattern arm
    (MlxA4 | MlxA8 | … => None). Every tools/check-*.sh is green on the rebased head.

metal_scan --compare against main 904266c: added=123, removed=0, changed=59. The changed entries are the existing
A4 programs; their names are now the template's (archive +96 B each). On Qwen3.8-27B MLX 4-bit, base and this branch
gave:

  • --logits-hash 32 bit for bit the same (79b3c52ec6067bd4);
  • decode_rest_ms 111.66 / 112.04 (base) and 111.65 / 111.60 (this branch), interleaved.

Real folders (generate_metal):

  • Qwen3.6-35B-A3B-4bit-DWQ (mixed 4/8-bit) opens. Its text is coherent ("The capital of France is Paris, a city
    renowned for …"; a fibonacci body).
    • Greedy on a random-id prompt splits from mlx-lm 0.32.0's at step 2.
    • Teacher-forced over our 12 ids, mlx-lm's own forward picks each of them. At step 2 our pick leads its second
      by 0.25.
    • So the split is mlx-lm's incremental decode at a near-tie.
  • LFM3-1.7B-MLX-8bit opens, and its text is coherent. mlx-lm 0.32.0 does not load lfm3, so there are no
    reference ids.

Hardware

Apple M1 Pro, 32 GB, macOS 27.0.

AI use: written with Claude Code (Sonnet and Opus rounds implemented it; the maintainer's lead session reviewed and ran
the gates).

🤖 Generated with Claude Code

midagedev and others added 7 commits November 1, 2026 03:10
…vec modes, GEMMs, routed pairs, experts, head and embedding — with its kernel-gate clauses and three mutants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…H), and every MLX affine kind opens a session

Llama and Mistral MLX folders store each group's scale and bias as F16; the Qwen folders store BF16. Two kinds hold the
F16 pair as stored (MLX_A4H 2006, MLX_A8H 2007): gguf's dequant takes the pair type, the planner places a weight by its
companions' dtype (a weight whose scales and biases disagree is refused by name), a plain F16 tensor widens to F32
exactly. On Metal the A4 and A8 decode owners take the pair as a parameter (A4T<Pair>, A8T<Pair>), so the H kinds are
instances on every launch kind A4 and A8 have. The open path (chain sites, the session's launched and projected
sites, the open's checks, model-hf's MLX type maps, the router's host dequant) takes MLX_A8, MLX_A4H and MLX_A8H.
Kernel-gate clauses for the H kinds and mutants half_scale_as_bf16, half_bias_as_scale, half_widen_as_bf16.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…spelling, is read at default

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…serving parses tool calls by the model's family

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e value; one missing-fixture owner, no plane wrapper, one make branch

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app 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 tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 31, 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:

  • Fixed: non-finite fixture values fail before requantization.
  • Fixed: missing-fixture clauses reuse clauses_a4::with.
  • Fixed: expert planes call Fixture::rows_as directly.
  • Fixed: one make branch handles both scale pairs.
  • Still open: Metal proof at crates/metal/kernels/quant.metal:703.

Verdict: CLEAN: the new commits resolve all earlier must-fix items and introduce no proven defect.

Non-blocking

⚠ Reproducible Metal proof: crates/metal/kernels/quant.metal:703 routes the existing A4 calculation through template pair methods. The body reports changed scan entries and timing summaries, but supplies no reproducible program-equivalence comparison. Attach that comparison for the renamed existing programs, both full commit hashes, and commands with output for the reported gates and A/B.

⚠ Protect the fixture refusal: crates/metal/src/bin/gate_metal_qwen35moe_kernels/fixture.rs:308 rejects non-finite values before matrix and expert requantization, reporting tensor, row and column. The new commits add no regression case for this fix. Add NaN and infinity fixture inputs and assert the named refusal; deleting this guard must turn the case red. This protects the gate from accepting invalid fixtures again.

Checked

Duplicates: no new functions, types or constants in the interdiff. The changes reuse clauses_a4::with, remove the plane wrapper and merge the make branches.
Complexity: with_geometry gains three pipeline names; pair_weights_for replaces forwarding calls. The fixture refusal adds one branch.
Silent failure: the new refusal returns a named error through both matrix and expert callers; a clause error makes the gate fail.
Tests: no tests added or changed in the interdiff. No regression case found for the fixture refusal. Device gates were not run during validation.
Gates: no bands, thresholds or pins move in the interdiff. All three new pipeline names have existing SCALED_SEG_ENTRIES instantiations.
Performance: the new pipeline lookups run at construction; the interdiff adds no per-token allocation, copy, launch or synchronization.
Escape catalog: C1–C4 do not match. No ledger lessons are in force.

Card check: needs-gpu. This pull request changes crates/gpu/src/site.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)

@midagedev
midagedev merged commit 49977d3 into main Oct 31, 2026
8 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 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 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