Skip to content

Commit 79b13a1

Browse files
authored
Set global device back to cpu at the end of tutorial
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')`
1 parent 420037e commit 79b13a1

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 gloablly 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)