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.
Something @willtebbutt pointed out to me the other day
We can use ChainRules's ability to define an inplace addition operation (the InplaceThunk) when defining the gradient of getindex.
Which would be much more efficient than e.g retuning a onehot dense matrix to be summed, and marginally more efficient than returning a onehot sparse matrix to be summed.
It would also mean maybe we would not need to say that the differential for a primal type depends on the primal type and the operation.
Though we still might want to.
Right now Zygote won't use ChainRules's inplace accumulation stuff, but idk how hard it would be to enable it.
I think it might be fine or it might (only) break nesting Zygote.
It would definitely require the deeper change over to ChainRules's types.
I am tempted to leave this WIP for a while and improve our abstractions, while trying to get Zygote to actually use this. (Though that is a bigger project as need Zygote to use ChainRules's trypes)