-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-14235] [AutoDiff] Cross-file differentiation error: derivative configuration not registered for @derivative
attribute
#55170
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
Comments
Look-up for functions with @Derivative attributes defined in non-primary source files Fixes #55170
@dan-zheng Apparently here is more serious problem which is not addressed by #58644. Consider the following case:
#58644 handles the case when a.swift: import _Differentiation
@differentiable(reverse)
func clamp(_ value: Double, _ lowerBound: Double, _ upperBound: Double) -> Double {
return max(min(value, upperBound), lowerBound)
} b.swift: import _Differentiation
@inlinable
@derivative(of: min)
func minVJP<T: Comparable & Differentiable>(
_ x: T,
_ y: T
) -> (value: T, pullback: (T.TangentVector) -> (T.TangentVector, T.TangentVector)) {
func pullback(_ v: T.TangentVector) -> (T.TangentVector, T.TangentVector) {
if x <= y {
return (v, .zero)
}
else {
return (.zero, v)
}
}
return (value: min(x, y), pullback: pullback)
}
@inlinable
@derivative(of: max)
func maxVJP<T: Comparable & Differentiable>(
_ x: T,
_ y: T
) -> (value: T, pullback: (T.TangentVector) -> (T.TangentVector, T.TangentVector)) {
func pullback(_ v: T.TangentVector) -> (T.TangentVector, T.TangentVector) {
if x < y {
return (.zero, v)
}
else {
return (v, .zero)
}
}
return (value: max(x, y), pullback: pullback)
} Looks like we'd need a dedicated pass over all non-primary sources to pull these custom derivatives :( Or something similar... |
Are you sure this is not currently working as intended? My understanding of the test case:
Expected behavior:
If you'd like to investigate this case, writing a multi-file test would be helpful! |
Well, I'd not put comment here w/o checking the testcase first ;)
Compiling both files together makes this error disappear obviously. |
Look-up for functions with @Derivative attributes defined in non-primary source files Fixes #55170
I'm reopening this issue as a1e138b implemented only partial fix |
…heck is finished for the primary source. This registers all custom derivatives before autodiff transformations and makes them available to them. Fully resolves swiftlang#55170
Look-up for functions with @Derivative attributes defined in non-primary source files Fixes swiftlang#55170
…wiftlang#58965) * Lookup for custom derivatives in non-primary source files after typecheck is finished for the primary source. This registers all custom derivatives before autodiff transformations and makes them available to them. Fully resolves swiftlang#55170
Additional Detail from JIRA
md5: 1c36955f37f690185a211308ac4034a9
Issue Description:
The error occurs because
AbstractFunctionDecl::getDerivativeConfigurations
is not sufficiently requestified to type-check@derivative
attributes in other files.The text was updated successfully, but these errors were encountered: