Skip to content

Commit fa9be97

Browse files
malfetSvetlana Karslioglu
and
Svetlana Karslioglu
authored
Set global device back to cpu at the end of tutorial (#2411)
We are using sphinx to render those tutorials, which does not start a new process to render, so one needs to restore global state to default value, by calling `torch.set_default_device('cpu')` Co-authored-by: Svetlana Karslioglu <svekars@fb.com>
1 parent 4648254 commit fa9be97

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

recipes_source/recipes/changing_default_device.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
print(mod.weight.device)
4444
print(mod(torch.randn(128, 20)).device)
4545

46+
# And then globally return it back to CPU
47+
torch.set_default_device('cpu')
48+
4649
################################################################
4750
# This function imposes a slight performance cost on every Python
4851
# call to the torch API (not just factory functions). If this

0 commit comments

Comments
 (0)