+
    &jd                     J    R t ^ RIt^ RItRR.t ! R R4      t ! R R4      tR# )zAutograd anomaly mode.Ndetect_anomalyset_detect_anomalyc                   ^   a  ] tR t^t o RtR
V 3R lR lltV 3R lR ltV 3R lR ltRtV t	R	# )r   a   Context-manager that enable anomaly detection for the autograd engine.

This does two things:

- Running the forward pass with detection enabled will allow the backward
  pass to print the traceback of the forward operation that created the failing
  backward function.
- If ``check_nan`` is ``True``, any backward computation that generate "nan"
  value will raise an error. Default ``True``.

.. warning::
    This mode should be enabled only for debugging as the different tests
    will slow down your program execution.

Example:
    >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_ANOMALY)
    >>> import torch
    >>> from torch import autograd
    >>> class MyFunc(autograd.Function):
    ...     @staticmethod
    ...     def forward(ctx, inp):
    ...         return inp.clone()
    ...
    ...     @staticmethod
    ...     def backward(ctx, gO):
    ...         # Error during the backward pass
    ...         raise RuntimeError("Some error in backward")
    ...         return gO.clone()
    >>> def run_fn(a):
    ...     out = MyFunc.apply(a)
    ...     return out.sum()
    >>> inp = torch.rand(10, 10, requires_grad=True)
    >>> out = run_fn(inp)
    >>> out.backward()
        Traceback (most recent call last):
          File "<stdin>", line 1, 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
    >>> 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

c                   < V ^8  d   QhRR/#    returnN )format__classdict__s   "s/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/autograd/anomaly_mode.py__annotate__detect_anomaly.__annotate__O   s     	
 	
$ 	
    c                    \         P                  ! 4       V n        Wn        \         P                  ! 4       V n        \        P                  ! R ^R7       R# )zqAnomaly Detection has been enabled. This mode will increase the runtime and should only be enabled for debugging.)
stacklevelN)torchis_anomaly_enabledprev	check_nanis_anomaly_check_nan_enabledprev_check_nanwarningswarn)selfr   s   &&r   __init__detect_anomaly.__init__O   s>    ,,.	"#@@B8 		
r   c                   < V ^8  d   QhRR/# r   r	   )r
   r   s   "r   r   r   Z   s     8 84 8r   c                H    \         P                  ! R V P                  4       R# )TN)r   set_anomaly_enabledr   r   s   &r   	__enter__detect_anomaly.__enter__Z   s    !!$7r   c                $   < V ^8  d   QhRS[ RR/# r   argsr   Nobject)r
   r   s   "r   r   r   ]        B Bf B Br   c                \    \         P                  ! V P                  V P                  4       R # Nr   r   r   r   r   r%   s   &*r   __exit__detect_anomaly.__exit__]       !!$))T-@-@Ar   )r   r   r   NT
__name__
__module____qualname____firstlineno____doc__r   r!   r-   __static_attributes____classdictcell__r   s   @r   r   r      s,     @D	
 	
8 8B Br   c                   ^   a  ] tR t^at o RtR
V 3R lR lltV 3R lR ltV 3R lR ltRtV t	R	# )r   a,  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 :attr:`mode`.
It can be used as a context-manager or as a function.

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

Args:
    mode (bool): Flag whether to enable anomaly detection (``True``),
                 or disable (``False``).
    check_nan (bool): Flag whether to raise an error when the backward
                      generate "nan"

c                *   < V ^8  d   QhRS[ RS[ RR/# )r   moder   r   N)bool)r
   r   s   "r   r   set_detect_anomaly.__annotate__r   s"     3 3T 3d 3d 3r   c                    \         P                  ! 4       V n        \         P                  ! 4       V n        \         P
                  ! W4       R # r*   )r   r   r   r   r   r   )r   r<   r   s   &&&r   r   set_detect_anomaly.__init__r   s1    ,,.	#@@B!!$2r   c                   < V ^8  d   QhRR/# r   r	   )r
   r   s   "r   r   r>   w   s      4 r   c                    R # r*   r	   r    s   &r   r!   set_detect_anomaly.__enter__w   s    r   c                $   < V ^8  d   QhRS[ RR/# r$   r&   )r
   r   s   "r   r   r>   z   r(   r   c                \    \         P                  ! V P                  V P                  4       R # r*   r+   r,   s   &*r   r-   set_detect_anomaly.__exit__z   r/   r   )r   r   Nr0   r1   r9   s   @r   r   r   a   s*      3 3
 B Br   )r6   r   r   __all__r   r   r	   r   r   <module>rH      s6       1
2RB RBjB Br   