Skip to content

Commit 112f1b7

Browse files
mlazossvekars
authored andcommitted
Exit cleanly for torch logs tutorial (#2755)
1 parent 5de1015 commit 112f1b7

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

recipes_source/torch_logs.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,49 @@
3434

3535
# exit cleanly if we are on a device that doesn't support torch.compile
3636
if torch.cuda.get_device_capability() < (7, 0):
37-
print("Exiting because torch.compile is not supported on this device.")
38-
import sys
37+
print("Skipping because torch.compile is not supported on this device.")
38+
else:
39+
@torch.compile()
40+
def fn(x, y):
41+
z = x + y
42+
return z + 2
3943

40-
sys.exit(0)
4144

42-
43-
@torch.compile()
44-
def fn(x, y):
45-
z = x + y
46-
return z + 2
47-
48-
49-
inputs = (torch.ones(2, 2, device="cuda"), torch.zeros(2, 2, device="cuda"))
45+
inputs = (torch.ones(2, 2, device="cuda"), torch.zeros(2, 2, device="cuda"))
5046

5147

5248
# print separator and reset dynamo
5349
# between each example
54-
def separator(name):
55-
print(f"==================={name}=========================")
56-
torch._dynamo.reset()
50+
def separator(name):
51+
print(f"==================={name}=========================")
52+
torch._dynamo.reset()
5753

5854

59-
separator("Dynamo Tracing")
55+
separator("Dynamo Tracing")
6056
# View dynamo tracing
6157
# TORCH_LOGS="+dynamo"
62-
torch._logging.set_logs(dynamo=logging.DEBUG)
63-
fn(*inputs)
58+
torch._logging.set_logs(dynamo=logging.DEBUG)
59+
fn(*inputs)
6460

65-
separator("Traced Graph")
61+
separator("Traced Graph")
6662
# View traced graph
6763
# TORCH_LOGS="graph"
68-
torch._logging.set_logs(graph=True)
69-
fn(*inputs)
64+
torch._logging.set_logs(graph=True)
65+
fn(*inputs)
7066

71-
separator("Fusion Decisions")
67+
separator("Fusion Decisions")
7268
# View fusion decisions
7369
# TORCH_LOGS="fusion"
74-
torch._logging.set_logs(fusion=True)
75-
fn(*inputs)
70+
torch._logging.set_logs(fusion=True)
71+
fn(*inputs)
7672

77-
separator("Output Code")
73+
separator("Output Code")
7874
# View output code generated by inductor
7975
# TORCH_LOGS="output_code"
80-
torch._logging.set_logs(output_code=True)
81-
fn(*inputs)
76+
torch._logging.set_logs(output_code=True)
77+
fn(*inputs)
8278

83-
separator("")
79+
separator("")
8480

8581
######################################################################
8682
# Conclusion

0 commit comments

Comments
 (0)