Skip to content

Commit 712b9d1

Browse files
rdspring1claude
andcommitted
Take the linear weight amax as an inf-norm
The same reduction as the grouped weight amax, on the dense path: the fp32 upcast materialized the whole weight to read a single scalar from it. One inf-norm over the bf16 weight gives a bitwise identical amax. Per weight at DeepSeek-V3 671B MLP shapes (7168x18432), the fp32 copy, abs and fp32 reduce cost 548.7 us together; the bf16 inf-norm costs 86.2 us. Over a 3-linear MLP block at 8192 tokens that is 18.6% of the CuteDSL block's device time (8111 -> 6603 us) and 16.4% of Triton's (9313 -> 7783 us), and the saving does not shrink with batch size. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 1eb1b4f commit 712b9d1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

torchao/prototype/moe_training/nvfp4_training/nvfp4_linear.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ def _weight_quantize_2d(x: torch.Tensor, use_cutedsl: bool):
116116
use_cutedsl selects the CuteDSL kernel (plain transpose-quantize via an identity Hadamard)
117117
over the Triton 2D weight kernel. Neither path applies RHT or SR.
118118
"""
119-
global_amax = x.float().abs().max()
119+
# An inf-norm is the amax in one reduction. Upcasting first would instead
120+
# materialize the whole weight in fp32, for the same result: bf16 -> fp32 is
121+
# exact, so it reduces over the same values.
122+
global_amax = torch.linalg.vector_norm(x, ord=float("inf")).float()
120123
quantize = cutedsl_weight_quantize_2d if use_cutedsl else triton_weight_quantize_2d
121124
codes, sf, t_codes, t_sf = quantize(x, global_amax)
122125
return (

0 commit comments

Comments
 (0)