Skip to content

[AutoDiff upstream] Add differentiability_witness_function instruction. #29765

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 3 commits into from
Feb 14, 2020

Conversation

dan-zheng
Copy link
Contributor

The differentiability_witness_function instruction looks up a
differentiability witness function (JVP, VJP, or transpose) for a referenced
function via SIL differentiability witnesses.

// Example differentiability witnesses.
sil_differentiability_witness [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float

sil_differentiability_witness [parameters 0 1] [results 0] <T where T : Differentiable, T == T.TangentVector> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

// Example `differentiability_witness_function` instructions.
sil @test : $@convention(thin) () -> () {
bb0:
  %foo_jvp_wrt_0 = differentiability_witness_function [jvp] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
  %generic_vjp_wrt_0_1 = differentiability_witness_function [vjp] [parameters 0 1] [results 0] <T where T: Differentiable, T == T.TangentVector> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
  return undef : $()
}

Add round-trip parsing/serialization and IRGen tests.

Notes:

  • Differentiability witnesses for linear functions require more support.
    differentiability_witness_function [transpose] instructions do not yet
    have IRGen.
  • Nothing currently generates differentiability_witness_function instructions.
    The differentiation transform does, but it hasn't been upstreamed yet.

Resolves TF-1141.

…ion.

The `differentiability_witness_function` instruction looks up a
differentiability witness function (JVP, VJP, or transpose) for a referenced
function via SIL differentiability witnesses.

Add round-trip parsing/serialization and IRGen tests.

Notes:
- Differentiability witnesses for linear functions require more support.
  `differentiability_witness_function [transpose]` instructions do not yet
  have IRGen.
- Nothing currently generates `differentiability_witness_function` instructions.
  The differentiation transform does, but it hasn't been upstreamed yet.

Resolves TF-1141.
Copy link
Contributor

@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.

Very nice!

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - eaba367

Use regex to capture pointer alignment instead of hardcoding to 8.
Fixes iOS tests.
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - eaba367

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - eaba367

Lowered function types in LLVM differ between architectures.
Fixes test for 32-bit iOS simulator.
@dan-zheng
Copy link
Contributor Author

FileCheck tests failed for the 32-bit iOS simulator due to LLVM IR differences. The test should be amended now.

@dan-zheng
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4ea1240

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4ea1240

Differentiable Programming
~~~~~~~~~~~~~~~~~~~~~~~~~~

differentiability_witness_function
Copy link
Member

Choose a reason for hiding this comment

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

This instruction is very confusing to me (not sure if its just me though). differentiability_witness_function makes me think that this returns the witness. If this is looking up the associated differentiation function associated with a function would you be open to renaming this to something like differential?

Copy link
Contributor

Choose a reason for hiding this comment

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

This name is similar to ’witness_method’, where it returns a method from a witness. ‘differentiability_witness_function’ returns a function from a differentiability witness. “Differential” is not the technically right name and can cause confusion with the “differential” in our API. The returned function is not a differential, but a JVP/VJP (derivative) function.

I’m entirely open to renaming this to ‘derivative_function’, but I just wanted to clarify that the current name falls in line with the name ‘witness_method’.

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I thought Id looked through the rest and then came back and changed differential to derivative. Id be okay with derivative_function as well.

The thing is that function becomes a fuzzy term here. It fetches the function pointer from the witness, returning a function which implements the function which performs a derivative over a function. The way that I initially read it, it made me question whether it was getting a getter for the differentiability witness or an entry in the witness table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

derivative_function is perhaps not wholly precise, because the instruction has a [transpose] option for returning a transpose function, in addition to [jvp] and [vjp] options for returning derivative functions. I'm open to derivative_function though.

Do we have consensus on derivative_function (or some other name) as an alternative name for differentiability_witness_function? cc @rxwei @marcrasi

If not, let's merge and defer renaming until later. I'll merge within a day if no one responds.

Copy link
Contributor

@rxwei rxwei Feb 14, 2020

Choose a reason for hiding this comment

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

In the future each witness will be either a linear witness or non-linear witness, so it’s possible to define both a ‘derivative_function’ and a ‘transpose_function’.

That said, I don’t like the idea of dropping the word “witness” from this instruction. It makes it sounds like it’s differentiating or transposing something, whereas all it does is retrieve the pointer to a function in the witness.

In the future when we unify JVP and VJP into a single derivative, a differentiability witness will be equivalent to a function forward declaration, so calling it ‘differentiability_witness_function’ is quite clear. I’m supporting keeping the existing name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the future when we unify JVP and VJP into a single derivative, a differentiability witness will be equivalent to a function forward declaration, so calling it ‘differentiability_witness_function’ is quite clear.

Interesting point. I'll go ahead and merge this patch now.

@dan-zheng dan-zheng merged commit a49428c into swiftlang:master Feb 14, 2020
@dan-zheng dan-zheng deleted the autodiff-upstream branch February 14, 2020 00:55
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