Skip to content

Keep derivatives and imaginary parts at ties in logsumexp - #129

Merged
devmotion merged 3 commits into
masterfrom
dmw/logsumexp-tie-derivative
Sep 25, 2026
Merged

devmotion merged 3 commits into
masterfrom
dmw/logsumexp-tie-derivative

Conversation

@devmotion

Copy link
Copy Markdown
Member

At exact ties, _logsumexp_onepass_op replaced the difference of the arguments by zero(...) to avoid Inf - Inf = NaN. This dropped derivatives in Enzyme and Mooncake and discarded differing imaginary parts of complex inputs (e.g. logsumexp(z for z in (0.0, im)) returned 0.69 + 1.0im instead of 0.56 + 0.5im). The difference is now replaced only if it is NaN.

Enzyme and Mooncake tests live in a separate environment test/ad with its own CI job on Julia 1, since Mooncake pins supported Julia versions (1.10.0, our min-patch, is not supported).

Fixes #128.

🤖 Generated with Claude Code

devmotion and others added 3 commits September 25, 2026 10:38
At exact ties, the reduction operators replaced the difference of the
arguments by a constant zero to avoid `Inf - Inf = NaN`. This dropped
derivatives in Enzyme and Mooncake and discarded differing imaginary
parts of complex inputs. Now the difference is replaced only if it is
`NaN`.

Adds Enzyme and Mooncake tests in a separate environment `test/ad`
with its own CI job.

Fixes #128.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Evaluate at a less trivial tie point, check primal values for Enzyme
and Mooncake, and test Mooncake in forward mode as well. The tie
parameters are passed as an explicit argument since Mooncake's forward
mode does not support closures that capture differentiable data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use single-argument functions with literal constants instead of a
parametrised tie function. They capture no data, so Mooncake's forward
mode works with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devmotion
devmotion marked this pull request as ready for review September 25, 2026 11:23
@devmotion
devmotion requested a review from tpapp September 25, 2026 11:23

@tpapp tpapp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for keeping the integration tests separate, much cleaner.

@devmotion
devmotion merged commit dae60ec into master Sep 25, 2026
6 checks passed
@devmotion
devmotion deleted the dmw/logsumexp-tie-derivative branch September 25, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logsumexp gives the wrong derivative at exact ties under Enzyme and Mooncake

2 participants