Repository navigation
perf(nvfp4): add opt-in native repack override for non-CUDA builds - #699
Merged
Merged
Conversation
Issue #694 asks whether Metal/non-CUDA should switch from the affine 4-bit fallback to the direct ModelOpt-triplet NVFP4 transcode that #693/#697 made the CUDA default. That decision needs an A/B benchmark on real M-series hardware, which is not available here, so this change only adds the plumbing the benchmark plan requires. The three cfg!(feature = "cuda") decision sites in src/models/sanitize.rs (the log label, the direct-transcode gate, and the dense-path quantize-mode choice) are replaced by a single pure function, nvfp4_repack_strategy(cuda_build, native_forced, dense_forced), so the three sites can never disagree. A new env var, MLXCEL_NVFP4_NATIVE_REPACK (same truthy-value parsing as the existing MLXCEL_NVFP4_DENSE_REPACK), opts a non-CUDA build into the direct transcode. Precedence: MLXCEL_NVFP4_DENSE_REPACK wins over everything, otherwise MLXCEL_NVFP4_NATIVE_REPACK forces native, otherwise the existing default applies (native on CUDA, affine off CUDA). Added nvfp4_repack_strategy_matrix, which exercises the full 2x2x2 build/native-forced/dense-forced matrix against the pure function, and nvfp4_native_repack_forced_matches_case_insensitively, matching the existing MLXCEL_NVFP4_DENSE_REPACK env-parsing test style. docs/environment-variables.md documents MLXCEL_NVFP4_NATIVE_REPACK next to MLXCEL_NVFP4_DENSE_REPACK with the precedence spelled out. docs/benchmark_results/nvfp4-direct-transcode-gb10-2026-07-08.md gets an Apple Silicon A/B runbook section with the exact build and bench-decode commands from issue #694's benchmark plan, what to record, and the decision gate (2048 prefill improves >= 20% and decode regresses <= 5%). Refs #694
6 tasks done
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…ablup#699) ## Summary This PR implements the hardware-independent plumbing that issue lablup#694's benchmark plan needs, so an Apple Silicon host can A/B test the direct NVFP4 transcode against the affine fallback without a code change. It does not run that benchmark and does not flip any default; this machine is GB10 Linux CUDA, not Apple Silicon, so both the M-series bench run and the default-flip decision remain explicitly out of scope here and stay open on lablup#694. ## What changed - `src/models/sanitize.rs`: the three `cfg!(feature = "cuda")` NVFP4 repack decision sites (the log label, the direct-transcode gate, and the dense-path quantize-mode choice) now all read from one pure function, `nvfp4_repack_strategy(cuda_build, native_forced, dense_forced)`, so the three sites can never disagree. - Added `MLXCEL_NVFP4_NATIVE_REPACK` (same case-insensitive 1/true/on/yes parsing as the existing `MLXCEL_NVFP4_DENSE_REPACK`), which opts a non-CUDA build into the direct triplet transcode that CUDA already defaults to. - Precedence, documented on `nvfp4_repack_strategy`: `MLXCEL_NVFP4_DENSE_REPACK` wins over everything (forces the dense debug fallback on any build), otherwise `MLXCEL_NVFP4_NATIVE_REPACK` forces the direct transcode, otherwise the existing default applies (native on CUDA, affine off CUDA). - Added `nvfp4_repack_strategy_matrix`, exercising the full cuda-build x native-forced x dense-forced matrix (8 combinations, including both overrides forced at once, where dense wins the route) against the pure function, and `nvfp4_native_repack_forced_matches_case_insensitively`, matching the existing `MLXCEL_NVFP4_DENSE_REPACK` env-parsing test style. - `docs/environment-variables.md`: documented `MLXCEL_NVFP4_NATIVE_REPACK` next to `MLXCEL_NVFP4_DENSE_REPACK` with the precedence spelled out. - `docs/benchmark_results/nvfp4-direct-transcode-gb10-2026-07-08.md`: added an Apple Silicon A/B runbook section with the exact build and `mlxcel-bench-decode` commands from issue lablup#694's benchmark plan (short-prompt and 2048-token runs, once with the affine default and once with `MLXCEL_NVFP4_NATIVE_REPACK=1`), what to record (cold-load wall time, MLX peak memory, prefill/decode tok/s, a 40+ token greedy parity spot-check), and the decision gate from the issue (enable native on Metal only if 2048 prefill improves at least 20% and decode regresses at most 5%). ## Test plan - [x] `cargo check -p mlxcel --features cuda --lib` - [x] `cargo test -p mlxcel --features cuda --lib nvfp4` (12 passed, including the two new tests) - [x] `cargo clippy -p mlxcel --features cuda --lib --tests -- -D warnings` - [x] `cargo fmt -p mlxcel -- --check` Refs lablup#694
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the hardware-independent plumbing that issue #694's benchmark plan needs, so an Apple Silicon host can A/B test the direct NVFP4 transcode against the affine fallback without a code change. It does not run that benchmark and does not flip any default; this machine is GB10 Linux CUDA, not Apple Silicon, so both the M-series bench run and the default-flip decision remain explicitly out of scope here and stay open on #694.
What changed
src/models/sanitize.rs: the threecfg!(feature = "cuda")NVFP4 repack decision sites (the log label, the direct-transcode gate, and the dense-path quantize-mode choice) now all read from one pure function,nvfp4_repack_strategy(cuda_build, native_forced, dense_forced), so the three sites can never disagree.MLXCEL_NVFP4_NATIVE_REPACK(same case-insensitive 1/true/on/yes parsing as the existingMLXCEL_NVFP4_DENSE_REPACK), which opts a non-CUDA build into the direct triplet transcode that CUDA already defaults to.nvfp4_repack_strategy:MLXCEL_NVFP4_DENSE_REPACKwins over everything (forces the dense debug fallback on any build), otherwiseMLXCEL_NVFP4_NATIVE_REPACKforces the direct transcode, otherwise the existing default applies (native on CUDA, affine off CUDA).nvfp4_repack_strategy_matrix, exercising the full cuda-build x native-forced x dense-forced matrix (8 combinations, including both overrides forced at once, where dense wins the route) against the pure function, andnvfp4_native_repack_forced_matches_case_insensitively, matching the existingMLXCEL_NVFP4_DENSE_REPACKenv-parsing test style.docs/environment-variables.md: documentedMLXCEL_NVFP4_NATIVE_REPACKnext toMLXCEL_NVFP4_DENSE_REPACKwith the precedence spelled out.docs/benchmark_results/nvfp4-direct-transcode-gb10-2026-07-08.md: added an Apple Silicon A/B runbook section with the exact build andmlxcel-bench-decodecommands from issue perf(metal): evaluate native NVFP4 path after direct transcode #694's benchmark plan (short-prompt and 2048-token runs, once with the affine default and once withMLXCEL_NVFP4_NATIVE_REPACK=1), what to record (cold-load wall time, MLX peak memory, prefill/decode tok/s, a 40+ token greedy parity spot-check), and the decision gate from the issue (enable native on Metal only if 2048 prefill improves at least 20% and decode regresses at most 5%).Test plan
cargo check -p mlxcel --features cuda --libcargo test -p mlxcel --features cuda --lib nvfp4(12 passed, including the two new tests)cargo clippy -p mlxcel --features cuda --lib --tests -- -D warningscargo fmt -p mlxcel -- --checkRefs #694