-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] populate diff witnesses during differentiation #28402
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
marcrasi
merged 2 commits into
swiftlang:tensorflow
from
marcrasi:populate-diff-witness
Nov 21, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
78 changes: 78 additions & 0 deletions
78
test/AutoDiff/pass_creates_differentiability_witnesses.swift
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,78 @@ | ||
// RUN: %target-swift-frontend -emit-sil -emit-sorted-sil %s | %FileCheck %s | ||
|
||
// MARK: - Public functions | ||
|
||
@differentiable | ||
@_silgen_name("f000_invokedDirectlyByDifferentiableAttrPublic") | ||
public func f000_invokedDirectlyByDifferentiableAttrPublic(_ x: Float) -> Float { | ||
return f001_invokedIndirectlyByDifferentiableAttrPublic(x) | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness [parameters 0] [results 0] @f000_invokedDirectlyByDifferentiableAttrPublic | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
@_silgen_name("f001_invokedIndirectlyByDifferentiableAttrPublic") | ||
public func f001_invokedIndirectlyByDifferentiableAttrPublic(_ x: Float) -> Float { | ||
return x | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f001_invokedIndirectlyByDifferentiableAttrPublic | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
@_silgen_name("f002_invokedDirectlyByConversionPublic") | ||
public func f002_invokedDirectlyByConversionPublic(_ x: Float) -> Float { | ||
return f003_invokedIndirectlyByConversionPublic(x) | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f002_invokedDirectlyByConversionPublic | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
@_silgen_name("f003_invokedIndirectlyByConversionPublic") | ||
public func f003_invokedIndirectlyByConversionPublic(_ x: Float) -> Float { | ||
return x | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f003_invokedIndirectlyByConversionPublic | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
// MARK: - Internal functions | ||
|
||
@differentiable | ||
@_silgen_name("f004_invokedDirectlyByDifferentiableAttrInternal") | ||
internal func f004_invokedDirectlyByDifferentiableAttrInternal(_ x: Float) -> Float { | ||
return f005_invokedIndirectlyByDifferentiableAttrInternal(x) | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f004_invokedDirectlyByDifferentiableAttrInternal | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
@_silgen_name("f005_invokedIndirectlyByDifferentiableAttrInternal") | ||
internal func f005_invokedIndirectlyByDifferentiableAttrInternal(_ x: Float) -> Float { | ||
return x | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f005_invokedIndirectlyByDifferentiableAttrInternal | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
@_silgen_name("f006_invokedDirectlyByConversionInternal") | ||
internal func f006_invokedDirectlyByConversionInternal(_ x: Float) -> Float { | ||
return f007_invokedIndirectlyByConversionInternal(x) | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f006_invokedDirectlyByConversionInternal | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
@_silgen_name("f007_invokedIndirectlyByConversionInternal") | ||
internal func f007_invokedIndirectlyByConversionInternal(_ x: Float) -> Float { | ||
return x | ||
} | ||
// CHECK-LABEL: sil_differentiability_witness hidden [parameters 0] [results 0] @f007_invokedIndirectlyByConversionInternal | ||
// CHECK-NEXT: jvp | ||
// CHECK-NEXT: vjp | ||
|
||
func invokesByConversion() -> Float { | ||
var result: Float = 0 | ||
result += gradient(at: 0, in: f002_invokedDirectlyByConversionPublic) | ||
result += gradient(at: 0, in: f006_invokedDirectlyByConversionInternal) | ||
return result | ||
} |
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
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.
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.
I wonder if the only case that triggers this "capacity extending due to captured variables" logic is the
@differentiable
attribute onfunc original
nested infunc differentiableFunction(from:)
?Full context: there are known issues regarding differentiation and local variable capture (TF-881). @rxwei mentioned disallowing
@differentiable
attribute on nested functions for now and creating a builtin to supportfunc differentiableFunction(from:)
. One known user ofdifferentiableFunction(from:)
is the custom differentiation tutorial.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.
Yes, that's the only thing (in the stdlib + swift-apis + tests, at least) that triggers this problem.
It would indeed be nice to remove that and forbid
@differentiable
on nested functions for now.