[docs] Document undefined behavior of non-0/1 bytes in bool tensors (#199012)
`Tensor.view(torch.bool)` and `torch.empty(..., dtype=torch.bool)` can produce bool tensors whose bytes are neither 0 nor 1. Operations on such tensors are inconsistent: e.g. on CUDA a contiguous clone copies the raw bytes while a strided copy normalizes them to 1, and `torch.compile` may differ from eager. Following the stance taken in numpy/numpy#29650, document that this is undefined behavior in the `Tensor.view(dtype)` and `torch.empty` docstrings, and point users to `Tensor.bool()` / `torch.zeros` instead. Fixes #193760 Assisted-by: Claude Code (Claude Opus 5.5) Pull Request resolved: https://github.com/pytorch/pytorch/pull/199012 Approved by: https://github.com/albanD
S
Saqib Khan committed
2c857e9be5dce274d51c1d4153664c35482bd864
Parent: 5378feb
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com>
on 9/30/2026, 10:20:13 PM