-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AD] Rewrite some of the tests with Tracked<Float> (2) #27767
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fccb33a
Leak checking in superset_adjoint.swift
bgogul e2b95df
Leak checking in method.swift.
bgogul a8c9ca7
Add a valueWithGradient function.
bgogul 016a8bc
Leak checking class_method.swift.
bgogul f8291cb
Leak checking for existential.swift.
bgogul 237afc5
Simplify versions of gradient.
bgogul 03704df
Leak checking for e2e_differentiable_property.swift
bgogul 41a9f93
Leak checking for custom_derivatives.swift
bgogul 0f2711a
Some leak checking in array.swift
bgogul 4e05254
Some leak checking in forward_mode_runtime.swift
bgogul 6b170e0
Formatting.
dan-zheng 4750624
Formatting update to test/AutoDiff/custom_derivatives.swift
bgogul 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,18 +257,27 @@ extension Tracked where T : Differentiable & FloatingPoint, T == T.TangentVector | |
} | ||
} | ||
|
||
// Differential operators for `Tracked<Float>`. | ||
public func gradient( | ||
at x: Tracked<Float>, in f: @differentiable (Tracked<Float>) -> Tracked<Float> | ||
) -> Tracked<Float> { | ||
return pullback(at: x, in: f)(1) | ||
// Differential operators for `Tracked<T>`. | ||
|
||
public func gradient<T, U>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Single gradient operator definitions for |
||
at x: T, in f: @differentiable (T) -> Tracked<U> | ||
) -> T.TangentVector | ||
where U : FloatingPoint, U.TangentVector == U { | ||
return pullback(at: x, in: f)(Tracked<U>(1)) | ||
} | ||
|
||
public func gradient<T, U, R>( | ||
at x: T, _ y: U, in f: @differentiable (T, U) -> Tracked<R> | ||
) -> (T.TangentVector, U.TangentVector) | ||
where R : FloatingPoint, R.TangentVector == R { | ||
return pullback(at: x, y, in: f)(Tracked<R>(1)) | ||
} | ||
|
||
public func gradient( | ||
at x: Tracked<Float>, _ y: Tracked<Float>, | ||
in f: @differentiable (Tracked<Float>, Tracked<Float>) -> Tracked<Float> | ||
) -> (Tracked<Float>, Tracked<Float>) { | ||
return pullback(at: x, y, in: f)(1) | ||
public func valueWithGradient<T, U : FloatingPoint>( | ||
at x: T, in f: @differentiable (T) -> Tracked<U> | ||
) -> (value: Tracked<U>, gradient: T.TangentVector) { | ||
let (y, pullback) = valueWithPullback(at: x, in: f) | ||
return (y, pullback(Tracked<U>(1))) | ||
} | ||
|
||
public extension Differentiable { | ||
|
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
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.
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.
Differential operators in this file can actually be deleted once
Tracked
conforms toFloatingPoint
. Were you working in this direction?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.
IIRC,
Tracked: FloatingPoint
conformance caused*
operator lookup for@differentiating(*)
to become ambiguous.That seems workaround-able by using
@differentiable(vjp: ...)
for now. We should probably investigate fixing@differentiating(*)
ambiguous lookup (and@differentiating
original declaration lookup for initializers/subscripts/properties) sometime.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.
@rxwei, yes it would be good to make
Tracked
conform toFloatingPoint
, but have issues that Dan mentions. I had already filed a bug: https://bugs.swift.org/browse/TF-926