class_docstr: Context-manager that enables gradient calculation.
  
  Enables gradient calculation, if it has been disabled via :class:`~no_grad`
  or :class:`~set_grad_enabled`.
  
  This context manager is thread local; it will not affect computation
  in other threads.
  
  Also functions as a decorator.
  
  .. note::
      enable_grad is one of several mechanisms that can enable or
      disable gradients locally see :ref:`locally-disable-grad-doc` for
      more information on how they compare.
  
  .. note::
      This API does not apply to :ref:`forward-mode AD <forward-mode-ad>`.
  
  Example::
      >>> # xdoctest: +SKIP
      >>> x = torch.tensor([1.], requires_grad=True)
      >>> with torch.no_grad():
      ...     with torch.enable_grad():
      ...         y = x * 2
      >>> y.requires_grad
      True
      >>> y.backward()
      >>> x.grad
      tensor([2.])
      >>> @torch.enable_grad()
      ... def doubler(x):
      ...     return x * 2
      >>> with torch.no_grad():
      ...     z = doubler(x)
      >>> z.requires_grad
      True
      >>> @torch.enable_grad
      ... def tripler(x):
      ...     return x * 3
      >>> with torch.no_grad():
      ...     z = tripler(x)
      >>> z.requires_grad
      True
class_docstr_tok: ["Context-manager","that","enables","gradient","calculation",".","Enables","gradient","calculation",",","if","it","has","been","disabled","via",":","class",":","`","~no_grad","`","or",":","class",":","`","~set_grad_enabled","`",".","This","context","manager","is","thread","local",";","it","will","not","affect","computation","in","other","threads",".","Also","functions","as","a","decorator",".","..","note",":",":","enable_grad","is","one","of","several","mechanisms","that","can","enable","or","disable","gradients","locally","see",":","ref",":","`","locally-disable-grad-doc","`","for","more","information","on","how","they","compare",".","..","note",":",":","This","API","does","not","apply","to",":","ref",":","`","forward-mode","AD","<","forward-mode-ad",">","`",".","Example",":",":",">",">",">","#","xdoctest",":","+SKIP",">",">",">","x","=","torch.tensor","(","[","1",".","]",",","requires_grad=True",")",">",">",">","with","torch.no_grad","(",")",":","...","with","torch.enable_grad","(",")",":","...","y","=","x","*","2",">",">",">","y.requires_grad","True",">",">",">","y.backward","(",")",">",">",">","x.grad","tensor","(","[","2",".","]",")",">",">",">","@","torch.enable_grad","(",")","...","def","doubler","(","x",")",":","...","return","x","*","2",">",">",">","with","torch.no_grad","(",")",":","...","z","=","doubler","(","x",")",">",">",">","z.requires_grad","True",">",">",">","@","torch.enable_grad","...","def","tripler","(","x",")",":","...","return","x","*","3",">",">",">","with","torch.no_grad","(",")",":","...","z","=","tripler","(","x",")",">",">",">","z.requires_grad","True"]
code: def __enter__(self) -> None:
      self.prev = torch.is_grad_enabled()
      torch._C._set_grad_enabled(True)
  
imports: from typing import Any, Optional
  import torch
  from torch.utils._contextlib import _DecoratorContextManager, _NoParamDecoratorContextManager, F
label_desc: Use image node_id 1 for calling the enable_grad obj's underlying member method code with example usage: obj.__enter__() without return types