[RELAY][GRAD] Fix first-order AD on tuple arguments #6827
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first-order AD currently incorrectly deals with functions with tuple arguments, in particular by trying to add tuples when summing the gradients. Notably, this causes errors in the gradients of functions like
stack
which take a tuple of tensors. This PR lifts addition to work on the tuples (which was already done by the higher-order AD).However, higher-order AD currently does not support tuples in the top-level function, and I added an xfail test to show this. I'm not sure how hard it is to change the higher-order code to support tuples at the top-level, so maybe someone else can take a look.
cc @MarisaKirisame @t-vi