Skip to content

Commit

Permalink
make is_tf32_env() safer (#6839)
Browse files Browse the repository at this point in the history
Following #6816 
### Description

make `is_tf32_env()` safer.
check `cuda`  to prevent fallthrough case when `pynvml` is not found

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

Signed-off-by: Qingpeng Li <qingpeng9802@gmail.com>
  • Loading branch information
qingpeng9802 authored Aug 8, 2023
1 parent ca96867 commit 8e99af5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8e99af5

Please sign in to comment.