Skip to content

fix(convert): keep recipe-pinned o_proj/out_proj/in_proj_a/b 8-bit affine under --q-mxfp - #89

Merged
Brooooooklyn merged 3 commits into
mainfrom
worktree-fix-mxfp-oproj
Jul 8, 2026
Merged

Brooooooklyn merged 3 commits into
mainfrom
worktree-fix-mxfp-oproj

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

apply_mxfp_upgrade upgraded the four recipe-pinned attention/GDN projections — self_attn.o_proj, linear_attn.out_proj, linear_attn.in_proj_a, linear_attn.in_proj_b — from 8-bit affine to mxfp8 under --q-recipe … --q-mxfp.

The unsloth/qwen3_5 recipes deliberately pin these to 8-bit affine so AR (M=1) and MTP-verify (M≥2) both route through the M-invariant qmv kernel (T=0 MTP↔AR bit-exactness), and 8-bit affine specifically keeps the worst-KLD out_proj (~6.0) near bf16. mxfp8's coarse E8M0 scales have ~10× the round-trip error of affine 8-bit, so the upgrade regressed exactly those tensors. The recipe author guarded against the nvfp4 path but not mxfp, and the CLI help already claimed "o_proj/out_proj at 8-bit affine" — contradicting the code.

Fix

  • New is_bitexact_affine_proj guard in apply_mxfp_upgrade, gated on the pinned Custom{bits:8, mode:"affine"} decision, so those keys keep 8-bit affine — symmetric with apply_nvfp4_upgrade, mirroring the existing router-gate / affine-only exclusions. Scoped to apply_mxfp_upgrade; the uniform/no-recipe path is unchanged.
  • Decision-scoped (not key-only), so generic mixed_* recipes — which give these keys low bits (e.g. mixed_4_6 → 4-bit affine o_proj) — still upgrade to mxfp4. Skip (MTP layers) is preserved via the main match.
  • Docs/comments made accurate: synced the quantMxfp doc across all 6 copies (2 Rust structs + 4 .d.cts blocks), fixed the stale bf16 row in cli/README.md, reworded the --q-mxfp help + qualified the run banner, added feed_forward.gate to the router-gate list, and corrected stale router-gate comments in convert.rs / persistence.rs / sparse_moe.rs against a verified control-flow trace (decision → emission → load-time resolution).

Tests

  • New apply_mxfp_upgrade_preserves_bitexact_affine_projections (pinned → stays affine; MTP Skip preserved) and apply_mxfp_upgrade_promotes_non_pinned_low_bit_projections (mixed_* low-bit → mxfp4).
  • 112/112 convert unit tests pass; yarn typecheck, cargo clippy -D warnings, cargo fmt --check all clean.

Follow-ups (non-blocking, out of scope of this gap)

  • Pre-existing --q-mode doc drift: README.md:133 / docs/cli.md:83 say "affine or mxfp8"; the CLI accepts affine/mxfp4/mxfp8/nvfp4/sym8 (GGUF: 4 modes) — note the GGUF-vs-SafeTensors mode-support nuance.
  • compute_moe_defaults' mxfp8 default_gate_plq branch is unreachable for convert-produced checkpoints (now documented) — candidate loader cleanup.

🤖 Generated with Claude Code


Note

Medium Risk
Changes quantization decisions for --q-recipe unsloth|qwen3_5 --q-mxfp checkpoints (affects model quality and MTP parity); logic is well-tested but convert output differs from before.

Overview
Fixes --q-mxfp incorrectly promoting unsloth / qwen3_5 recipe pins — self_attn.o_proj, linear_attn.out_proj, in_proj_a, in_proj_b — from 8-bit affine to mxfp8, which hurt MTP↔AR bit-exactness and quality on high-KLD layers.

apply_mxfp_upgrade now uses is_bitexact_affine_proj: only when the inner recipe already returned Custom { bits: 8, mode: "affine" } those keys skip the mxfp8 upgrade; mixed_* low-bit decisions on the same keys still upgrade to mxfp4. MoE router gates are forced to 8-bit affine for non-Skip decisions but preserve an explicit Skip (aligned with nvfp4). quantMxfp docs, CLI --q-mxfp help, README recipe table, and MoE gate comments are brought in line with this behavior; two unit tests cover pinned vs mixed-recipe paths.

Reviewed by Cursor Bugbot for commit 395b8f0. Bugbot is set up for automated code reviews on this repo. Configure here.

Brooooooklyn and others added 3 commits July 7, 2026 23:50
…fine under --q-mxfp

The unsloth / qwen3_5 recipes pin four attention/GDN projections
(self_attn.o_proj, linear_attn.out_proj, linear_attn.in_proj_a,
linear_attn.in_proj_b) to 8-bit affine so AR (M=1) and MTP-verify (M>=2)
both route through the M-invariant qmv kernel for T=0 MTP<->AR
bit-exactness, and 8-bit affine keeps the worst-KLD out_proj near bf16.

apply_mxfp_upgrade previously upgraded any non-excluded 8-bit affine
Custom decision to mxfp8, silently degrading these four keys under
--q-recipe unsloth --q-mxfp --q-bits 4 (mxfp8's E8M0 scales have ~10x
the round-trip error of affine 8-bit). Add is_bitexact_affine_proj and
guard the upgrade so the recipe's decision (and any Skip for MTP-layer
keys) is preserved. The nvfp4 path is unaffected (no 8-bit arm).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…under --q-mxfp; fix stale bf16 table

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…cisions

apply_mxfp_upgrade wraps every recipe, not just qwen3_5/unsloth. The
is_bitexact_affine_proj guard returned the original decision for
o_proj/out_proj/in_proj_a/in_proj_b unconditionally, so generic mixed_*
recipes (which assign these keys low-bit decisions, e.g. mixed_4_6 ->
4-bit affine o_proj) no longer upgraded them to mxfp4 under --q-mxfp.
Gate the guard on the pinned Custom{bits:8, mode:"affine"} decision so
mixed_* low-bit decisions still promote; Skip falls through to the main
match. Adds a regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7959858a-d62b-4085-b9a4-75e56fff3bf5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-fix-mxfp-oproj

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_72184bc5-6b92-4c48-9596-7336bee776f1)

@Brooooooklyn
Brooooooklyn merged commit 31f3502 into main Jul 8, 2026
7 checks passed
@Brooooooklyn
Brooooooklyn deleted the worktree-fix-mxfp-oproj branch July 8, 2026 09:02
Brooooooklyn added a commit that referenced this pull request Jul 9, 2026
…#93)

## What

CI's rolling `stable` toolchain bumped to **rustc/clippy 1.97.0
(2026-07-07)**, which added the **"redundant reference in `format!`
argument"** lint. That trips the existing `cargo clippy --all-targets --
-D warnings` gate on a pre-existing line in
`crates/mlx-core/src/tools/mod.rs`:

```rust
error: Some(format!("Tool call missing name: {}", &raw_content)),   // &raw_content is now flagged
```

This is what turned the **Rust Lint → Clippy** job red on `main` (first
failure on #89, then the #90 merge — run `29022183758`). The code itself
dates back to #64; nothing on #90 touched it — a toolchain bump surfaced
it.

## Fix

Inline the captured identifier:

```rust
error: Some(format!("Tool call missing name: {raw_content}")),
```

`raw_content` is still moved into the struct field on the next line, so
behavior is unchanged.

## Verification

Reproduced the CI toolchain locally (`rustup update stable` → clippy
`0.1.97 (2d8144b788 2026-07-07)`) and ran the exact gate:

```
cargo clippy -p mlx-core --all-targets -- -D warnings
    Finished `dev` profile in 2m 34s   # exit 0, no redundant-reference error
```

Only remaining output is the pre-existing `block v0.1.6` future-incompat
note (present on all green runs; not a `-D warnings` failure).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> One-line formatting change in an error message path; no logic or API
changes.
> 
> **Overview**
> Unblocks **Rust Lint → Clippy** on CI after **clippy 0.1.97** started
enforcing the redundant-reference-in-`format!` lint under `-D warnings`.
> 
> In `ToolCallResult::missing_name`, the error string now uses inline
capture (`{raw_content}`) instead of `{}", &raw_content`. The message
and move semantics are unchanged.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
44cc4cd. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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