-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[AutoDiff] Initial Forward Mode AD Support #26057
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
bartchr808
merged 51 commits into
swiftlang:tensorflow
from
bartchr808:differential-emitter
Aug 20, 2019
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
fb2d647
Merge in work from branch jvp-emitter.
bartchr808 34fcebe
Init commit.
bartchr808 571b5e8
WIP.
bartchr808 1651a78
Make DifferentialEmitter create differential.
bartchr808 2ce55ec
Merge branch 'tensorflow' into differential-emitter
bartchr808 a06d54d
Typos and small bugs.
bartchr808 0ca031b
Get visitApplyInst and visitReturnInst working.
bartchr808 652a6d7
Remove multi block logic.
bartchr808 8fd3e44
WIP
bartchr808 5aeca34
Merge branch 'tensorflow' into differential-emitter
bartchr808 d04b479
Accidentally removed mapper.
bartchr808 966c470
Move JVP lower and start adding AdjointValue.
bartchr808 5883668
Create differential builder.
bartchr808 f27a2bd
Get value mapping for seed params.
bartchr808 da8b1d6
PullbackInfo -> LinearMapInfo.
bartchr808 8aade2f
Get correct output, have retain memory leak.
bartchr808 17776b5
Move around code.
bartchr808 e313857
Fix release bug.
bartchr808 0d7c17c
More cleanup.
bartchr808 e60e478
More cleanup x2.
bartchr808 95c7321
Add tangent accumulation.
bartchr808 e20f3a6
Merge branch 'tensorflow' into differential-emitter
bartchr808 f20b98a
PR feedback #1.
bartchr808 3ad5c96
WIP: start adding tests.
bartchr808 3fb255d
Merge branch 'tensorflow' into differential-emitter
bartchr808 0973f3f
Fix SIL tests.
bartchr808 2ac6316
Remove tangent aggregation logic and cleanup.
bartchr808 75aa17c
Merge branch 'tensorflow' into differential-emitter
bartchr808 bca2df3
Fix comments, add jvpNegate, add/modify tests, simplify lit flag.
bartchr808 71db0ca
Merge branch 'tensorflow' into differential-emitter
bartchr808 14eef90
PR feedback.
bartchr808 64e334d
Update new test due to upstream changes and existing tests now that J…
bartchr808 8eb5bf5
PR feedback.
bartchr808 0b1f430
Fix tests and PR feedback.
bartchr808 5a6cdae
PR feedback.
bartchr808 c8fac01
[NFC] Fix naming.
dan-zheng 293dca1
PR feedback and additional 'Tracked<Float>' tests.
bartchr808 4881e7b
[NFC] Small name and spacing changes.
bartchr808 96a5c66
Merge branch 'tensorflow' into differential-emitter
bartchr808 6889345
Revamp linear map info struct creation.
bartchr808 9ad0596
Merge branch 'tensorflow' into differential-emitter
bartchr808 cbd0fa2
Merge branch 'tensorflow' into differential-emitter
bartchr808 54b97bd
WIP: throw fatal error in JVPs that aren't defined.
bartchr808 cbce4d4
Throw fatal error in JVPs that aren't defined.
bartchr808 6b82eee
Gardening.
bartchr808 af1f241
Merge branch 'differential-emitter' of https://github.com/bartchr808/…
bartchr808 e4025d3
Merge branch 'tensorflow' into differential-emitter
bartchr808 1883ac1
Make changes for ownership change.
bartchr808 fb68404
Style feedback.
bartchr808 129a3d5
Add more tests (classes, protocols) and PR feedback.
bartchr808 adaf91b
PR feedback.
bartchr808 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // RUN: %target-swift-frontend -Xllvm -run-jvp-generation -emit-sil -verify %s | ||
|
|
||
| // TODO: move these tests back into `autodiff_diagnostics.swift` once | ||
| // forward mode reaches feature parity with reverse mode. | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Basic function | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| func one_to_one_0(_ x: Float) -> Float { | ||
| return x + 2 | ||
| } | ||
|
|
||
| _ = derivative(at: 0, in: one_to_one_0) // okay! | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Function composition | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| func base(_ x: Float) -> Float { | ||
| // expected-error @+2 2 {{expression is not differentiable}} | ||
| // expected-note @+1 2 {{cannot differentiate through a non-differentiable result; do you want to use 'withoutDerivative(at:)'?}} | ||
| return Float(Int(x)) | ||
| } | ||
|
|
||
| // TODO: Fix nested differentiation diagnostics. Need to fix indirect differentiation invokers. | ||
| func nested(_ x: Float) -> Float { | ||
| // xpected-note @+1 {{when differentiating this function call}} | ||
| return base(x) | ||
| } | ||
|
|
||
| func middle(_ x: Float) -> Float { | ||
| // xpected-note @+1 {{when differentiating this function call}} | ||
| return nested(x) | ||
| } | ||
|
|
||
| func middle2(_ x: Float) -> Float { | ||
| // xpected-note @+1 {{when differentiating this function call}} | ||
| return middle(x) | ||
| } | ||
|
|
||
| func func_to_diff(_ x: Float) -> Float { | ||
| // xpected-note @+1 {{expression is not differentiable}} | ||
| return middle2(x) | ||
| } | ||
|
|
||
| func calls_diff_of_nested(_ x: Float) -> Float { | ||
| // xpected-error @+1 {{function is not differentiable}} | ||
| return derivative(at: x, in: func_to_diff) | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Inout arguments | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| func activeInoutArg(_ x: Float) -> Float { | ||
| var a = x | ||
| // expected-note @+1 {{cannot differentiate through 'inout' arguments}} | ||
| a += x | ||
| return a | ||
| } | ||
| // expected-error @+1 {{function is not differentiable}} | ||
| _ = differential(at: .zero, in: activeInoutArg(_:)) | ||
|
|
||
| func activeInoutArgTuple(_ x: Float) -> Float { | ||
| var tuple = (x, x) | ||
| // expected-note @+1 {{cannot differentiate through 'inout' arguments}} | ||
| tuple.0 *= x | ||
| return x * tuple.0 | ||
| } | ||
| // expected-error @+1 {{function is not differentiable}} | ||
| _ = differential(at: .zero, in: activeInoutArgTuple(_:)) | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Non-varied results | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| func one() -> Float { | ||
| return 1 | ||
| } | ||
| @differentiable | ||
| func nonVariedResult(_ x: Float) -> Float { | ||
| // expected-warning @+1 2 {{result does not depend on differentiation arguments and will always have a zero derivative; do you want to use 'withoutDerivative(at:)'?}} {{10-10=withoutDerivative(at:}} | ||
| return one() | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Subset parameters | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| func nondiff(_ f: @differentiable (Float, @nondiff Float) -> Float) -> Float { | ||
| // expected-note @+2 {{cannot differentiate with respect to a '@nondiff' parameter}} | ||
| // expected-error @+1 {{function is not differentiable}} | ||
| return derivative(at: 2, 3) { (x, y) in f(x * x, y) } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.