Repository navigation
Commit d2e7701
log_add: shift-guard NaN gradient at structural-zero (-inf) - (-inf)
When both operands are structural zeros (sign=0, log_mag=-inf),
``small_log - big_log`` evaluates to ``(-inf) - (-inf) = NaN``.
The downstream ``where`` cascade masks the forward value (returns
LOG_ZERO correctly), but reverse-mode autodiff still differentiates
through the NaN expression and propagates a NaN gradient.
Apply the same ``big_log_safe = where(isneginf(big_log), 0, big_log)``
shift used in log_sum so the dangerous branches stay finite. The
both-zero case is already masked to LOG_ZERO regardless, so the
shift is irrelevant to the forward value but unblocks the gradient.
Add test_log_add_both_zero_grad_finite as a regression lock.
Latent fragility — production jet rules go through log_sum (already
safe) — so no acopula experiment results were affected.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c28564a commit d2e7701
2 files changed
Lines changed: 42 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
116 | 125 | | |
117 | 126 | | |
118 | 127 | | |
119 | | - | |
120 | | - | |
| 128 | + | |
| 129 | + | |
121 | 130 | | |
122 | 131 | | |
123 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
143 | 171 | | |
144 | 172 | | |
145 | 173 | | |
| |||
0 commit comments