Skip to content

Commit 741d46b

Browse files
committed
Abort if device is not supported
1 parent d90487f commit 741d46b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

recipes_source/compiling_optimizer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444
# In this example, we'll use the Adam optimizer
4545
# and create a helper function to wrap the step()
4646
# in torch.compile()
47+
#
48+
# .. note::
49+
#
50+
# torch.compile is only supported on cuda devices with compute capability >= 7.0
51+
52+
# exit cleanly if we are on a device that doesn't support torch.compile
53+
if torch.cuda.get_device_capability() < (7, 0):
54+
print("Exiting because torch.compile is not supported on this device.")
55+
import sys
56+
sys.exit(0)
57+
4758

4859
opt = torch.optim.Adam(model.parameters(), lr=0.01)
4960

0 commit comments

Comments
 (0)