[AutoDiff] Fix control flow AD when OME is skipped. #28459
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.
-enable-strip-ownership-after-serializationis now true by default,skipping ownership model eliminator after differentiation.
This is problematic for control flow differentiation.
VJPEmittercreatestrampoline bbs, which create predecessor enum values and immediately branch to
a destination bb. Trampoline bbs share the argument of their destination bb,
which may have
@guaranteedownership kind.@guaranteedvalues need a singlelifetime-ending use, e.g. an
end_borrow.Previously,
VJPEmitter::trampolinedGuaranteedPhiArgumentstracked all@guaranteedtrampoline/destination bb argument pairs and emitted anend_borrowfor the trampoline bb argument after the clonedend_borrowforthe destination bb argument. However, this does not work when ownership model
eliminator is skipped: mandatory inlining invokes
mergeBasicBlockson VJPs,which causes the
end_borrowinstructions to be redundant.Now,
VJPEmitterpreemptively callsmergeBasicBlocks, which merges trampolinebbs with their destinations.
@guaranteedbb arguments are merged and no longerduplicated, so there is no need to specially emit
end_borrowfor them.Consequences:
the transform to generate the merged destination bbs in the first place.
Resolves TF-990.