Skip to content

[nvfp4 training][rl] Add a CuTe DSL fast-path kernel for four-over-six quantize - #13

Closed
wolfcomos wants to merge 1 commit into
4over6/ao1-densefrom
4over6/ao2-cutedsl
Closed

[nvfp4 training][rl] Add a CuTe DSL fast-path kernel for four-over-six quantize#13
wolfcomos wants to merge 1 commit into
4over6/ao1-densefrom
4over6/ao2-cutedsl

Conversation

@wolfcomos

@wolfcomos wolfcomos commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Stacked on #12. Adds this series' one minimal kernel prototype: the quantizer is the recipe's hot op — it runs on every activation and weight of every forward — so it gets a CuTe DSL fast-path kernel, dispatched automatically for eligible inputs (CUDA bf16/fp32, SM100+, contiguous, C % 64 == 0). Ineligible inputs silently fall through to the pure-PyTorch reference; the CuTe DSL runtime is assumed installed wherever the gate passes (no package probing in the dispatch).

The kernel is bitwise-identical to the reference: the rounding-critical steps (correctly-rounded FP32 division, the FP4/E4M3 casts and their exact decodes) are emitted as raw inline PTX, and the width-16 error-reduction order is pinned (clamped shuffle-down tree), so no compiler lowering choice can change a rounding and the kernel is insulated from cutlass-dsl wrapper churn. One documented divergence: NaN inputs take NaN-dropping block amaxes and encode to +6 codes, while torch.amax propagates NaN into the reference's scales. Compile caching keys on every shape/dtype/knob that changes codegen, and a torch.library custom op with a fake impl keeps torch.compile tracing through the dispatch.

Numerics / perf: all 440 swept shape/knob configurations (block x err_mode x bound x scale granularity x dtype x data construction x shape) bitwise-identical to the pure-torch reference on GB200; 26–30x over the reference body at training shapes (bench file included). Further kernel work (fused dequantize, grouped variants) lands in future PRs.

Stack: #12 ← this PR ← #14.

@wolfcomos
wolfcomos force-pushed the 4over6/ao2-cutedsl branch 3 times, most recently from 5113820 to 7f1e7d4 Compare August 31, 2026 04:37
@wolfcomos wolfcomos changed the title [NVFP4 4over6] Add the CuTe DSL fast path for four-over-six quantize [nvfp4 training][rl] Add a CuTe DSL fast-path kernel for four-over-six quantize Aug 31, 2026
The quantizer is the recipe's one hot op — it runs on every activation
and weight of every forward — so this PR adds a minimal CuTe DSL
kernel prototype for it, dispatched automatically for eligible inputs
(CUDA bf16/fp32, SM100+, contiguous, C % 64 == 0); ineligible inputs
silently fall through to the pure-PyTorch reference body. The CuTe DSL
runtime packages are assumed present wherever the gate passes — the
dispatch does no package probing.

The kernel is bitwise-identical to the reference: the rounding-critical
steps (correctly-rounded FP32 division, the FP4/E4M3 casts and their
exact decodes) are emitted as raw inline PTX so no compiler lowering
choice can change a rounding, and the width-16 error-reduction order is
pinned (clamped shuffle-down tree), insulating the kernel from
cutlass-dsl wrapper churn. Compile caching keys on every
shape/dtype/knob that changes codegen, and compilation runs under the
input's device context. One documented divergence: NaN inputs take
NaN-dropping block amaxes and encode to +6 codes, where torch.amax
propagates NaN.

The kernel is wrapped in a CUDA-only torch.library custom op with a
fake impl so torch.compile traces through the dispatch; direct op
callers get the dispatch gate's and wrapper's checks mirrored as
errors. The bench file measures the kernel against the pure-torch
reference (26-30x at training shapes). Further kernel work (fused
dequantize, grouped variants) lands in future PRs.

Numerics: all 440 swept shape/knob configurations (block x err_mode x
bound x scale granularity x dtype x data construction x shape) bitwise
identical to the pure-torch reference on GB200.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wolfcomos

Copy link
Copy Markdown
Owner Author

Opened upstream as pytorch#4852 (same head). This fork draft stays as the staging copy.

@wolfcomos

Copy link
Copy Markdown
Owner Author

Live upstream as pytorch#4852 — closing the staging draft. The branch stays: it is the upstream PR's head.

@wolfcomos wolfcomos closed this Aug 31, 2026
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