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

[AutoDiff upstream] Add @derivative(of:) attribute. #28321

Merged
merged 1 commit into from
Dec 10, 2019

Conversation

dan-zheng
Copy link
Contributor

@dan-zheng dan-zheng commented Nov 18, 2019

The @derivative(of:) attribute registers a function as a derivative of another function.
This patch adds the @derivative(of:) attribute definition, syntax, parsing, and printing.

Resolves TF-826.

Todos:

@dan-zheng
Copy link
Contributor Author

cc @rxwei @marcrasi @bgogul

Copy link
Contributor

@lattner lattner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few changes, thanks!

rxwei added a commit that referenced this pull request Nov 23, 2019
…utes.

In the code review for #28321, the main developers of AutoDiff agreed to rename `@differentiating` and `@transposing` to `@derivative(of:)` and `@transpose(of:)`, respectively.  This PR updates the manifesto to reflect this change.
dan-zheng added a commit to dan-zheng/swift that referenced this pull request Nov 26, 2019
Rename `@differentiating` to `@derivative(of:)`. `@derivative(of:)` more
clearly evokes derivative registration; the syntax is otherwise unchanged.

Deprecate `@differentiating`, to be removed in the next release.

Discussed here:
swiftlang#28321 (comment)

Partially resolves TF-999.
TF-1000 tracks updating all `@differentiating` usages across repositories.
rxwei pushed a commit that referenced this pull request Nov 26, 2019
Rename `@differentiating` to `@derivative(of:)`. `@derivative(of:)` more
clearly evokes derivative registration; the syntax is otherwise unchanged.

Deprecate `@differentiating`, to be removed in the next release.

Discussed here: #28321 (comment).

Partially resolves TF-999.
TF-1000 tracks updating all `@differentiating` usages across repositories.

---

Confirmed via `grep -nr differentiating include lib stdlib test` that all
remaining occurrences are intended.

---

Example:
```swift
extension Float {
    @Derivative(of: +)
    static func vjpAdd(lhs: Self, rhs: Self) -> (value: Self, pullback: (Self) -> (Self, Self)) {
       (lhs + rhs, { v in (v, v) })
    }
}
```
dan-zheng added a commit to dan-zheng/swift that referenced this pull request Nov 26, 2019
Rename `@transposing` to `@transpose(of:)` and deprecate `@transposing`.
`@transpose(of:)` more clearly evokes transpose registration; the syntax is
otherwise unchanged.

Discussed here:
swiftlang#28321 (comment)

Resolves TF-992.

TF-999 tracks removing `@transposing` attribute in the next release.
TF-1009 tracks `@transpose` syntax support for qualified names.
dan-zheng added a commit that referenced this pull request Nov 27, 2019
Rename `@transposing` to `@transpose(of:)`. `@transpose(of:)` more clearly
evokes transpose registration; the syntax is otherwise unchanged.

Discussed here:
#28321 (comment)

Remove `@transposing`. Removal without deprecation should be fine because
there are no known users of `@transposing` attribute.

Resolves TF-992.

TF-1009 tracks `@transpose` syntax support for qualified names.
@dan-zheng dan-zheng force-pushed the upstream-differentiating-attr branch 2 times, most recently from 4b9f025 to 9acdfba Compare December 10, 2019 06:12
@dan-zheng dan-zheng changed the title [AutoDiff upstream] Add @differentiating attribute. [AutoDiff upstream] Add @derivative(of:) attribute. Dec 10, 2019
@dan-zheng
Copy link
Contributor Author

I addressed all comments and rebased onto master.

There are no major changes: the biggest syntax change is renaming @differentiating to @derivative(of:), which has already been done on tensorflow branch: #28481.

dan-zheng added a commit to dan-zheng/swift-syntax that referenced this pull request Dec 10, 2019
…ibute.

Update gyb-generated files for `@derivative` attribute.
Friend PR: swiftlang/swift#28321
dan-zheng added a commit to dan-zheng/swift-syntax that referenced this pull request Dec 10, 2019
Update gyb-generated files for `@derivative` attribute.
Friend PR: swiftlang/swift#28321
@dan-zheng dan-zheng force-pushed the upstream-differentiating-attr branch from 9acdfba to 03ae118 Compare December 10, 2019 07:03
The `@derivative(of:)` attribute registers a function as a derivative of another
function. This patch adds the `@derivative(of:)` attribute definition, syntax,
parsing, and printing.

Resolves TF-826.

Todos:
- Type-checking (TF-829).
- Serialization (TF-837).
@dan-zheng dan-zheng force-pushed the upstream-differentiating-attr branch from 03ae118 to 48e3b47 Compare December 10, 2019 07:19
@dan-zheng
Copy link
Contributor Author

swiftlang/swift-syntax#188
@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9acdfba49cc212523c0224a44a4da95bfb2e760e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9acdfba49cc212523c0224a44a4da95bfb2e760e

@dan-zheng
Copy link
Contributor Author

Merging since there are no major changes since the last approval and CI has passed.

@dan-zheng dan-zheng merged commit 0585eb0 into swiftlang:master Dec 10, 2019
@dan-zheng dan-zheng deleted the upstream-differentiating-attr branch December 10, 2019 17:29
dan-zheng added a commit that referenced this pull request Dec 10, 2019
Minor style fixes and gardening.
Change code to be closer to master after #28321.
dan-zheng added a commit to dan-zheng/swift-syntax that referenced this pull request Apr 8, 2020
Update gyb-generated files for `@derivative` attribute.
Friend PR: swiftlang/swift#28321
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.

5 participants