Skip to content

[Sema] [AutoDiff] Synthesize more @_fieldwiseProductSpace attributes. #21863

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 2 commits into from
Jan 15, 2019

Conversation

dan-zheng
Copy link
Contributor

When all members have all Differentiable associated types equal to Self,
a single member AllDifferentiableVariables struct is synthesized.
Later, TangentVector and CotangentVector typealiases are generated that
forward to it.

This patch proactively generates TangentVector and CotangentVector aliases
with the @_fieldwiseProductSpace attribute.

When all members have all `Differentiable` associated types equal to `Self`,
a single member `AllDifferentiableVariables` struct is synthesized.
Later, `TangentVector` and `CotangentVector` typealiases are generated that
forward to it.

This patch proactively generates `TangentVector` and `CotangentVector` aliases
with the `@_fieldwiseProductSpace` attribute.
@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Jan 15, 2019
@dan-zheng dan-zheng requested a review from rxwei January 15, 2019 01:16
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Jan 15, 2019

What if, in a type whose members’ tangent/cotangent/alldiffable equals the original type, the user explicitly declares ‘typealias TangentVector = AllDifferentiableVariables’? Will synthesis still run?

@dan-zheng
Copy link
Contributor Author

dan-zheng commented Jan 15, 2019

What if, in a type whose members’ tangent/cotangent/alldiffable equals the original type, the user explicitly declares ‘typealias TangentVector = AllDifferentiableVariables’? Will synthesis still run?

Not currently, but it's a simple fix to do so.
Since CI mysteriously failed and needs to run again, I'll push the fix in this PR.


EDIT: Sorry, I was mistaken. The following simple program fails:

// test.swift
public struct Foo : Differentiable {
  public var a: Float
  typealias TangentVector = AllDifferentiableVariables
}
test.swift:3:29: error: reference to invalid associated type 'AllDifferentiableVariables' of type 'Foo'
  typealias TangentVector = AllDifferentiableVariables
                            ^
test.swift:1:15: error: type 'Foo' does not conform to protocol 'Differentiable'
public struct Foo : Differentiable {
              ^
Swift.Differentiable:2:20: note: protocol requires nested type 'TangentVector'; do you want to add it?
    associatedtype TangentVector where Self.TangentVector == Self.AllDifferentiableVariables.TangentVector, Self.AllDifferentiableVariables.TangentVector == Self.CotangentVector.CotangentVector, Self.CotangentVector.TangentVector == Self.TangentVector.AllDifferentiableVariables.CotangentVector
                   ^
Swift.Differentiable:3:20: note: protocol requires nested type 'CotangentVector'; do you want to add it?
    associatedtype CotangentVector : Differentiable where Self.CotangentVector == Self.AllDifferentiableVariables.CotangentVector, Self.AllDifferentiableVariables.CotangentVector == Self.CotangentVector.TangentVector, Self.CotangentVector.CotangentVector == Self.TangentVector.AllDifferentiableVariables.TangentVector
                   ^
Swift.Differentiable:4:20: note: protocol requires nested type 'AllDifferentiableVariables'; do you want to add it?
    associatedtype AllDifferentiableVariables : Differentiable where Self.AllDifferentiableVariables == Self.AllDifferentiableVariables.AllDifferentiableVariables, Self.CotangentVector.AllDifferentiableVariables == Self.CotangentVector.AllDifferentiableVariables.AllDifferentiableVariables
                   ^

Referencing AllDifferentiableVariables in the source file seems problematic. We could try to work around that later, if important.

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor Author

macOS CI fails mysteriously, twice in a row now.
https://ci-external.swift.org/job/swift-PR-TensorFlow-macOS/640/console

@shahmishal Do you have any idea what's going on? Thanks!

@shahmishal
Copy link
Member

Looks like it lost connection:

Caused: java.io.IOException: Unexpected termination of the channel
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:73)
Caused: java.io.IOException: Backing channel 'macOS-tensorflow' is disconnected.

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Jan 15, 2019

The current synthesis behavior is fine. Not running synthesis is better than running and forgetting to add @fieldwise.

@rxwei rxwei merged commit 2d20e63 into swiftlang:tensorflow Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants