Back Home

GitHub Repo

PyTorch Community Reports Logit Boundary Issue: Tiny Epsilon May Still Produce Infinities in FP32

A PyTorch report filed on November 14 says that `torch.logit` in FP32 can still return infinite values when `eps=1e-8` and the input is 1. It compares stable and Nightly releases, but maintainers have not confirmed the issue or provided an official fix.

Pytorch Deepdream (https://github.com/gordicaleksa/pytorch-deepdream) by gordicaleksa (https://github.com/gordicaleksa/pytorch-deepdream/commits?author=gordicaleksa) · MIT · Image source
zh-Hant

On November 14, a member of the PyTorch community filed issue #204898, reporting that the boundary protection in torch.logit(x, eps=1e-8) may be affected by FP32 rounding. In the attached example, an input of 1 produces positive infinity in both the forward output and the backward gradient. The same code in FP64 returns an output of about 18.42 and a gradient of zero. The reporter says the same behavior occurs in version 2.15.0 and the tested 2.16 Nightly build. Issue report

logit computes the log odds of a probability, or ln(p / (1-p)). The official documentation says that when eps is set, the input is clamped to [eps, 1-eps] so the calculation avoids the endpoints. This matters especially for probability transformations: when a probability is close to zero or one, the denominator and logarithm can amplify tiny numerical differences. API documentation

The report points to the upper-bound calculation as the cause: in FP32, 1-1e-8 rounds to 1, so an input of 1 is not moved away from the singularity. The lower-bound clamp still works in the same example. This shows that a positive eps does not guarantee that the stored upper bound is less than one. PyTorch’s numerical-accuracy notes say that single precision provides about seven decimal digits of precision; in practice, engineers must also account for the operation and data type involved. Report analysis, numerical-accuracy notes

For teams using inverse probability transforms or custom loss functions, this means that checking whether eps is set in a configuration file is not enough to confirm that outputs and gradients will be finite. Based on this example, engineers can add boundary tests for zero, one, and nearby values using the actual data type, and compare forward and backward results across precisions. This is a validation recommendation inferred from the report, not an official mitigation.

As of this review, the issue remains open. The page shows only automated triage, with no maintainer confirmation, linked fix, or release timeline. Follow-up should track how the project defines clamping behavior and whether it adds regression tests across data types and devices; the report should not yet be treated as a confirmed defect affecting all versions. Issue status

Sources

  1. torch.logit 在 FP32 微小 eps 下回傳 inf 的問題回報 #204898
  2. torch.special.logit API 文件
  3. PyTorch 數值精度說明