-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Use VJP in differentiation #21063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use VJP in differentiation #21063
Conversation
@@ -1,4 +1,4 @@ | |||
// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s | |||
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug -Xllvm -debug-only -Xllvm differentiation %s | %FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unnecessary. We are not CHECK'ing against any debug dump.
// Get the pullback. | ||
auto *field = getPrimalInfo().lookupPullbackDecl(ai); | ||
assert(field); | ||
SILValue pullback = builder.createStructExtract(remapLocation(ai->getLoc()), primalValueAggregateInAdj, field); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80col
@@ -586,6 +612,14 @@ class PrimalInfo { | |||
: lookup->getSecond(); | |||
} | |||
|
|||
/// Finds the pullback decl in the primal value struct for an `apply` in the | |||
/// original function. | |||
VarDecl *lookupPullbackDecl(ApplyInst *inst) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been using "lookUp" instead of "lookup" in this file.
// Get all results in type-defined order. | ||
SmallVector<SILValue, 8> allResults; | ||
collectAllActualResultsInTypeOrder( | ||
pullbackCall, dirResults, pullbackCall->getIndirectSILResults(), allResults); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80col
LLVM_DEBUG({ | ||
auto &s = getADDebugStream(); | ||
s << "All direct results of the nested pullback call: \n"; | ||
interleave(dirResults, [&](SILValue v) { s << v; }, [&]{}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you aren't doing anything in between, then llvm::for_each
is a better fit than interleave
.
@swift-ci please test tensorflow |
(This is on top of #21062. Ask GitHub to see the last commit to see the changes before I merge #21062).
This teaches the differentiation pass to use VJPs.
I put it under a flag because the TensorFlow autodiff tests are still failing. I will investigate those failures next.