File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,9 @@ Locally disabling gradient computation
142142The context managers :func: `torch.no_grad `, :func: `torch.enable_grad `, and
143143:func: `torch.set_grad_enabled ` are helpful for locally disabling and enabling
144144gradient computation. See :ref: `locally-disable-grad ` for more details on
145- their usage.
145+ their usage. These context managers are thread local, so they won't
146+ work if you send work to another thread using the :module: `threading `
147+ module, etc.
146148
147149Examples::
148150
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ class no_grad(object):
1010 consumption for computations that would otherwise have `requires_grad=True`.
1111 In this mode, the result of every computation will have
1212 `requires_grad=False`, even when the inputs have `requires_grad=True`.
13+ This context manager is thread local; it will not affect computation
14+ in other threads.
1315
1416 Also functions as a decorator.
1517
@@ -49,6 +51,8 @@ class enable_grad(object):
4951
5052 Enables gradient calculation inside a :class:`~no_grad` context. This has
5153 no effect outside of :class:`~no_grad`.
54+ This context manager is thread local; it will not affect computation
55+ in other threads.
5256
5357 Also functions as a decorator.
5458
@@ -93,6 +97,8 @@ class set_grad_enabled(object):
9397
9498 ``set_grad_enabled`` will enable or disable grads based on its argument :attr:`mode`.
9599 It can be used as a context-manager or as a function.
100+ This context manager is thread local; it will not affect computation
101+ in other threads.
96102
97103 Arguments:
98104 mode (bool): Flag whether to enable grad (``True``), or disable
You can’t perform that action at this time.
0 commit comments