[mutable-arrays] allow internal-only refs in remat #31389
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.
A few ingredients were needed:
InternalMutableArrayEffectas allowed under remat (just whitelisting it)NotImplementedErrorin the scan discharge rule, solved when we used the aptly-namedstate_discharge2@dougalm observed a downside to item 3: it means remat with an everything-saveable policy is not the same as AD classic (without the remat decorator). That's because we always remat these internally-stateful operations, regardless of policy. An alternative is to always save such computations (regardless of policy), but then we can't recover full remat. We don't want to risk splitting up stateful operations across the two sides, and it's sufficient to always put them one way or the other (regardless of policy). One way around this would be to statically switch on everything-saveable and/or nothing-saveable policies, represented as something other than an opaque callback.
We still can't handle this code until we redo remat again on top of direct-linearize (remat3):