swift
79160afd - [AutoDiff] Fix over-consume when differentiating `tuple` instruction. (#28257)

Commit
5 years ago
[AutoDiff] Fix over-consume when differentiating `tuple` instruction. (#28257) Instruction visitors in `PullbackEmitter` should not consume adjoint values preemptively, because adjoint values are managed "globally" in a basic block by the block temporary mechanism. The crasher in TF-962 was caused by the previously unexercised logic in `PullbackEmitter::visitTupleInst`, where a `destructure_tuple` instruction is emitted with an adjoint value being its operand. This causes an over-consume. This patch fixes this by creating a copy of the adjoint value before destructuring it, and recording all destructured elements as block temporaries. TODO: The differentiation transform rarely visits `tuple` instructions. More tests should be added, for example, cases where the tuple type's tangent type is not a tuple (`([Float], Int)`). Resolves TF-962.
Author
Committer
Parents
Loading