Skip to content

Fix TorchConnector input gradients summing over batch axes - #1099

Open
Adithyaphani wants to merge 1 commit into
stfc:mainfrom
Adithyaphani:fix/torch-connector-input-grad-output-axes
Open

Adithyaphani wants to merge 1 commit into
stfc:mainfrom
Adithyaphani:fix/torch-connector-input-grad-output-axes

Conversation

@Adithyaphani

Copy link
Copy Markdown

Summary

Fixes #1088. TorchConnector was computing wrong input gradients when the input has more than one batch axis (e.g. shape (1, 2, 1)) and raised a shape error for shapes like (2, 3, 1).

Details and comments

The einsum in the backward pass always summed over axis 1, which is only the output axis when there's a single batch axis. It now sums over the output axes only, and grad_output is reshaped to match the leading axes of the network gradient. That also fixes unbatched multi-dimensional outputs. It covers dense and sparse, input and weight gradients.

  • _get_einsum_signature gets an n_output_dims argument (default keeps the old behaviour)
  • Added regression tests for several input shapes. They fail on main and pass with this change.
  • Added a release note (the repo uses reno, so no CHANGELOG entry)

I ran test/connectors, black and pylint locally. Happy to adjust if you'd prefer a different approach. I also saw PR #1089 on the issue, so let me know if this overlaps.

This branch has not been deployed

No deployments
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.

TorchConnector input gradients contract batch axes instead of output axes

1 participant