Skip to content

Fix cvt_packfloat compatibility with nvidia-cutlass-dsl 4.6.0+ - #4766

Merged
andrewor14 merged 1 commit into
mainfrom
cutlass-cvt-packfloat
Sep 4, 2026
Merged

andrewor14 merged 1 commit into
mainfrom
cutlass-cvt-packfloat

Conversation

@andrewor14

@andrewor14 andrewor14 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

nvidia-cutlass-dsl 4.6.0 removed a leading argument in a few nvvm ops. The current callsite in torchao (introduced in #4725) still includes this leading argument, resulting in the following error:

TypeError: cvt_packfloat_f32() takes 4 positional arguments but 5 were given

Correct signature:

\# 4.5.x
nvvm.cvt_packfloat_f32(T.i32(), src_a, src_b, src_c, to, rnd=..., sat=...)
\# 4.5.x[cu13], 4.6.0+
nvvm.cvt_packfloat_f32(src_a, src_b, src_c, to, rnd=..., sat=...)

Note that we cannot simply gate this on the verison because different variants within the same version can have different signatures. Here is the complete table:

nvidia-cutlass-dsl          4.4.x, 4.5.x    accepts `res` == T.i32()
nvidia-cutlass-dsl[cu13]    4.4.x, 4.5.x    no `res`
nvidia-cutlass-dsl          4.6.0+          no `res`
nvidia-cutlass-dsl[cu13]    4.6.0+          no `res`

Full list of affected ops used by cute_utils.py:

fmax
cvt_packfloat
cvt_packfloat32

Test Plan

Full version sweep across the following versions. vllm nightly currently requires 4.6.2.

nvidia-cutlass-dsl          4.5.3, 4.6.0, 4.6.2, 4.7.1
nvidia-cutlass-dsl[cu13]    4.5.3, 4.6.0, 4.6.2, 4.7.1

Repro 1:

import torch
from torchao.prototype.moe_training.kernels.mxfp8 import (
    mxfp8_quantize_2d_1x32_cutedsl,
)

x = torch.randn(128, 2048, device="cuda", dtype=torch.bfloat16)
offs = torch.tensor([128], device="cuda", dtype=torch.int32)
mxfp8_quantize_2d_1x32_cutedsl(x, scaling_mode="rceil", offs=offs)

Repro 2:

import torch
from torchao.prototype.moe_training.kernels.mxfp8 import (
    mxfp8_quantize_cuda_3d,
)

x = torch.randn(2, 256, 256, device="cuda", dtype=torch.bfloat16)
mxfp8_quantize_cuda_3d(
    x, scale_block_dim1=32, scale_block_dim2=32, scaling_mode="rceil",
)

@pytorch-bot

pytorch-bot Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4766

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 550f24f with merge base ca74881 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 17, 2026
@andrewor14 andrewor14 added topic: bug fix Use this tag for PRs that fix bugs module: training quantize_ api training flow and removed topic: bug fix Use this tag for PRs that fix bugs labels Aug 17, 2026
@andrewor14
andrewor14 force-pushed the cutlass-cvt-packfloat branch from 8ec516a to c7041df Compare August 17, 2026 19:40
@andrewor14

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Claude finished @andrewor14's task in 3m 0s —— View job


Code Review: Fix cvt_packfloat compatibility with nvidia-cutlass-dsl 4.6.0+

  • Read the diff and surrounding code
  • Analyze version-guard logic and correctness
  • Post review feedback

The overall approach is sound: gate the removed leading result-type argument (T.i32()) behind a _CUTLASS_DSL_BEFORE_4_6_0 version check computed once at import. Nice touch caching the check at module level rather than per-call. But I found one issue that I think undermines the stated goal of the PR, plus a couple of smaller points.


🔴 The RoundingModeKind → FPRoundingMode rename is not version-guarded

This is the main concern. The diff changes every nvvm.RoundingModeKind.* to nvvm.FPRoundingMode.* unconditionally:

  • cute_utils.py:233, :244 — rnd=nvvm.FPRoundingMode.RN
  • cute_utils.py:286 — rounding_mode=nvvm.FPRoundingMode.RP
  • cute_utils.py:300 — rounding_mode=nvvm.FPRoundingMode.RZ

The pre-existing code (from #4725) used nvvm.RoundingModeKind, which means that symbol existed and worked on the 4.5.x line the code was written against. If 4.6.0 renamed RoundingModeKind to FPRoundingMode (which is the most likely reason for this change), then the _CUTLASS_DSL_BEFORE_4_6_0 == True branch — the branch that only exists to keep 4.5.x working — will now hit AttributeError: module 'nvvm' has no attribute 'FPRoundingMode' on 4.5.x.

In other words: the positional-arg fix is version-gated, but the enum rename is not, so the 4.5.x path the guard is meant to preserve may no longer import/run on 4.5.x at all. The PR description says it was "Verified on 4.6.0" but doesn't mention verifying 4.5.x.

Two questions/asks:

  1. Does nvvm.FPRoundingMode exist on 4.5.x? If yes (both names present as aliases), this is fine — please confirm/mention it. If no, the enum reference also needs to be selected by _CUTLASS_DSL_BEFORE_4_6_0.
  2. If 4.5.x support is no longer actually intended, then the _CUTLASS_DSL_BEFORE_4_6_0 branch is dead code and the whole conditional could be dropped in favor of the 4.6.0+ signature. Right now the PR is in an in-between state: it claims to support both but only demonstrably works on one.

Fix this →


🟡 Prerelease versions of 4.6.0 will take the wrong branch

parse_version (torchao/utils.py:375) collapses the patch to -1 for any string containing dev/git:

parse_version("4.6.0.dev20260101")  # -> [4, 6, -1]

[4, 6, -1] < [4, 6, 0] is True, so a 4.6.0 dev/nightly build would be classified as before 4.6.0 and take the old 5-arg signature — the exact failure this PR fixes. Probably an edge case you don't hit in practice, but worth being aware of since nightlies of cutlass-dsl are common. If you want to be safe, compare on [major, minor] only (< [4, 6]) since the breaking change is a minor-version boundary.


🟢 Minor: branch duplication

The two if/else blocks in _cvt_f32_to_ue8m0 (:188-210) and _cvt_ue8m0_to_f32 (:226-248) are identical except for the leading T.i32(). Optional cleanup to reduce the ~40 duplicated lines:

res_prefix = (T.i32(),) if _CUTLASS_DSL_BEFORE_4_6_0 else ()
packed = nvvm.cvt_packfloat_f32(
    *res_prefix, src_a, src_b, src_c, to,
    rnd=rounding_mode, sat=nvvm.SaturationModeKind.NONE, loc=loc, ip=ip,
)

Purely stylistic — the explicit branches are also perfectly readable.


Notes

  • I couldn't execute the code locally (nvidia-cutlass-dsl isn't installed in this CI runner and the H100/L4 GPU jobs are still pending), so the FPRoundingMode-on-4.5.x question above is based on reading the diff — please double-check it.
  • Ruff and the label check are green; GPU test jobs (1xH100, 1xL4) are still queued/in-progress and are the ones that actually exercise this kernel.

Nice, focused fix overall — resolving the enum-guarding question is the one thing I'd want settled before merge.
· branch cutlass-cvt-packfloat

@janbernloehr

Copy link
Copy Markdown

Thanks for addressing the cvt_packfloat_f32 / cvt_packfloat signature change.

One additional compatibility point may be worth including before merge: cute_utils.py also calls nvvm.fmax with a leading result type (T.f32()), and the 4.6.x API changed that result-type convention as well. The same compatibility handling should cover the fmax_nan_f32 call.

Also, since nvvm.FPRoundingMode is now used on the pre-4.6 branch, could we confirm that symbol exists across all supported 4.5.x versions? If not, enum selection should be version- or feature-gated separately from the positional-argument handling.

It would be useful to test both a 4.5.x and 4.6.x CuTeDSL environment before merging, since the goal is to preserve older-version support while adding 4.6+ compatibility.

@andrewor14
andrewor14 force-pushed the cutlass-cvt-packfloat branch 2 times, most recently from f08577a to 55edcb6 Compare August 21, 2026 13:33
@andrewor14

Copy link
Copy Markdown
Contributor Author

@claude review again? I just rebased. The naming change was actually made before this PR

@andrewor14

andrewor14 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @janbernloehr, thanks for the suggestion. I fixed it for fmax too. Will test on 4.5.0 now. I did actually confirm that FPRoundingMode was in 4.5.x as well as all future versions including 4.6.x and 4.7.x here: #4765.

@claude

claude Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Claude finished @andrewor14's task in 1m 14s —— View job


Re-review: Fix cvt_packfloat compatibility with nvidia-cutlass-dsl 4.6.0+

  • Re-read the diff after rebase (git diff origin/main...HEAD)
  • Re-check the FPRoundingMode / enum-rename concern from the last round
  • Re-check the fmax result-type concern raised by @janbernloehr
  • Post updated feedback

You're right — and the rebase resolves the two blocking items from the last round. 👍


✅ Resolved: RoundingModeKind → FPRoundingMode rename

Confirmed on origin/main: the code already uses nvvm.FPRoundingMode (cute_utils.py:204, 246, 260 on main), so the rename landed before this PR (in the already-merged #4765) and is not something this PR introduces or needs to version-guard. My earlier worry that the pre-4.6 branch would AttributeError on 4.5.x was based on the assumption that this PR made the rename — it didn't. Thanks for the correction.

✅ Resolved: nvvm.fmax leading result type (@janbernloehr's point)

fmax_nan_f32 (cute_utils.py:158-183) now gates the leading T.f32() on _CUTLASS_DSL_BEFORE_4_6_0, matching the same convention change as cvt_packfloat*. This is exactly the compatibility handling that was requested.


🟡 Still open (minor): prerelease/nightly builds of 4.6.0 take the wrong branch

parse_version (torchao/utils.py:382-388) collapses the patch to -1 for any string containing dev/git:

parse_version("4.6.0.dev20260101")  # -> [4, 6, -1]
[4, 6, -1] < [4, 6, 0]  # True  -> classified as "before 4.6.0"

So a 4.6.0 dev/nightly build would take the old 5-arg signature and hit the very TypeError this PR fixes. Since the breaking change is a minor-version boundary, comparing on [major, minor] is safe:

_CUTLASS_DSL_BEFORE_4_6_0 = parse_version(
    importlib.metadata.version("nvidia-cutlass-dsl")
)[:2] < [4, 6]

Non-blocking, but cutlass-dsl nightlies are common enough that it's worth the one-line change. Fix this →

🟢 Still open (stylistic): branch duplication

The three if/else pairs in fmax_nan_f32, _cvt_f32_to_ue8m0, and _cvt_ue8m0_to_f32 differ only by the leading result-type arg. Could collapse each with a prefix tuple, e.g.:

res_prefix = (T.i32(),) if _CUTLASS_DSL_BEFORE_4_6_0 else ()
packed = nvvm.cvt_packfloat_f32(
    *res_prefix, src_a, src_b, src_c, to,
    rnd=rounding_mode, sat=nvvm.SaturationModeKind.NONE, loc=loc, ip=ip,
)

Purely optional — the explicit branches read fine.


Verdict

The two correctness blockers from the previous review are now resolved (enum rename was pre-existing; fmax is version-guarded). Only the nightly-version edge case and the optional dedup remain, neither blocking. LGTM once you decide on the [major, minor] comparison.

As before, I can't execute the kernel here (no nvidia-cutlass-dsl / GPU in this runner) — the 1xH100 / 1xL4 jobs are the ones that actually exercise it. Testing in both a 4.5.x and a 4.6.x env before merge (as @janbernloehr suggested) is still the best confirmation.
· branch cutlass-cvt-packfloat

@andrewor14
andrewor14 force-pushed the cutlass-cvt-packfloat branch 4 times, most recently from 759a77b to 082ac20 Compare September 3, 2026 21:34
@andrewor14

Copy link
Copy Markdown
Contributor Author

@claude review latest changes again

@claude

claude Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Claude finished @andrewor14's task in 48s —— View job


Re-review: Fix cvt_packfloat compatibility with nvidia-cutlass-dsl 4.6.0+

  • Re-read the diff after latest changes (git diff origin/main...HEAD)
  • Evaluate the new signature-introspection approach vs. the previous version gate
  • Re-check my two prior open items (nightly misclassification, dedup)
  • Post updated feedback

The detection strategy changed entirely since the last round, and it's a clear improvement. 👍


✅ Signature introspection replaces the version gate — this is the right call

Instead of _CUTLASS_DSL_BEFORE_4_6_0 version math, the code now inspects the actual op signature once at import (cute_utils.py:67-72):

def _accepts_res_arg(op) -> bool:
    return "res" in inspect.signature(op).parameters

_FMAX_ACCEPTS_RES_ARG = _accepts_res_arg(nvvm.fmax)
_CVT_PACKFLOAT_F32_ACCEPTS_RES_ARG = _accepts_res_arg(nvvm.cvt_packfloat_f32)
_CVT_PACKFLOAT_ACCEPTS_RES_ARG = _accepts_res_arg(nvvm.cvt_packfloat)

This directly resolves both issues that couldn't be solved by version comparison:

  1. The cu13-vs-default split within the same version — the whole motivation for the PR. 4.5.x accepts res but 4.5.x[cu13] does not, so no version string could disambiguate them. Introspecting the real signature does, and it's checked per-op (fmax, cvt_packfloat_f32, cvt_packfloat are detected independently), which is the correct granularity since the description notes the ops changed convention at different points.
  2. The nightly/dev misclassification I flagged last round (parse_version("4.6.0.dev...") → [4,6,-1] < [4,6,0]) is now moot — there's no version parsing left to misclassify. Nice.

Caching the three booleans at module scope rather than calling inspect.signature per kernel invocation is the right tradeoff.


🟢 Minor (non-blocking): still some branch duplication

fmax_nan_f32, _cvt_f32_to_ue8m0, and _cvt_ue8m0_to_f32 each carry a full if/else that differs only by the leading result-type arg. Now that the operands are hoisted into locals (src_a/src_b/src_c/to), each pair could collapse with a prefix tuple:

res_prefix = (T.i32(),) if _CVT_PACKFLOAT_F32_ACCEPTS_RES_ARG else ()
packed = nvvm.cvt_packfloat_f32(
    *res_prefix, src_a, src_b, src_c, to,
    rnd=rounding_mode, sat=nvvm.SaturationModeKind.NONE, loc=loc, ip=ip,
)

Purely stylistic — the explicit branches read fine and the duplication is bounded. Fix this →


🟢 One thing worth a sanity check

inspect.signature(nvvm.fmax) assumes these MLIR-dialect op bindings expose an introspectable Python signature. If any build wraps them in a C-extension callable that raises ValueError/TypeError on inspect.signature, the module import would fail. Given the ops are the generated pybind dialect functions and the PR was swept across 4.5.3/4.6.0/4.6.2/4.7.1 (both default and cu13 per the description), this is presumably fine on all supported versions — just flagging that the guarantee here is "introspectable on every tested build" rather than "introspectable in general." No change needed if the sweep passed.


Verdict

This is a better fix than the version-gated version I reviewed last time — it solves the same-version/different-extra ambiguity that motivated the PR and eliminates the nightly-misclassification edge case entirely. Both prior blockers are gone. Only the optional dedup remains. LGTM, assuming the full version sweep in the PR description passed (which is the real confirmation, since there's no nvidia-cutlass-dsl/GPU in this runner for me to exercise the kernels).
· branch cutlass-cvt-packfloat

# nvidia-cutlass-dsl 4.4.x, 4.5.x accepts `res`
# nvidia-cutlass-dsl[cu13] 4.4.x, 4.5.x no `res`
# nvidia-cutlass-dsl 4.6.0+ no `res`
# nvidia-cutlass-dsl[cu13] 4.6.0+ no `res`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a TODO here to go back to a version gate once 4.5.x ages out of pytorch support

**Summary:** `nvidia-cutlass-dsl` 4.6.0 removed a leading argument in a
few nvvm ops. The current callsite in torchao (introduced in #4725) still
includes this leading argument, resulting in the following error:

```
TypeError: cvt_packfloat_f32() takes 4 positional arguments but 5 were given
```

Correct signature:

```
\# 4.5.x
nvvm.cvt_packfloat_f32(T.i32(), src_a, src_b, src_c, to, rnd=..., sat=...)
\# 4.5.x[cu13], 4.6.0+
nvvm.cvt_packfloat_f32(src_a, src_b, src_c, to, rnd=..., sat=...)
```

Note that we cannot simply gate this on the verison because different
variants within the same version can have different signatures. Here is
the complete table:

```
nvidia-cutlass-dsl          4.4.x, 4.5.x    accepts `res` == T.i32()
nvidia-cutlass-dsl[cu13]    4.4.x, 4.5.x    no `res`
nvidia-cutlass-dsl          4.6.0+          no `res`
nvidia-cutlass-dsl[cu13]    4.6.0+          no `res`
```

Full list of affected ops used by `cute_utils.py`:

```
fmax
cvt_packfloat
cvt_packfloat32
```

**Test Plan:** Full version sweep across the following versions.
vllm nightly currently requires 4.6.2.

```
nvidia-cutlass-dsl          4.5.3, 4.6.0, 4.6.2, 4.7.1
nvidia-cutlass-dsl[cu13]    4.5.3, 4.6.0, 4.6.2, 4.7.1
```

Repro 1:
```
import torch
from torchao.prototype.moe_training.kernels.mxfp8 import (
    mxfp8_quantize_2d_1x32_cutedsl,
)

x = torch.randn(128, 2048, device="cuda", dtype=torch.bfloat16)
offs = torch.tensor([128], device="cuda", dtype=torch.int32)
mxfp8_quantize_2d_1x32_cutedsl(x, scaling_mode="rceil", offs=offs)
```

Repro 2:
```
import torch
from torchao.prototype.moe_training.kernels.mxfp8 import (
    mxfp8_quantize_cuda_3d,
)

x = torch.randn(2, 256, 256, device="cuda", dtype=torch.bfloat16)
mxfp8_quantize_cuda_3d(
    x, scale_block_dim1=32, scale_block_dim2=32, scaling_mode="rceil",
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: training quantize_ api training flow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants