Skip to content

Commit 99038e7

Browse files
committed
Fix NVFP4 benchmark scaling and explicit CuTe exports
1 parent 093461d commit 99038e7

2 files changed

Lines changed: 57 additions & 66 deletions

File tree

benchmarks/tma_m1_scaled_mm_heatmap.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,23 @@ def scaled_mm_mxfp8(
208208

209209

210210
def scaled_mm_nvfp4(
211-
mat_a: torch.Tensor, mat_b: torch.Tensor, scale_a: torch.Tensor, scale_b: torch.Tensor
211+
mat_a: torch.Tensor,
212+
mat_b: torch.Tensor,
213+
scale_a: torch.Tensor,
214+
scale_b: torch.Tensor,
215+
global_scale_a: torch.Tensor,
216+
global_scale_b: torch.Tensor,
212217
):
213-
"""Run the cuBLASLt NVFP4 block-scaled GEMV baseline."""
218+
"""Run the cuBLASLt NVFP4 block- and tensor-scaled GEMV baseline."""
214219
return scaled_mm(
215220
mat_a,
216221
mat_b,
217-
scale_a=[scale_a],
218-
scale_recipe_a=[ScalingType.BlockWise1x16],
219-
swizzle_a=[SwizzleType.SWIZZLE_32_4_4],
220-
scale_b=[scale_b],
221-
scale_recipe_b=[ScalingType.BlockWise1x16],
222-
swizzle_b=[SwizzleType.SWIZZLE_32_4_4],
222+
scale_a=[scale_a, global_scale_a],
223+
scale_recipe_a=[ScalingType.BlockWise1x16, ScalingType.TensorWise],
224+
swizzle_a=[SwizzleType.SWIZZLE_32_4_4, SwizzleType.NO_SWIZZLE],
225+
scale_b=[scale_b, global_scale_b],
226+
scale_recipe_b=[ScalingType.BlockWise1x16, ScalingType.TensorWise],
227+
swizzle_b=[SwizzleType.SWIZZLE_32_4_4, SwizzleType.NO_SWIZZLE],
223228
output_dtype=torch.bfloat16,
224229
)
225230

@@ -286,6 +291,8 @@ def run_mxfp8(n: int, k: int, rounds: int, iterations: int, seed: int) -> Benchm
286291
def run_nvfp4(n: int, k: int, rounds: int, iterations: int, seed: int) -> BenchmarkResult:
287292
"""Benchmark the NVFP4 TMA specialization against the matching scaled_mm contract."""
288293
mat_a, mat_b, scale_a, scale_b = make_nvfp4_case(n, k, seed)
294+
global_scale_a = torch.tensor([1.5], dtype=torch.float32, device="cuda")
295+
global_scale_b = torch.tensor([0.75], dtype=torch.float32, device="cuda")
289296
config = select_nvfp4_config(n, k, mat_a.device)
290297
output = torch.empty((1, n), dtype=torch.bfloat16, device="cuda")
291298
partial_output = (
@@ -304,10 +311,19 @@ def run_nvfp4(n: int, k: int, rounds: int, iterations: int, seed: int) -> Benchm
304311
grid_scheduler=config.grid_scheduler,
305312
split_k=config.split_k,
306313
stage_weight_scales=config.stage_weight_scales,
314+
global_scale_a=global_scale_a,
315+
global_scale_b=global_scale_b,
307316
output=output,
308317
partial_output=partial_output,
309318
)
310-
baseline = lambda: scaled_mm_nvfp4(mat_a, mat_b, scale_a, scale_b)
319+
baseline = lambda: scaled_mm_nvfp4(
320+
mat_a,
321+
mat_b,
322+
scale_a,
323+
scale_b,
324+
global_scale_a,
325+
global_scale_b,
326+
)
311327
torch.testing.assert_close(tma(), baseline(), atol=2.0, rtol=0.05)
312328
torch.cuda.synchronize()
313329
tma_us, scaled_mm_us = median_interleaved_latency(tma, baseline, rounds, iterations)

transformer_nuggets/cute/__init__.py

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,35 @@
1111
from transformer_nuggets.cute.element_wise import ElementwiseOp, elementwise_op
1212
from transformer_nuggets.cute.utils import visualize_tv_layout
1313
from transformer_nuggets.cute import profiler
14-
15-
16-
_BLOCKSCALED_TMA_EXPORTS = {
17-
"DEFAULT_PERSISTENT_CTAS_PER_SM",
18-
"BlockScaleLayout",
19-
"GridScheduler",
20-
"ProfileTag",
21-
}
22-
23-
_MXFP8_TMA_EXPORTS = {
24-
"MXFP8_TMA_PROFILE_TAGS",
25-
"Mxfp8TmaGemv",
26-
"get_mxfp8_tma_gemv",
27-
"mxfp8_tma_gemv",
28-
"mxfp8_tma_scaled_mm",
29-
"select_mxfp8_tma_compute_warps",
30-
}
31-
32-
_NVFP4_TMA_EXPORTS = {
33-
"NVFP4_TMA_PROFILE_TAGS",
34-
"Nvfp4TmaGemv",
35-
"get_nvfp4_tma_gemv",
36-
"nvfp4_tma_gemv",
37-
"nvfp4_tma_scaled_mm",
38-
"select_nvfp4_tma_compute_warps",
39-
"select_nvfp4_tma_config",
40-
"select_nvfp4_tma_split_k",
41-
"select_nvfp4_tma_stage_weight_scales",
42-
}
43-
44-
_SYMMETRIC_MEMORY_EXPORTS = {
45-
"compile_symmetric_memory_all_reduce",
46-
"init_torchrun_process_group",
47-
"run_symmetric_memory_all_reduce_example",
48-
"symmetric_memory_all_reduce",
49-
"symmetric_memory_peer_tensors",
50-
}
51-
52-
53-
def __getattr__(name):
54-
if name in _BLOCKSCALED_TMA_EXPORTS:
55-
from transformer_nuggets.cute import blockscaled_tma
56-
57-
return getattr(blockscaled_tma, name)
58-
if name in _MXFP8_TMA_EXPORTS:
59-
from transformer_nuggets.cute import mxfp8_tma
60-
61-
return getattr(mxfp8_tma, name)
62-
if name in _NVFP4_TMA_EXPORTS:
63-
from transformer_nuggets.cute import nvfp4_tma
64-
65-
return getattr(nvfp4_tma, name)
66-
if name in _SYMMETRIC_MEMORY_EXPORTS:
67-
from transformer_nuggets.cute import symmetric_memory
68-
69-
return getattr(symmetric_memory, name)
70-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
14+
from transformer_nuggets.cute.blockscaled_tma import (
15+
DEFAULT_PERSISTENT_CTAS_PER_SM,
16+
BlockScaleLayout,
17+
GridScheduler,
18+
ProfileTag,
19+
)
20+
from transformer_nuggets.cute.mxfp8_tma import (
21+
MXFP8_TMA_PROFILE_TAGS,
22+
Mxfp8TmaGemv,
23+
get_mxfp8_tma_gemv,
24+
mxfp8_tma_gemv,
25+
mxfp8_tma_scaled_mm,
26+
select_mxfp8_tma_compute_warps,
27+
)
28+
from transformer_nuggets.cute.nvfp4_tma import (
29+
NVFP4_TMA_PROFILE_TAGS,
30+
Nvfp4TmaGemv,
31+
get_nvfp4_tma_gemv,
32+
nvfp4_tma_gemv,
33+
nvfp4_tma_scaled_mm,
34+
select_nvfp4_tma_compute_warps,
35+
select_nvfp4_tma_config,
36+
select_nvfp4_tma_split_k,
37+
select_nvfp4_tma_stage_weight_scales,
38+
)
39+
from transformer_nuggets.cute.symmetric_memory import (
40+
compile_symmetric_memory_all_reduce,
41+
init_torchrun_process_group,
42+
run_symmetric_memory_all_reduce_example,
43+
symmetric_memory_all_reduce,
44+
symmetric_memory_peer_tensors,
45+
)

0 commit comments

Comments
 (0)