in>", line 8, in backward
        RuntimeError: Some error in backward
    >>> with autograd.detect_anomaly():
    ...     inp = torch.rand(10, 10, requires_grad=True)
    ...     out = run_fn(inp)
    ...     out.backward()
        Traceback of forward call that caused the error:
          File "tmp.py", line 53, in <module>
            out = run_fn(inp)
          File "tmp.py", line 44, in run_fn
            out = MyFunc.apply(a)
        Traceback (most recent call last):
          File "<stdin>", line 4, in <module>
          File "/your/pytorch/install/torch/tensor.py", line 93, in backward
            torch.autograd.backward(self, gradient, retain_graph, create_graph)
          File "/your/pytorch/install/torch/autograd/__init__.py", line 90, in backward
            allow_unreachable=True)  # allow_unreachable flag
          File "/your/pytorch/install/torch/autograd/function.py", line 76, in apply
            return self._forward_cls.backward(self, *args)
          File "<stdin>", line 8, in backward
        RuntimeError: Some error in backward
    

_class_ ` torch.autograd. ` ` set_detect_anomaly ` (  _mode: bool_ )  [
[source]  ](_modules/torch/autograd/anomaly_mode.html#set_detect_anomaly) ¶

    

Context-manager that sets the anomaly detection for the autograd engine on or
off.

` set_detect_anomaly  ` will enable or disable the autograd anomaly detection
based on its argument ` mode  ` . It can be used as a context-manager or as a
function.

See ` detect_anomaly  ` above for details of the anomaly detection behaviour.

Parameters

    

**mode** ( [ _bool_ ](https://docs.python.org/3/library/functions.html#bool
"\(in Python v3.8\)") ) – Flag whether to enable anomaly detection ( ` True  `
), or disable ( ` False  ` ).

[ Next ![](_static/images/chevron-right-orange.svg) ](cuda.html "torch.cuda")
[ ![](_static/images/chevron-right-orange.svg) Previous ](tensor_view.html
"Tensor Views")

* * *

© Copyright 2019, Torch Contributors.

Built with [ Sphinx ](http://sphinx-doc.org/) using a [ theme
](https://github.com/rtfd/sphinx_rtd_theme) provided by [ Read the Docs
](https://readthedocs.org) .

  * Automatic differentiation package - torch.autograd 
    * Functional higher level API 
    * Locally disabling gradient computation 
    * Default gradient layouts 
      * Manual gradient layouts 
    * In-place operations on Tensors 
      * In-place correctness checks 
    * Variable (deprecated) 
    * Tensor autograd functions 
    * Function 
    * Context method mixins 
    * Numerical gradient checking 
    * Profiler 
    * Anomaly detection 

![](https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&guid=ON&script=0)

##  Docs

Access comprehensive developer documentation for PyTorch

[ View Docs ](https://pytorch.org/docs/stable/index.html)

##  Tutorials

Get in-depth tutorials for beginners and advanced developers

[ View Tutorials ](https://pytorch.org/tutorials)

##  Resources

Find development resources and get your questions answered

[ View Resources ](https://pytorch.org/resources)

[ ](https://pytorch.org/)

  * [ PyTorch ](https://pytorch.org/)
  * [ Get Started ](https://pytorch.org/get-started)
  * [ Features ](https://pytorch.org/features)
  * [ Ecosystem ](https://pytorch.org/ecosystem)
  * [ Blog ](https://pytorch.org/blog/)
  * [ Contributing ](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md)

  * [ Resources ](https://pytorch.org/resources)
  * [ Tutorials ](https://pytorch.org/tutorials)
  * [ Docs ](https://pytorch.org/docs/stable/index.html)
  * [ Discuss ](https://discuss.pytorch.org)
  * [ Github Issues ](https://github.com/pytorch/pytorch/issues)
  * [ Brand Guidelines ](https://pytorch.org/assets/brand-guidelines/PyTorch-Brand-Guidelines.pdf)

  * Stay Connected 
  * Email Address 

[ ](https://www.facebook.com/pytorch) [ ](https://twitter.com/pytorch) [
](https://www.youtube.com/pytorch)

To analyze traffic and optimize your experience, w