-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Serialization] Implement serialization for @differentiable attribute. #17155
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
dan-zheng
merged 6 commits into
swiftlang:tensorflow
from
dan-zheng:serialize-autodiff-attr
Jun 13, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4da28d
[Serialization] Implement serialization for @differentiable attribute.
dan-zheng 05c381e
Merge branch 'tensorflow' into serialize-autodiff-attr
dan-zheng d7ea8bc
Update module format version minor number.
dan-zheng f750ef8
Add SWIFT_ENABLE_TENSORFLOW marker comments.
dan-zheng 3fdf49a
Minor edits.
dan-zheng 1e73971
Fix typo.
dan-zheng 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SWIFT_ENABLE_TENSORFLOW | ||
// TODO: Handle trailing where clause in @differentiable attribute. | ||
|
||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend %s -emit-module -parse-as-library -o %t | ||
// RUN: %target-sil-opt -disable-sil-linking -enable-sil-verify-all %t/differentiable_attr.swiftmodule -o - | %FileCheck %s | ||
|
||
struct CheckpointsFoo {} | ||
func pfoo(_ x: Float) -> (checkpoints: CheckpointsFoo, originalValue: Float) { | ||
return (CheckpointsFoo(), x * x) | ||
} | ||
func dfoo_checkpointed(_ x: Float, checkpoints: CheckpointsFoo, originalValue: Float, seed: Float) -> Float { | ||
return 2 * x | ||
} | ||
// CHECK-DAG: @differentiable(reverse, primal: pfoo, adjoint: dfoo_checkpointed) | ||
// CHECK-DAG: func foo_checkpointed(_ x: Float) -> Float | ||
@differentiable(reverse, primal: pfoo(_:), adjoint: dfoo_checkpointed(_:checkpoints:originalValue:seed:)) | ||
func foo_checkpointed(_ x: Float) -> Float { | ||
return x * x | ||
} | ||
|
||
struct S<T> { | ||
struct Checkpoints { | ||
let s: S | ||
} | ||
func primal(x: Float) -> (Checkpoints, Float) { | ||
return (Checkpoints(s: self), x) | ||
} | ||
func adjoint_checkpointed(x: Float, _: Checkpoints, _: Float, _: Float) -> S { | ||
return self | ||
} | ||
|
||
// CHECK-DAG: @differentiable(reverse, (self), primal: primal, adjoint: adjoint_checkpointed) | ||
// CHECK-DAG: func original(x: Float) -> Float | ||
@differentiable(reverse, withRespectTo: (self), primal: primal, adjoint: adjoint_checkpointed) | ||
func original(x: Float) -> Float { | ||
return x | ||
} | ||
} | ||
|
||
func pbaz1<T>(_ x: T, _ y: T) -> ((T, T), T) { | ||
return ((y, y), x) | ||
} | ||
func dbaz1_checkpointed<T>(_ x: T, _ y: T, primal: (T, T), originalValue: T, seed: T) -> (T, T) { | ||
return (y, x) | ||
} | ||
// CHECK-DAG: @differentiable(reverse, primal: pbaz1, adjoint: dbaz1_checkpointed) | ||
// CHECK-DAG: func baz1_checkpointed<T>(_ x: T, _ y: T) -> T | ||
@differentiable(reverse, primal: pbaz1(_:_:), adjoint: dbaz1_checkpointed(_:_:primal:originalValue:seed:)) | ||
func baz1_checkpointed<T>(_ x: T, _ y: T) -> T { | ||
return x | ||
} | ||
|
||
struct CheckpointsFP<T : FloatingPoint> { | ||
let meow: T | ||
} | ||
func pbaz2<T : FloatingPoint>(_ x: T, _ y: T) -> (CheckpointsFP<T>, T) { | ||
return (CheckpointsFP(meow: 1), x + y) | ||
} | ||
func dbaz2_checkpointed<T : FloatingPoint>(_ x: T, _ y: T, primal: CheckpointsFP<T>, originalValue: T, seed: T) -> (T, T) { | ||
return (1, 1) | ||
} | ||
// CHECK-DAG: @differentiable(reverse, primal: pbaz2, adjoint: dbaz2_checkpointed) | ||
// CHECK-DAG: func baz2_checkpointed<T>(_ x: T, _ y: T) -> T where T : FloatingPoint | ||
@differentiable(reverse, primal: pbaz2(_:_:), adjoint: dbaz2_checkpointed(_:_:primal:originalValue:seed:)) | ||
func baz2_checkpointed<T : FloatingPoint>(_ x: T, _ y: T) -> T { | ||
return x | ||
} |
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.
VERSION_MINOR in this file needs to be bumped.
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.
Thanks! Done in d7ea8bc.