Skip to content

Commit 02aab2f

Browse files
shoumikhinAnthony Shoumikhin
andauthored
fix(tests): compare baddbmm lowering against TensorRT in fp32, not TF32 (#4586)
Co-authored-by: Anthony Shoumikhin <shoumikhin@gmail.com>
1 parent cb69e24 commit 02aab2f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

tests/py/dynamo/lowering/test_decompositions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2507,16 +2507,26 @@ def forward(self, bias, batch1, batch2):
25072507
inputs,
25082508
min_block_size=1,
25092509
pass_through_build_failures=True,
2510+
# The reference below runs the matmul in full fp32, so TensorRT has to
2511+
# as well. TF32 is on by default and rounds the operands to 10 mantissa
2512+
# bits, which costs far more than DECIMALS_OF_AGREEMENT allows.
2513+
disable_tf32=True,
25102514
)
25112515
with torch.no_grad():
25122516
trt_results = optimized_model(*inputs).detach().cpu()
25132517
torch_results = fx_graph(*inputs).detach().cpu()
25142518

25152519
max_diff = float(torch.max(torch.abs(trt_results - torch_results)))
2520+
# TensorRT-RTX ignores disable_tf32 and always runs the matmul in TF32, so
2521+
# the fp32 reference can differ by one TF32 rounding step. Only the standard
2522+
# runtime can meet DECIMALS_OF_AGREEMENT here.
2523+
decimals_of_agreement = (
2524+
1 if torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx else DECIMALS_OF_AGREEMENT
2525+
)
25162526
self.assertAlmostEqual(
25172527
max_diff,
25182528
0,
2519-
DECIMALS_OF_AGREEMENT,
2529+
decimals_of_agreement,
25202530
f"baddbmm TRT outputs don't match with the original model. (diff={max_diff})",
25212531
)
25222532

0 commit comments

Comments
 (0)