@@ -208,18 +208,23 @@ def scaled_mm_mxfp8(
208208
209209
210210def 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
286291def 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 )
0 commit comments