Skip to content

fix(autodiff): accumulate repeated multiplication inputs#89

Merged
AlekseiChirkovVention merged 1 commit into
mainfrom
feat/repeated-input-mul-vjp-fix
Jul 22, 2026
Merged

fix(autodiff): accumulate repeated multiplication inputs#89
AlekseiChirkovVention merged 1 commit into
mainfrom
feat/repeated-input-mul-vjp-fix

Conversation

@AlekseiChirkovVention

Copy link
Copy Markdown
Collaborator

Summary

  • Fix multiplication VJP generation when both operands reference the same input.
  • Preserve both partial derivatives and combine them with a symbolic addition.
  • Keep the existing VJP result contract and broadcast-reduction behavior unchanged.
  • Add structural and numerical regression coverage for mul(x, x).

How it works

Each multiplication operand produces its own partial gradient and completes any required broadcast reduction independently. When both operands share one value ID, the two resulting gradient IDs are combined with an AddOperator, whose output becomes the sole exported gradient for that input.

How to test

  1. Run:
    python -m pytest py/tests/test_autodiff_elementwise.py py/tests/test_autodiff_matmul.py py/tests/test_autodiff_reductions.py -q
  2. Confirm all 55 focused tests pass.
  3. Verify the repeated-input regression generates two multiplication nodes followed by one addition node.
  4. Verify numerical execution returns 2 * seed * value.

Preserve both VJP contributions when a multiplication uses the same
value as both operands, then combine them symbolically in the generated
derivative program.
@AlekseiChirkovVention AlekseiChirkovVention self-assigned this Jul 21, 2026
@AlekseiChirkovVention
AlekseiChirkovVention marked this pull request as ready for review July 21, 2026 13:43
@AlekseiChirkovVention
AlekseiChirkovVention merged commit bdfe149 into main Jul 22, 2026
@AlekseiChirkovVention
AlekseiChirkovVention deleted the feat/repeated-input-mul-vjp-fix branch July 22, 2026 06:41
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.

3 participants