Skip to content

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

Merged
merged 1 commit into from
Dec 6, 2018
Merged

Use VJP in differentiation #21063

merged 1 commit into from
Dec 6, 2018

Conversation

marcrasi
Copy link

@marcrasi marcrasi commented Dec 5, 2018

(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.

@marcrasi marcrasi requested a review from rxwei December 5, 2018 22:34
@@ -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
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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);
Copy link
Contributor

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; }, [&]{});
Copy link
Contributor

@rxwei rxwei Dec 6, 2018

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.

@marcrasi
Copy link
Author

marcrasi commented Dec 6, 2018

@swift-ci please test tensorflow

@marcrasi marcrasi merged commit c91a626 into swiftlang:tensorflow Dec 6, 2018
@marcrasi marcrasi deleted the use-vjp branch December 6, 2018 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants