Repository navigation
fix(marlin): make the MXFP8 and MXFP4 microscaling paths work - #5193
Merged
Merged
Conversation
Marlin instantiates and dispatches MXFP8 (float8_e4m3fn weights with float8_e8m0fnu group-32 scales, bf16) and MXFP4, but neither could run: * gptq_marlin.cu gated every float8_e8m0fnu path on __has_include(<ATen/native/quantized/Float8_e8m0fnu.h>). That header does not exist (the type lives in c10/util), so E8M0 scales were always rejected. Include <c10/util/Float8_e8m0fnu.h> and drop the guard; torch >= 2.13 always provides the type. * marlin_template.h applies the paired 8-bit scale layout (two groups per 16-bit slot, int2 reads) only when the weight is FP4. MXFP8 used 16-bit strides and int4 reads over a 1-byte scale tensor, so every group read the wrong scales. Key these sites on is_8bit_scale, as vLLM does (vllm-project/vllm#34664). * fp16 MXFP4 failed with "Invalid thread config" because no fp16 E8M0 kernels exist; reject it with the same "requires bfloat16 compute" error as MXFP8. Add mxfp8_marlin_prepare() (fp8 packing, repack, scale permutation and 8-bit interleave) and a real-kernel FP64-oracle test for MXFP8 and MXFP4. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9 of 11 tasks
Qubitium
marked this pull request as ready for review
November 18, 2026 11:02
This was referenced Nov 18, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
The part-2 slice restart copied the initial s_gl_rd row term from before #5193, so it divided by 2 only for FP4 weights (w_type == kFE2M1f). Since #5193 the 8-bit (paired) scale layout keys on the scale width, so MXFP8 restarts landed on twice the right scale row. On an RTX 4090, MXFP8 at M=1000, K=4096, N=4096 came out with errors as large as the outputs. Use is_8bit_scale like the initial s_gl_rd. Add MXFP8 and MXFP4 cases to the part-1 -> part-2 transition test. They fail with the old divisor and pass with this one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
…ule) (#5222) * fix(marlin): stop re-reading a group's scale slot after it is refilled (#4913) For group_blocks > thread_k_blocks (g128 with thread_k = 64) a quantization group spans two pipeline stages. fetch_to_shared() copies the group's scales and zero points only into the slot of the group's first stage. The second stage re-read that slot (`2 * (pipe / 2)`) after the last wait_for_stage() barrier that protects it. In the same window, faster warps refill that slot with stage pipe + stages, which belongs to group g + 2. cp.async latency normally hides the race. When the GPU time-slices to another process, in-flight copies drain before the context is saved, so a lagging warp applies group g+2's scales. One k-warp-group then gets a whole 64-row output block wrong, with no error raised. This affects GPTQ and AWQ in fp16 and bf16 on sm_89 and sm_120. Port vLLM's guard from vllm-project/vllm#24722 (vLLM >= 0.12.0): only the group's first stage reads shared memory for scales and integer or float zero points; the later stages keep frag_s / frag_qzp / frag_zpf. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(marlin): take whole output tiles before striping K (hybrid schedule) Port the hybrid work schedule from vLLM's Marlin kernel (vllm-project/vllm#24722, scheduling part only). With more output tiles than threadblocks, each block first takes part1_mn_iters rounds of whole tiles (all of K, slice_count 1, no lock or global reduction). The remaining part2_mn_tiles are then striped along K as before. The striped remainder is kept at least a third of the grid. The first part-2 slice of a block usually starts mid-K. The slice re-init now rebuilds a_gl_rd, b_gl_rd/B_ptr, s_gl_rd and zp_gl_rd from (slice_row, slice_col) instead of assuming slice_row == 0. #24722's contiguous-K warp layout and single-copy scale fetch are not ported. Measured on an RTX 5090, they regressed M=16 by up to 9%, and they reshape the scale-read lines that #5193 changes. Adds test_marlin_hybrid_schedule.py, which drives the part-1 -> part-2 transition with g128 scales, AWQ zero points, bias and FP32/FP16 reductions against an FP64 oracle, plus docs/marlin-hybrid-schedule.md. Depends on #5188 (#4913 scale-slot race fix), which this branch carries. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(marlin): rebuild the 8-bit scale row on hybrid part-2 restarts The part-2 slice restart copied the initial s_gl_rd row term from before #5193, so it divided by 2 only for FP4 weights (w_type == kFE2M1f). Since #5193 the 8-bit (paired) scale layout keys on the scale width, so MXFP8 restarts landed on twice the right scale row. On an RTX 4090, MXFP8 at M=1000, K=4096, N=4096 came out with errors as large as the outputs. Use is_8bit_scale like the initial s_gl_rd. Add MXFP8 and MXFP4 cases to the part-1 -> part-2 transition test. They fail with the old divisor and pass with this one. Co-Authored-By: Claude Opus 5.5 <[email protected]> * perf(marlin): make the hybrid schedule a prefill-only kernel (>= 512 rows) The hybrid schedule is now a compile-time kernel variant (`hybrid` template argument), instantiated only for 64-row tiles. The host launches it only for calls with at least MARLIN_HYBRID_MIN_ROWS (512) rows; every smaller call runs the hybrid=false kernel, which compiles to the original schedule. A clean A/B on a 124-SM A100 measured the ungated hybrid kernel ~1 us slower per call at M=1 and up to 14% slower at M=64, and 1.06x median (up to 1.20x) faster at M >= 1024. The small-M cost shows even where no part-1 round runs, so it is kernel code, not schedule; hence a compile-time gate. Adds a source-contract test for the gate and FP64-oracle tests at 511 rows (original kernel) and 512 rows (hybrid kernel). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Nov 19, 2026
Keep the stable-ABI surfaces while taking main's changes: - marlin: adopt the MXFP4/MXFP8 microscaling fix (#5193): the e8m0 type is always available through torch_stable_compat.h, fp16 MXFP4 is rejected with the bfloat16-compute error, and the bf16 path keeps the e8m0 scale pointer. - marlin: take the thread_k/thread_n/num_threads tile override (#5281) in the core schema and the torch-version adapter schema, so the boxed forward keeps matching arity. - paro: keep main's 64-bit row indexing (#5253) and port its Meta kernels (#5225) to STABLE_TORCH_LIBRARY_IMPL, allocating with at::options(). - compat: do not take the AOTI empty fast path for Meta tensors, which have no accelerator index. - exllamav3: register main's bf16 prescale/rescale wrappers with TORCH_BOX.
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
Marlin instantiates and dispatches MXFP8 (
float8_e4m3fnweights, onefloat8_e8m0fnuscale per 32 inputs, bf16 compute), and MXFP4, but neither path could produce a correct result:gptq_marlin.cugatedfloat8_e8m0fnuon__has_include(<ATen/native/quantized/Float8_e8m0fnu.h>). That header doesn't exist; the type lives inc10/util.HAS_FLOAT8_E8M0FNUwas therefore always0, and bf16 calls failed withexpected scalar type BFloat16 but found Float8_e8m0fnu. This blocked MXFP8 and MXFP4 alike.marlin_template.hreads 8-bit scales in a paired layout: two adjacent groups share one 16-bit slot, read asint2. It applied that layout only when the weight was FP4 (w_type == kFE2M1f). MXFP8 (FP8 weights, E8M0 scales) used the 16-bit scale strides andint4reads over a 1-byte tensor, so every group read the wrong scales and outputs were off by about 100%.Invalid thread config ... thread_k = -1, while fp16 MXFP8 gave a clear message.This completes the port of vllm-project/vllm#34664 (MXFP8 on Marlin), adapted to GPT-QModel's paired 8-bit scale layout from before vllm-project/vllm#24722.
What Changed
gptqmodel_ext/marlin/gptq_marlin.cu:<c10/util/Float8_e8m0fnu.h>and remove the brokenHAS_FLOAT8_E8M0FNUguard. The minimum supported torch is 2.13, which always has the type, andfloatx_cpu.cppalready includes it unconditionally.float4_e2m1f with float8_e8m0fnu scales requires bfloat16 compute (MXFP4).gptqmodel_ext/marlin/marlin_template.h: addis_8bit_scale = s_type.size_bits() == 8and key the five scale-layout sites on it instead ofw_type == kFE2M1f:s_tb_groups,s_gl_rd,s_sh_rd,cur_group_id, and theint4/int2scale read.gptqmodel/utils/marlin.py: new helpers.pack_fp8_to_int32().marlin_interleave_8bit_scales(), the paired-layout scale interleave shared by MXFP4 and MXFP8 (vLLM'smxfp4_marlin_process_scales).mxfp8_marlin_prepare(weight, scales), which turns an OCP MXFP8(N, K)weight and(N, K/32)E8M0 scales into Marlin operands. Scale bytes are permuted raw, with no float round trip.tests/kernels/test_marlin_mxfp8.py(new):tests/kernels/test_marlin_tile_determinism_4735.py: the shared-memory layout model evaluates template expressions, so it now definesis_8bit_scale = Falsefor the 16-bit-scale kernels it models.mxfp8_marlin_prepare()+gptq_marlin_gemm().Tests
Red (
tests/kernels/test_marlin_mxfp8.py, MXFP8 cases, RTX 4090):a706c646e: all oracle cases fail withRuntimeError: expected scalar type BFloat16 but found Float8_e8m0fnu.M=1 K=2048 N=2048: 1982 outputs off; max err 2.004e+05 vs |oracle| max 2.329e+05.Green (this branch):
budgetsource tests intest_marlin_tile_determinism_4735.pyinitially failed withNameError: is_8bit_scale. They are fixed in this PR and now pass.tests/test_marlin_jit.py::test_marlin_cuda_smoke_build_and_forwardfails only when run in the same process after another test has loaded the Marlin extension ("already loaded in this Python process"). It fails identically on the basea706c646e.tests/test_marlin_jit.pyalone: 65 passed.test_awq_marlin_determinism_4683.py::test_repeated_launches_are_bitwise_identical[512-2048-8192-bf16]failed once on the RTX 4090 while another tenant held the card at 97%. That is [BUG] #4859 (fix of #4683) incomplete: AwqMarlinLinear bf16 still returns grossly wrong 48x64 output blocks when another process loads the GPU (single stream; also before #4657); fp16/GPTQ Marlin/cuBLAS clean #4913 (fixed by fix(marlin): stop re-reading a group's scale slot after it is refilled (#4913) #5188, not in this branch's base). This PR doesn't touch that code, and the two branches merge cleanly.ruff check gptqmodel docs/eora tests setup.py(0.14.2): all checks passed.Measured accuracy: MXFP8 and MXFP4 max relative error is 2–4e-3 of each row's max output, which is bf16 output rounding (2^-8). The test bound is 2^-7.
Model Support / Module Plan
Not applicable: no model or definition changes.
AWQ onboarding safety
Not applicable.
Logic Flow Documentation
Not applicable: it fixes data layout and type gating inside an existing kernel path.
Review Requirements
Kernel Accuracy Requirements
Notes
fetch_scales_to_registers, andgit merge-treeis clean.🤖 Generated with Claude Code