Skip to content

[AutoDiff] Add '@differentiable(reverse)'. #35811

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 1 commit into from
Feb 8, 2021

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Feb 7, 2021

Compiler:

  • Add Forward and Reverse to DifferentiabilityKind.
  • Expand DifferentiabilityMask in ExtInfo to 3 bits so that it now holds all 4 cases of DifferentiabilityKind.
  • Parse @differentiable(reverse) and @differentiable(_forward) declaration attributes and type attributes.
  • Emit a warning for @differentiable without reverse.
  • Emit an error for @differentiable(_forward).
  • Rename @differentiable(linear) to @differentiable(_linear).
  • Make @differentiable(reverse) type lowering go through today's @differentiable code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:

  • Add Forward and Reverse to FunctionMetadataDifferentiabilityKind.
  • Extend TargetFunctionTypeFlags by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in DifferentiabilityMask which is reserved for AsyncMask and ConcurrentMask; AsyncMask is ABI-stable so we cannot change that.

_Differentiation module:

  • Replace all occurrences of @differentiable with @differentiable(reverse).
  • Delete _transpose(of:).

Resolves rdar://69980056.

@rxwei rxwei requested review from DougGregor and dan-zheng February 7, 2021 04:04
@rxwei
Copy link
Contributor Author

rxwei commented Feb 7, 2021

TODO: Update all the call sites.

@rxwei rxwei changed the title Rename '@differentiable' to '@differentiable(reverse)'. [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'. Feb 7, 2021
@rxwei rxwei force-pushed the 69980056-differentiable-reverse branch from 96e4059 to 283b3d2 Compare February 7, 2021 10:08
@rxwei rxwei requested a review from joshnewnham February 7, 2021 10:09
@rxwei rxwei force-pushed the 69980056-differentiable-reverse branch from 283b3d2 to f8ba991 Compare February 7, 2021 11:29
@rxwei rxwei changed the title [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'. [AutoDiff] Add '@differentiable(reverse)'. Feb 7, 2021
@rxwei rxwei force-pushed the 69980056-differentiable-reverse branch from f8ba991 to d457cb7 Compare February 7, 2021 13:51
@rxwei
Copy link
Contributor Author

rxwei commented Feb 7, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2021

Build failed
Swift Test OS X Platform
Git Sha - d457cb7a93f49375fb975502608099ffc137dd39

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2021

Build failed
Swift Test Linux Platform
Git Sha - d457cb7a93f49375fb975502608099ffc137dd39

Copy link

@joshnewnham joshnewnham left a comment

Choose a reason for hiding this comment

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

LGTM

@rxwei rxwei force-pushed the 69980056-differentiable-reverse branch 2 times, most recently from 624a6d4 to f2baf57 Compare February 7, 2021 21:58
Compiler:
- Add `Forward` and `Reverse` to `DifferentiabilityKind`.
- Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`.
- Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes.
- Emit a warning for `@differentiable` without `reverse`.
- Emit an error for `@differentiable(_forward)`.
- Rename `@differentiable(linear)` to `@differentiable(_linear)`.
- Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:
- Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`.
- Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that.

_Differentiation module:
- Replace all occurrences of `@differentiable` with `@differentiable(reverse)`.
- Delete `_transpose(of:)`.

Resolves rdar://69980056.
@rxwei rxwei force-pushed the 69980056-differentiable-reverse branch from f2baf57 to af8942d Compare February 7, 2021 22:09
@rxwei
Copy link
Contributor Author

rxwei commented Feb 7, 2021

@swift-ci please smoke test

@rxwei
Copy link
Contributor Author

rxwei commented Feb 7, 2021

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2021

Build failed
Swift Test OS X Platform
Git Sha - f2baf57f47e9d9be0e92d697c5bc26b85a19687f

@swift-ci
Copy link
Contributor

swift-ci commented Feb 7, 2021

Build failed
Swift Test Linux Platform
Git Sha - f2baf57f47e9d9be0e92d697c5bc26b85a19687f

@rxwei
Copy link
Contributor Author

rxwei commented Feb 8, 2021

@swift-ci please test and merge

@rxwei
Copy link
Contributor Author

rxwei commented Feb 8, 2021

@swift-ci please test macOS

rxwei added a commit to rxwei/swift-syntax that referenced this pull request Feb 8, 2021
@rxwei
Copy link
Contributor Author

rxwei commented Feb 8, 2021

swiftlang/swift-syntax#258
@swift-ci Please clean test

@rxwei rxwei merged commit 18fe723 into swiftlang:main Feb 8, 2021
@rxwei rxwei deleted the 69980056-differentiable-reverse branch February 8, 2021 12:32
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.

4 participants