From f6a2d05ac3a7711eb52e213771d7b1fd30bdde17 Mon Sep 17 00:00:00 2001 From: Qingpeng Li Date: Tue, 8 Aug 2023 17:39:21 +0800 Subject: [PATCH] make `is_tf32_env()` safer Signed-off-by: Qingpeng Li --- tests/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.py b/tests/utils.py index 1dfd5e6e209..dc6e8fac44e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -180,7 +180,7 @@ def is_tf32_env(): global _tf32_enabled if _tf32_enabled is None: _tf32_enabled = False - if detect_default_tf32() or torch.backends.cuda.matmul.allow_tf32: + if torch.cuda.is_available() and (detect_default_tf32() or torch.backends.cuda.matmul.allow_tf32): try: # with TF32 enabled, the speed is ~8x faster, but the precision has ~2 digits less in the result g_gpu = torch.Generator(device="cuda")