class_docstr: Context-manager that sets gradient calculation on or off.
  
  ``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.
  
  Args:
      mode (bool): Flag whether to enable grad (``True``), or disable
                   (``False``). This can be used to conditionally enable
                   gradients.
  
  .. note::
      set_grad_enabled 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)
      >>> is_train = False
      >>> with torch.set_grad_enabled(is_train):
      ...     y = x * 2
      >>> y.requires_grad
      False
      >>> _ = torch.set_grad_enabled(True)
      >>> y = x * 2
      >>> y.requires_grad
      True
      >>> _ = torch.set_grad_enabled(False)
      >>> y = x * 2
      >>> y.requires_grad
      False
class_docstr_tok: ["Context-manager","that","sets","gradient","calculation","on","or","off",".","``","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",".","Args",":","mode","(","bool",")",":","Flag","whether","to","enable","grad","(","``","True","``",")",",","or","disable","(","``","False","``",")",".","This","can","be","used","to","conditionally","enable","gradients",".","..","note",":",":","set_grad_enabled","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",")",">",">",">","is_train","=","False",">",">",">","with","torch.set_grad_enabled","(","is_train",")",":","...","y","=","x","*","2",">",">",">","y.requires_grad","False",">",">",">","_","=","torch.set_grad_enabled","(","True",")",">",">",">","y","=","x","*","2",">",">",">","y.requires_grad","True",">",">",">","_","=","torch.set_grad_enabled","(","False",")",">",">",">","y","=","x","*","2",">",">",">","y.requires_grad","False"]
code: def clone(self) -> "set_grad_enabled":
      return self.__class__(self.mode)
  
imports: from typing import Any, Optional
  import torch
  from torch.utils._contextlib import _DecoratorContextManager, _NoParamDecoratorContextManager, F
label_desc: Use image node_id 5 for calling the set_grad_enabled obj's underlying member method code with example usage: obj.clone() and returns: self