Skip to content

Commit e1c7e8c

Browse files
FIX Reset the FP32 matmul precision in tests (#2411)
Fixes currently failing hotswap+compile tests that fail because outputs are not close enough before vs after compilation. In test_gpu_examples.py, some tests run torchao, which sets the float32 matmul precision to "high". This in turn results in some models producing different outputs when compiled (but only for some seeds). Therefore, we need to ensure that the precision is reset to "highest", which is the default.
1 parent 24150d0 commit e1c7e8c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test_gpu_examples.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,15 @@ class TestHotSwapping:
42474247

42484248
torch_device = infer_device()
42494249

4250+
@pytest.fixture(scope="class", autouse=True)
4251+
def reset_float32_matmul_precision(self):
4252+
# Earlier tests may run torchao, which, at the time this was added, sets the float32 matmul precision to 'high'.
4253+
# This in turn results in some models producing different outputs when compiled (but only for some seeds).
4254+
# Therefore, we need to ensure that the precision is reset to "highest", which is the default.
4255+
# TODO: if torchao removes the side effect, this fixture can be deleted.
4256+
# https://github.com/pytorch/ao/blob/ffb4350640e76c7e7f449dd1e36d33f19fe384c8/torchao/quantization/utils.py#L589
4257+
torch.set_float32_matmul_precision("highest")
4258+
42504259
@pytest.fixture(autouse=True)
42514260
def reset_dynamo_cache(self):
42524261
# It is critical that the dynamo cache is reset for each test. Otherwise, if the test re-uses the same model,

0 commit comments

Comments
 (0)