[BUG] Complex vjps are wrong for arcsin/arccos/arctan/arcsinh/arccosh/arctanh (missing conjugate)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 28.5k
- Forks
- 2.3k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 62
Description
Describe the bug
The inverse trigonometric / hyperbolic ops return the wrong gradient for complex inputs: their vjp delegates to their jvp, so the conjugate is dropped. For a holomorphic f the vjp must be cotangent * conj(f'(z)).
Affected: arccos, arccosh, arcsin, arcsinh, arctan, arctanh.
This is the same issue fixed for square/sin/tanh/… in #3766.
To Reproduce
import mlx.core as mx
z = mx.array(0.3 + 0.2j, mx.complex64)
g = mx.array(1.0 + 1.0j, mx.complex64)
vjp = mx.vjp(mx.arctan, [z], [g])[1][0]
expected = g * mx.conj(1 / (1 + z**2)) # cotangent * conj(f'(z))
print(vjp, expected) # differ
Expected behavior
vjp == cotangent * conj(f'(z)), consistent with mx.exp/mx.log and finite differences.
Desktop
- OS: macOS
- Version: main (0.32.0.dev)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the mx.vjp and affected inverse trigonometric and hyperbolic operations described in the issue, then reproduce the complex arctan case from the example. Check the existing implementation and tests for mx.exp, mx.log, and the fix referenced in #3766. Done means all six listed operations produce the conjugated derivative for complex inputs and agree with finite differences.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100