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

[SR-9448] [AD] Diagnose @autodiff function types whose parameters or results don't conform to Differentiable #51912

Closed
rxwei opened this issue Dec 8, 2018 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow

Comments

@rxwei
Copy link
Member

rxwei commented Dec 8, 2018

Previous ID SR-9448
Radar None
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee pschuh (JIRA)
Priority Medium

md5: befdfabb4c9c4f81ed793d918da2b9d7

Issue Description:

Test case

struct NonDiffType { var x: Int }
// expected-error @+1 {{argument is not differentiable, but the enclosing function type is marked '@autodiff'; did you want to add '@nondiff' to this argument?}}
let _: @autodiff (NonDiffType) -> Float
// expected-error @+1 {{result is not differentiable, but the enclosing function type is marked '@autodiff'; did you want to add '@nondiff' to this argument?}}
let _: @autodiff (Float) -> NonDiffType
@rxwei
Copy link
Member Author

rxwei commented Jan 26, 2019

pschuh (JIRA User) Interested in looking into this?

@swift-ci
Copy link
Collaborator

Comment by Parker Schuh (JIRA)

Hi Richard, I took a look at this and I'm able to generate the warnings in TypeCheckType.cpp, but it incorrectly fails on:

func evaldiff<T: Differentiable, U: Differentiable>(_ f: @autodiff (T) -> U, _ x: T) -> (U, (T.TangentVector) -> U.TangentVector)
where T == T.TangentVector {
return Builtin.autodiffApply_jvp(f, x)
}

I'm just trying to sort out how to check type conformance when it is a generic_type_param_type.

However, If I blindly allow all generics (as a hack) I an error for:

func methoddiff<T: Differentiable, U: Differentiable, R: Differentiable>(_ f: @autodiff (T) -> (U) -> R, _ x: T, _ y: U)

It is complaining about: (U) -> R not conforming to a protocol.

@rxwei
Copy link
Member Author

rxwei commented Jan 28, 2019

Just sent #22166 for you to be able to calculate an AD-associated vector space of a function type.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow
Projects
None yet
Development

No branches or pull requests

2 participants