From cd10048d74072991b32e1eb09fe45aa48c250ce2 Mon Sep 17 00:00:00 2001 From: Quantum-Kayak Date: Sun, 24 Aug 2025 22:02:28 -0700 Subject: [PATCH] docs: add fallback for torch.compile in torch_logs tutorial (#137285) --- recipes_source/torch_logs.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/recipes_source/torch_logs.py b/recipes_source/torch_logs.py index b5c3f0bd8ac..4630ae24917 100644 --- a/recipes_source/torch_logs.py +++ b/recipes_source/torch_logs.py @@ -32,17 +32,22 @@ import torch -# exit cleanly if we are on a device that doesn't support torch.compile -if torch.cuda.get_device_capability() < (7, 0): - print("Skipping because torch.compile is not supported on this device.") -else: - @torch.compile() +# Use torch.compile if supported, fallback to eager mode otherwise +try: + @torch.compile def fn(x, y): z = x + y return z + 2 + + inputs = (torch.ones(2, 2, device="cuda"), torch.zeros(2, 2, device="cuda")) +except (RuntimeError, AssertionError): + print("⚠️ torch.compile is not supported on this system. Falling back to eager mode.") + def fn(x, y): + z = x + y + return z + 2 - inputs = (torch.ones(2, 2, device="cuda"), torch.zeros(2, 2, device="cuda")) + inputs = (torch.ones(2, 2), torch.zeros(2, 2)) # print separator and reset dynamo