-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff][SILGen] Did not create differentiability witness for function #59135
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
This originated between the 2021-09-09 and 2021-09-14 development snapshots (September 2021). |
The crash has some peculiar characteristics for when it appears and how it manifests:
Release toolchains
Development toolchains
When you add the
For now my solution in S4TF is: make both |
* Initial support for release toolchains * Fix typo * Remove fatal error * Comment out x10_training_loop for Colab * Make `Mergeable.stack` differentiable, working around swiftlang/swift#59876 * Remove #available(macOS 9999, *) restriction * Enable RNN tests * Re-enable tensorflow#1162 * Allow Array replaceSubrange * Fit within 100 spaces * Type fix "partecipating" -> "participating" * Remove redundant same-type constraint * Remove deprecated Dataset API and reposition Zip2TensorGroup * Refactor tests * Refactor X10 tests * Fix failing tests on macOS + arm64 * Remove workarounds for swiftlang/swift#55703 (SR-13263) * Enable ops_test.swift * Optimize ops_test.swift * Optimize more tests * Rename gradient(at:in) to gradient(at:of:) * Rename argument label in withoutDerivative * Enable tests blocked by reflection crash * Workaround for swiftlang/swift#59135 on dev toolchains * Fix tests for Colab * Attempt to speed up tests on Colab * Revert changes to tests * Fix tests on Colab NVIDIA GPU * Revert specializations for NVIDIA GPUs
@philipturner Why are you closing it? |
This does still reproduce with the 2023-04-27 nightly snapshot, in the same form. |
This is showing up in some of the work we've been doing recently. I have the following single-file reproducer: import Foundation
import _Differentiation
struct B: Differentiable{}
struct X { var j = [Float]()}
struct W: Differentiable {
@noDerivative var z: X
var h: B
}
func o<T, R>(_ x: T, _ f: @differentiable(reverse) (T) -> R) -> R {f(x)}
func m<T, R>(_ f: @escaping @differentiable(reverse) (T) -> R) -> @differentiable(reverse) (T) -> R {{ x in o(x, f) }}
@differentiable(reverse)
func s(h: B) -> B {
var (_, e) = (0,0)
@differentiable(reverse)
func y(_ i: W) -> W {
for m in 0 ... e {let d = i.z.j[m]}
return i
}
let w = m(y)
return B()
} Here's the stack trace when building with the 6.1 2025-03-25a toolchain:
The stack trace is similar, but not quite. I'm not sure if it's a result of the codebase changing after a couple of years. |
Here is the assertion:
Looks like we failed to create witness for: // function_ref specialized y #1 (_:) in s(h:)
%12 = function_ref @$s4main1s1hAA1BVAE_tF1yL_yAA1WVAHFTf2ni_n : $@convention(thin) (@guaranteed W, Int) -> @owned W // user: %14
%13 = load [trivial] %2 // user: %14
%14 = partial_apply [callee_guaranteed] %12(%13) : $@convention(thin) (@guaranteed W, Int) -> @owned W // user: %15
%15 = differentiable_function [parameters 0] [results 0] %14 // users: %34, %16 So, it is likely related to nested functions. And unlikely to the original issue testcase as above... |
So, here the problem is the mandatory CapturePromotion pass that specialized closure taking arguments by reference into closures taking arguments by value. In this particular case it does not create differentiability witness for the newly cloned function. |
The original issue is different. Without // differentiability witness for Tensor.subscriptRanges()
sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] @$s4main6TensorV15subscriptRangesACyF : $@convention(method) (Tensor) -> Tensor {
}
// differentiability witness for Tensor.subscriptIndexPath()
sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] @$s4main6TensorV18subscriptIndexPathACyF : $@convention(method) (Tensor) -> Tensor {
vjp: @$s4main6TensorV18subscriptIndexPathACyFTJrSpSr : $@convention(method) (Tensor) -> (Tensor, @owned @callee_guaranteed (Tensor) -> Tensor)
} And with // differentiability witness for Tensor.subscriptRanges()
sil_differentiability_witness [serialized] [reverse] [parameters 0] [results 0] @$s4main6TensorV15subscriptRangesACyF : $@convention(method) (Tensor) -> Tensor {
} hence the assertion. |
So, the original function I guess this raises interesting questions, similar to |
Describe the bug
When running the following script, the compiler crashes. Use
swiftc file.swift -emit-module
to reproduce this behavior.Reproducer
Expected behavior
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: