Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/source/torch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ Locally disabling gradient computation
The context managers :func:`torch.no_grad`, :func:`torch.enable_grad`, and
:func:`torch.set_grad_enabled` are helpful for locally disabling and enabling
gradient computation. See :ref:`locally-disable-grad` for more details on
their usage.
their usage. These context managers are thread local, so they won't
work if you send work to another thread using the :module:`threading`
module, etc.

Examples::

Expand Down
6 changes: 6 additions & 0 deletions torch/autograd/grad_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class no_grad(object):
consumption for computations that would otherwise have `requires_grad=True`.
In this mode, the result of every computation will have
`requires_grad=False`, even when the inputs have `requires_grad=True`.
This context manager is thread local; it will not affect computation
in other threads.

Also functions as a decorator.

Expand Down Expand Up @@ -49,6 +51,8 @@ class enable_grad(object):

Enables gradient calculation inside a :class:`~no_grad` context. This has
no effect outside of :class:`~no_grad`.
This context manager is thread local; it will not affect computation
in other threads.

Also functions as a decorator.

Expand Down Expand Up @@ -93,6 +97,8 @@ class set_grad_enabled(object):

``set_grad_enabled`` will enable or disable grads based on its argument :attr:`mode`.
It can be used as a context-manager or as a function.
This context manager is thread local; it will not affect computation
in other threads.

Arguments:
mode (bool): Flag whether to enable grad (``True``), or disable
Expand Down