pytorch/docs/source/notes
Julian De la Barrera Brandner 2dc1627451 [doc] Add documentation for division by zero behavior in autograd (#155987)
Fixes #128796

This PR adds documentation about the behavior of division by zero operations in PyTorch's autograd system. The documentation explains:

1. How division by zero produces `inf` values following IEEE-754 floating point arithmetic
2. How autograd handles these cases and why masking after division can lead to `nan` gradients
3. Provides concrete examples showing the issue
4. Recommends two solutions:
   - Masking before division
   - Using MaskedTensor (experimental API)

The documentation is added to the autograd notes section, making it easily discoverable for users who encounter this common issue.

This addresses the original issue #128796 which requested better documentation of this behavior to help users avoid common pitfalls when dealing with division by zero in their models.

dditional changes:
- Fixed formatting consistency by replacing curly apostrophes with straight apostrophes in the existing documentation

Pull Request resolved: https://github.com/pytorch/pytorch/pull/155987
Approved by: https://github.com/soulitzer

Co-authored-by: sekyondaMeta <127536312+sekyondaMeta@users.noreply.github.com>
2025-06-16 19:02:12 +00:00
..
amp_examples.rst Update document for autocast on CPU (#135299) 2024-09-13 09:11:47 +00:00
autograd.rst [doc] Add documentation for division by zero behavior in autograd (#155987) 2025-06-16 19:02:12 +00:00
broadcasting.rst
cpu_threading_runtimes.svg
cpu_threading_torchscript_inference.rst
cpu_threading_torchscript_inference.svg
cuda.rst Document the default garbage_collection_threshold value and improve the organization of cuda docs (#155341) 2025-06-08 22:09:35 +00:00
custom_operators.rst Redirect the custom ops landing page :D (#139634) 2024-11-04 22:25:15 +00:00
ddp.rst
extending.func.rst
extending.rst [autograd][docs] Add more details on why save_for_backward is important in extending autograd note (#153005) 2025-05-09 16:36:57 +00:00
faq.rst
fsdp.rst Fix some incorrect reST markups in the document (#154831) 2025-06-07 19:09:46 +00:00
get_start_xpu.rst update get start xpu (#151886) 2025-06-13 07:46:13 +00:00
gradcheck.rst
hip.rst Fix broken URLs (#152237) 2025-04-27 09:56:42 +00:00
large_scale_deployments.rst
libtorch_stable_abi.md Improve stable library apis per Scott's feedback (#152040) 2025-04-24 20:51:03 +00:00
modules.rst Fix to modules.rst: indent line with activation functions (#139667) 2024-11-08 01:12:52 +00:00
mps.rst
multiprocessing.rst Document poison fork note for accelerator APIs (#147507) 2025-04-10 02:37:37 +00:00
numerical_accuracy.rst Add option to configure reduced precision math backend for SDPA (#135964) 2024-09-24 07:11:38 +00:00
out.rst add Out Notes (#151306) 2025-04-24 20:25:09 +00:00
randomness.rst Fix typo in Reproducibility docs (#141341) 2024-11-26 16:53:26 +00:00
serialization.rst Update serialization docs (#153631) 2025-05-19 20:22:07 +00:00
windows.rst Removing conda references from PyTorch Docs (#152702) 2025-05-20 20:33:28 +00:00