Skip to content
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

[6.1] [AutoDiff] Peel off @sendable implicit conversion when checking for unsupported differentiable function conversion #79538

Open
wants to merge 1 commit into
base: release/6.1
Choose a base branch
from

Conversation

clackary
Copy link

import Testing
import _Differentiation

@inlinable
@derivative(of: min)
public func _vjpMin<T: Comparable & Differentiable>(
    _ lhs: T,
    _ rhs: T
) -> (value: T, pullback: (T.TangentVector) -> (T.TangentVector, T.TangentVector)) {
    func pullback(_ tangentVector: T.TangentVector) -> (T.TangentVector, T.TangentVector) {
        if lhs <= rhs {
            return (tangentVector, .zero)
        }
        else {
            return (.zero, tangentVector)
        }
    }
    return (value: min(lhs, rhs), pullback: pullback)
}

@Test
func testMin() {
    @differentiable(reverse)
    func minContainer(_ lhs: Float, _ rhs: Float) -> Float {
        return min(lhs, rhs)
    }
    let vwgLessThan = valueWithGradient(at: 2.0, 3.0, of: min(_:_:))
    print(vwgLessThan.value == 2.0)
    print(vwgLessThan.gradient == (1.0, 0.0))
}

…nsupported differentiable function conversion (swiftlang#77869)

(cherry picked from commit 8e53ccd)
@clackary clackary requested a review from a team as a code owner February 21, 2025 17:08
@clackary
Copy link
Author

cc @JaapWijnen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants