[Bugfix] Canonicalize FP8 weight layout to (K, N) at the source#44735
Merged
Conversation
MarlinFP8ScaledMMLinearKernel previously tried to detect whether its incoming weight was (N, K) or (K, N) and transpose accordingly. The shape-based heuristic was a no-op when N == K, silently corrupting square layers (vllm-project#44110). PR vllm-project#44113 swapped the heuristic from shape to is_contiguous(), which still encodes a fragile implicit contract in the kernel. Fix it at the source instead, matching what cutlass already requires and what modelopt already does: each LinearMethod canonicalizes the weight to (K, N) before delegating to the kernel. - Fp8LinearMethod (use_marlin, non-block): transpose before delegating. - Fp8OnlineLinearMethod: collapse the marlin/non-marlin branches into one transpose + delegate. - CompressedTensorsW8A16Fp8 (non-block): transpose before delegating. - MarlinFP8ScaledMMLinearKernel: drop the detect-and-transpose conditional from the non-block branch. This addresses the canonicalization TODO referenced in vllm-project#33314 for the FP8 W8A16 / W8A8 paths, and removes the square-N==K regression at its real root cause. Signed-off-by: mgoin <mike.goin12@gmail.com> Signed-off-by: mgoin <mgoin64@gmail.com>
Contributor
|
Hi @mgoin, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, |
robertgshaw2-redhat
approved these changes
Jun 8, 2026
ekagra-ranjan
pushed a commit
to ekagra-ranjan/vllm
that referenced
this pull request
Jun 9, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com> Signed-off-by: Ekagra Ranjan <3116519+ekagra-ranjan@users.noreply.github.com>
waqahmed-amd-fi
pushed a commit
to waqahmed-amd-fi/vllm
that referenced
this pull request
Jun 10, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com> Signed-off-by: Waqar Ahmed <waqar.ahmed@amd.com>
Saddss
pushed a commit
to Saddss/vllm
that referenced
this pull request
Jun 14, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com>
vivek8123
pushed a commit
to odh-on-pz/vllm-upstream
that referenced
this pull request
Jun 18, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com>
divineearthly
pushed a commit
to divineearthly/vllm
that referenced
this pull request
Jun 19, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com> Signed-off-by: divineearthly <divineearthly@gmail.com>
tunglinwood
pushed a commit
to tunglinwood/vllm
that referenced
this pull request
Jun 22, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com>
nkzhenhua
pushed a commit
to nkzhenhua/vllm
that referenced
this pull request
Jun 24, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com>
Coisinixixi
pushed a commit
to Coisinixixi/vllm
that referenced
this pull request
Jul 2, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com> (cherry picked from commit 6afa250)
ohsono
pushed a commit
to ohsono/vllm
that referenced
this pull request
Jul 3, 2026
…-project#44735) Signed-off-by: mgoin <mgoin64@gmail.com>
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
Fixes #44110 at the root cause, as an alternative to #44113.
MarlinFP8ScaledMMLinearKernel.process_weights_after_loadingpreviouslytried to detect whether its incoming weight was
(N, K)or(K, N)andtranspose accordingly. The shape-based heuristic was a no-op when
N == K, silently corrupting square layers. #44113 swaps the heuristicfrom shape to
is_contiguous(), but that just trades one fragileimplicit contract in the kernel for another.
The real issue is that the kernel boundary has no agreed-on layout:
CutlassFP8ScaledMMLinearKernelexpects(K, N)and does not transpose.ModelOptFp8{,PcPt}LinearMethodalready pre-transposes to(K, N).Fp8LinearMethod(non-marlin),Fp8OnlineLinearMethod(non-marlin) pre-transpose to(K, N).Fp8LinearMethod(use_marlin) andCompressedTensorsW8A16Fp8skip the transpose and let Marlin guess.This PR makes every FP8 linear caller canonicalize to
(K, N)beforedelegating, and removes the detection heuristic from Marlin entirely.
This is the canonicalization step that the TODO referenced in #33314
was asking for, scoped to the FP8 paths that share this kernel.
Changes
Fp8LinearMethod(use_marlin, non-block): transpose before delegating.Fp8OnlineLinearMethod: collapse the marlin/non-marlin branches into a single transpose + delegate.CompressedTensorsW8A16Fp8(non-block): transpose before delegating.MarlinFP8ScaledMMLinearKernel: drop the conditional transpose from the non-block branch.Net diff: 3 files, +11 / -29.
Why this is preferable to #44113
is_contiguous()switch in [Bugfix] Fix MarlinFP8 weight transpose silently skipped for square matrices (N==K) #44113 still breaks if any future caller pre-transposes and then calls.contiguous(), or loads a checkpoint that happens to land non-contiguous.Test plan
VLLM_TEST_FORCE_FP8_MARLIN=1, both the checkpoint-layout path (CompressedTensors-style) and the pre-transposed path (ModelOpt-style). Relative error < 0.005 in all cases.pre-commit run --fileson the changed files — all hooks pass (ruff, mypy, etc.).tests/quantization/test_fp8.pyandtests/evals/gsm8k/test_gsm8k_correctness.pyruns in CI.AI assistance (Claude) was used to draft the change; I (mgoin) reviewed and tested every line.
Co-authored-by: Claude noreply@anthropic.com