Skip to content

Fix complex vjps for the inverse trig and hyperbolic ops#3779

Open
obchain wants to merge 1 commit into
ml-explore:mainfrom
obchain:fix/complex-inverse-trig-vjp
Open

Fix complex vjps for the inverse trig and hyperbolic ops#3779
obchain wants to merge 1 commit into
ml-explore:mainfrom
obchain:fix/complex-inverse-trig-vjp

Conversation

@obchain

@obchain obchain commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes #3778.

ArcCos, ArcCosh, ArcSin, ArcSinh, ArcTan, and ArcTanh delegated their vjp to their jvp. For a holomorphic f the jvp is f'(z) * t but the vjp must be cotangent * conj(f'(z)); delegating dropped the conjugate, so gradients through these ops were wrong for complex inputs. This is the same fix as #3766, applied to the inverse trig / hyperbolic ops.

Each vjp now conjugates the cotangent, runs the jvp, and conjugates the result (conj(jvp(conj(w))) = w * conj(f'(z))), a no-op for real inputs.

Verified each op's complex gradient against finite differences and the hand-computed cotangent * conj(f'(z)) (away from the branch cuts); real gradients and jvps are unchanged. Added test_complex_inverse_trig_vjps.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

ArcCos, ArcCosh, ArcSin, ArcSinh, ArcTan, and ArcTanh delegated their vjp
to their jvp, dropping the conjugate for complex inputs. As with the
other unary ops, conjugate the cotangent into the jvp and conjugate the
result so the vjp is cotangent * conj(f'(z)); this is a no-op for real
inputs.
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.

[BUG] Complex vjps are wrong for arcsin/arccos/arctan/arcsinh/arccosh/arctanh (missing conjugate)

1 participant