Skip to content

feat(aggregation): Add Composition class and << operator - #776

Closed
powerofaisinstudy-debug wants to merge 2 commits into
SimplexLab:mainfrom
powerofaisinstudy-debug:feat/composition-api
Closed

powerofaisinstudy-debug wants to merge 2 commits into
SimplexLab:mainfrom
powerofaisinstudy-debug:feat/composition-api

Conversation

@powerofaisinstudy-debug

Copy link
Copy Markdown

Summary

Closes #775.

This PR adds support for composability of aggregators and matrix transformations:

  • Implemented Composition in src/torchjd/aggregation/composition.py.
  • Overloaded __lshift__ operator in Aggregator (src/torchjd/aggregation/_aggregator.py).
  • Added unit tests in tests/aggregation/test_composition.py.

@PierreQuinton Here is an initial draft implementation ready for review whenever you have time!

Overload __lshift__ operator to support composability syntax for chaining aggregators and matrix transformations.
@powerofaisinstudy-debug powerofaisinstudy-debug changed the title feat(aggregation): add Composition class and __lshift__ operator feat(aggregation): add Composition class and << operator Sep 14, 2026
@powerofaisinstudy-debug

powerofaisinstudy-debug commented Sep 14, 2026

Copy link
Copy Markdown
Author

@PierreQuinton Here is an initial implementation ready for review whenever you have time!

Could you please add the cc: feat label to this PR so the format-title CI check passes? I don't have permission to edit labels. Also, the Check Links workflow is timing out on an external journal link in the existing repository files (comptes-rendus.academie-sciences.fr).

@powerofaisinstudy-debug
powerofaisinstudy-debug marked this pull request as ready for review September 14, 2026 04:03
@PierreQuinton PierreQuinton added cc: feat Conventional commit type for new features. package: aggregation labels Sep 14, 2026
@github-actions github-actions Bot changed the title feat(aggregation): add Composition class and << operator feat(aggregation): Add Composition class and << operator Sep 14, 2026
@PierreQuinton

Copy link
Copy Markdown
Contributor

Thanks for the PR. Could you adapt the code to match what is done in https://github.com/SimplexLab/TorchJD/blob/main/src/torchjd/autojac/_transform/_base.py ?

Mainly:

@PierreQuinton

Copy link
Copy Markdown
Contributor

@ValerianRey Can this be implemented using a hook? So basically, can a hook change the value of the input matrix, or is it just an observer?

@ValerianRey

Copy link
Copy Markdown
Member

@ValerianRey Can this be implemented using a hook? So basically, can a hook change the value of the input matrix, or is it just an observer?

Yes. Also, this PR doesn't work because the output of the first aggregator in the composition will be a vector, not a matrix. We can't compose aggregators since their domains don't match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cc: feat Conventional commit type for new features. package: aggregation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add support for custom conflict-resolution hooks in gradient aggregation

3 participants