PR #115554
tensorflow/tensorflow · Core Math · Merged · 2 files changed
Prevented +inf accumulators in tf.math.cumulative_logsumexp from triggering NaN cascades by guarding stabilized max-subtraction in the C++ scan kernel.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 115554 --repo tensorflow/tensorflowPrevented +inf accumulators in tf.math.cumulative_logsumexp from triggering NaN cascades by guarding stabilized max-subtraction in the C++ scan kernel.
File-by-File Modification Breakdown (2)
- +11 / -3
tensorflow/core/kernels/scan_ops.h
Core C++ Eigen kernel implementation and boundary guards
- +12 / -0
tensorflow/python/kernel_tests/math_ops/cumulative_logsumexp_test.py
Python/XLA regression test suite verifying edge-case behavior
Changed Files (2)
1. Introduction & Motivation
tf.math.cumulative_logsumexp computes running log-space sums in sequential models, particle filters, and CTC decoding. To avoid exponential overflow, the kernel uses the classic max-subtraction trick [1]. However, when any prefix element equals , the running maximum becomes , causing subsequent terms to evaluate and poison all remaining outputs.
2. Numerical Stability Proof
Standard stabilized LogSumExp evaluates:
If , then , so every subsequent scan step evaluates:
Guarding explicitly in the scan accumulator preserves without generating NaN.
| Prefix Input | Before Fix | After Fix |
|---|---|---|
| Finite values | Stable | Stable |
| Contains | NaN cascade | Exact |
3. Implementation & Verification
4. References
- Blanchard, Higham & Higham, Accurately Computing the Log-Sum-Exp and Softmax Functions, IMA Journal of Numerical Analysis, 2021.