Skip to content

feat(quant): nvfp4 per-expert global_scale on QuantizedSwitchLinear, streaming, Inkling sanitize, X-ray, and converter (#677 Gap 2) - #739

Merged
goodmai merged 1 commit into
mainfrom
feat/677-gap2-nvfp4-global-scale
Nov 24, 2026
Merged

goodmai merged 1 commit into
mainfrom
feat/677-gap2-nvfp4-global-scale

Conversation

@goodmai

@goodmai goodmai commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

Part of #677 (Gap 2, stacked on #733). Adds per-expert nvfp4 global_scale (F32 [E]) support across the fork, switch builders, expert streaming, Inkling 2 checkpoint sanitize, X-ray tensor inspection, and the universal converter — unblocking mlx-community/Inkling-2-Mini-oQ4e-mtp (#650), MiniMax-M3.1-Flash, and #677 Gap 3 (ModelOpt NVFP4).

Fork (goodmai/mlx-swift-lm, branch basalt-677-nvfp4-global-scale @ f1a251a)

  • QuantizedSwitchLinear: added @ParameterInfo(key: "global_scale") public var globalScale: MLXArray?, per-expert NVFP4 quantization init, direct-arrays init, refusal for non-nvfp4 modes, and globalScale: self.globalScale passed to MLX.gatherQuantizedMM.
  • Load.swift: creates globalScale placeholders on QuantizedSwitchLinear / QuantizedLinear when checkpoint weights carry .global_scale, and refuses non-nvfp4 modes with a clear error.

Basalt

  • Bumped mlx-swift-lm pin to f1a251a1869fe2d70518e4b5a31bef0fe7e3d828.
  • FlintModel.quantizeModulesMatchingPackedWeights: supports .nvfp4 / .mxfp8 and attaches global_scale placeholders on switch/dense layers (split into packedQuantSpec + quantizedReplacement, largest CCN 14).
  • Inkling2Checkpoint.swift: maps experts.w13|w2.global_scale → experts.gate_up_proj|down_proj.global_scale.
  • StreamedSwitchLinear & ExpertStreamingLoader: keeps per-expert globalScales: [Float]? on ExpertLayout and refreshes a per-slot copy slotGlobalScales on each slot load (and direct read path), passing globalScale to MLX.gatherQuantizedMM.
  • MLXInferenceEngine+XRayTensors.swift: slices per-expert global_scale for 3D switch weights and scales by g[e] / 2688.
  • WeightConverter.swift, WeightConverter+SINQ.swift, UniversalSourceReader.swift: lifts .global_scale refusal, tracks .global_scale as a companion tensor, decodes 3D per-expert NVFP4 canonically (dequant * g[e] / 2688), and detects nvfp4+global.
  • Added Tests/BasaltTests/NVFP4GlobalScaleSwitchTests.swift ([P2] tests: shared tiny-model fixtures (Gemma 4, MoE routers) and a kernel admission rule #228, [P3] moe: R&D out-of-core MoE with 16 KB expert slots, a GPU expert cache and double-buffered SSD streaming #225): parity vs dense reference + chunked decode (1, 3, 7), streamed vs resident (1, 4, 8 slots), Inkling sanitize, and bit-for-bit converter canonical decode.

Verification

  • swift build -Xswiftc -warnings-as-errors — PASS
  • swift test --parallel --filter "NVFP4GlobalScaleSwitchTests" — 3/3 PASS
  • swift scripts/check_no_new_comments.swift — PASS
  • swift scripts/check_size_limits.swift --impact — PASS (largest CCN 14 → 14)
  • swift scripts/check_concurrency_hatches.swift — PASS

@goodmai

goodmai commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

Rebased on main 9403f42 (after #733 and #759) at the owner's request.

Note, not blocking: Inkling2Checkpoint.quantParts now includes global_scale, so on an oQ attn.in_proj a per-tensor global_scale would be row-split like the weight. Expert global_scale (per expert) is only renamed, which is right. nvfp4 attention projections with a global scale were not supported before either.

@goodmai
goodmai force-pushed the feat/677-gap2-nvfp4-global-scale branch from 12a4db4 to 3bdce92 Compare November 24, 2026 10:48
@goodmai
goodmai changed the base branch from feat/677-gap1-config-traps to main November 24, 2026 10:50
…streaming, Inkling sanitize, X-ray, and converter (#677 Gap 2)
@goodmai
goodmai force-pushed the feat/677-gap2-nvfp4-global-scale branch from 3bdce92 to 77de6eb Compare November 24, 2026 10:50
@goodmai
goodmai merged commit 0fbd063 into main Nov 24, 2026
8 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