ml-explore / ml-explore/mlx

[BUG] jvp of mx.logcumsumexp is not implemented

Open
#3,710 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
28.5k
Forks
2.3k
Avg merge
3d 8h
Merged PRs (30d)
62

Description

Describe the bug

Forward-mode autodiff (mx.jvp) through mx.logcumsumexp raises instead of returning the tangent:

RuntimeError: JVP is not implemented for cumulative prod/min/max

Scan::jvp only implements the Sum reduction; logcumsumexp (the LogAddExp scan) falls through to the generic "not implemented" branch even though its vjp is implemented. This breaks mx.jvp and forward-over-reverse compositions that go through logcumsumexp.

To Reproduce
import mlx.core as mx

x = mx.array([1.0, 2.0, 3.0])
t = mx.ones_like(x)
mx.jvp(lambda z: mx.logcumsumexp(z), [x], [t])
# RuntimeError: JVP is not implemented for cumulative prod/min/max
Expected behavior

mx.jvp of logcumsumexp returns the running softmax-weighted sum of the tangents,

d/dt logcumsumexp(x)_k = sum_{i<=k} softmax(x)_i * t_i,

consistent with the existing vjp (the adjoint identity <w, Jv> == <v, Jᵀw> should hold).

Desktop
  • OS: macOS
  • Version: main (0.32.0.dev)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Scan::jvp and trace the LogAddExp scan path used by mx.logcumsumexp, comparing it with the existing vjp implementation. Reproduce the Python mx.jvp example, then verify that the tangent is returned and that the stated adjoint identity holds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.