Skip to content

Commit 0b79041

Browse files
[FX] Fix scaled_mm_v2 test shape for PyTorch compatibility (#4643)
## Description PyTorch requires `scale_a/b` to be 2D tensors for `scaled_mm_v2` (see [validate_scaled_mm_v2_inputs](https://github.com/pytorch/pytorch/blob/d4165ba8f7d119c23f08273aa6979734f843845c/aten/src/ATen/native/ScaledBlasUtils.cpp#L449)). In older PyTorch versions, this check was enforced in Python meta-registrations (prior to [this commit](pytorch/pytorch@1a00857) moving the validation to C++). However, `test_import_scaled_mm_v2_rowwise_fp4` was using 1D tensors, causing tracing and metadata checks to fail on PyTorch 2.3+. This PR fixes the test case by updating the scale tensors to `(128, 1)`.
1 parent 1828c50 commit 0b79041

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

test/python/fx_importer/scaled_mm_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def forward(self, a, b, a_scale, b_scale):
301301

302302
@run
303303
# CHECK-LABEL: test_import_scaled_mm_v2_rowwise_fp4
304-
# CHECK: func.func @test_import_scaled_mm_v2_rowwise_fp4(%arg0: !torch.vtensor<[128,64],f4E2M1FN>, %arg1: !torch.vtensor<[64,128],f4E2M1FN>, %arg2: !torch.vtensor<[128],f32>, %arg3: !torch.vtensor<[128],f32>) -> !torch.vtensor<[128,128],bf16>
304+
# CHECK: func.func @test_import_scaled_mm_v2_rowwise_fp4(%arg0: !torch.vtensor<[128,64],f4E2M1FN>, %arg1: !torch.vtensor<[64,128],f4E2M1FN>, %arg2: !torch.vtensor<[128,1],f32>, %arg3: !torch.vtensor<[128,1],f32>) -> !torch.vtensor<[128,128],bf16>
305305
# CHECK-NOT: torch.operator
306306
# CHECK: %[[SCALE_A:.*]] = torch.prim.ListConstruct %arg2
307307
# CHECK: %[[RECIPE_A_VALUE:.*]] = torch.constant.int 1
@@ -337,8 +337,8 @@ def forward(self, a, b, a_scale, b_scale):
337337

338338
a = make_fp4_tensor((128, 64))
339339
b = make_fp4_tensor((64, 128), stride=(1, 64))
340-
a_scale = torch.zeros((128,), dtype=torch.float32)
341-
b_scale = torch.zeros((128,), dtype=torch.float32)
340+
a_scale = torch.zeros((128, 1), dtype=torch.float32)
341+
b_scale = torch.zeros((128, 1), dtype=torch.float32)
342342

343343
m = fx.export_and_import(
344344
Basic(),

0 commit comments

Comments
 (0)