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] Enable differentiation of generic functions. #22023

Merged
merged 3 commits into from Jan 21, 2019

Conversation

dan-zheng
Copy link
Collaborator

@dan-zheng dan-zheng commented Jan 21, 2019

  • Relax differentiability diagnostic for generic functions.
    • Previously, an error was emitted when attempting to differentiate any
      generic function. Now, diagnose only functions with indirect
      differentiation parameters/result.
  • Propagate differentiation associated function generic signature throughout
    differentiation pass.
    • Change PrimalGenCloner to inherit TypeSubstCloner.
    • Make primal value structs inherit primal function's generic parameters
      and signature.
    • Calculate correct substitution map for PrimalGenCloner::visitApplyInst.
      Emit diagnostic when apply instruction's associated function (e.g. VJP)
      has generic requirements unmet by the primal generic environment.
    • Remap types in AdjointEmitter.
  • Remove manual @differentiable attribute where clause conformance
    requirement checks.
    • GenericSignatureBuilder already performs checks so manual checks are
      unnecessary.

@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Jan 21, 2019
@dan-zheng dan-zheng requested a review from rxwei January 21, 2019 11:47
- Relax differentiability diagnostic for generic functions.
  - Previously, an error was emitted when attempting to differentiate any
    generic function. Now, diagnose only functions with indirect
    differentiation parameters/result.
- Propagate differentiation associated function generic signature throughout
  differentiation pass.
  - Change `PrimalGenCloner` to inherit `TypeSubstCloner`.
  - Make primal value structs inherit primal function's generic parameters
    and signature.
  - Calculate correct substitution map for `PrimalGenCloner::visitApplyInst`.
    Emit diagnostic when apply instruction's associated function (e.g. VJP)
    has generic requirements unmet by the primal generic environment.
  - Remap types in `AdjointEmitter`.
- Remove manually `@differentiable` attribute where clause conformance
  requirement checks.
  - `GenericSignatureBuilder` already performs checks so manual checks are
     unnecessary.
@dan-zheng dan-zheng force-pushed the enable-generic-differentiation branch from 6b0e269 to e2155bf Compare January 21, 2019 11:51
lib/SILOptimizer/Mandatory/Differentiation.cpp Outdated Show resolved Hide resolved
lib/SILOptimizer/Mandatory/Differentiation.cpp Outdated Show resolved Hide resolved
lib/SILOptimizer/Mandatory/Differentiation.cpp Outdated Show resolved Hide resolved
lib/SILOptimizer/Mandatory/Differentiation.cpp Outdated Show resolved Hide resolved
test/AutoDiff/autodiff_diagnostics.swift Show resolved Hide resolved
include/swift/AST/DiagnosticsSIL.def Show resolved Hide resolved
TODO: Add more tests.
Copy link
Member

@rxwei rxwei left a comment

Choose a reason for hiding this comment

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

Congrats on figuring out generics! :)

lib/SILOptimizer/Mandatory/Differentiation.cpp Outdated Show resolved Hide resolved
lib/SILOptimizer/Mandatory/Differentiation.cpp Outdated Show resolved Hide resolved
@dan-zheng
Copy link
Collaborator Author

@swift-ci Please test tensorflow

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.

None yet

2 participants