Skip to content

[AutoDiff] Introduce 'linear_function' and 'linear_function_extract' instructions. #27637

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 25 commits into from
Oct 15, 2019

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented Oct 12, 2019

Introduce linear_function and linear_function_extract instructions, which are used for creating and destructing @differentiable(linear) functions.

linear_function instruction

Bundles a function with its transpose function into a @differentiable(linear) function.

sil-instruction ::= 'linear_function'
                    sil-linear-function-parameter-indices?
                    sil-value ':' sil-type
                    sil-linear-function-transpose-function-clause?

sil-linear-function-parameter-indices ::=
    '[' 'parameters' [0-9]+ (' ' [0-9]+)* ']'
sil-linear-transpose-function-clause ::=
    with_transpose sil-value ':' sil-type

linear_function_extract instruction

Extracts the original function or a transpose function from the given @differentiable(linear) function. It must be provided with an extractee: [original] or [transpose].

sil-instruction ::= 'linear_function_extract'
                    sil-linear-function-extractee
                    sil-value ':' sil-type

sil-linear-function-extractee ::=
    '[' sil-linear-function-extractee ']'
sil-linear-function-extractee-name ::= 'original' | 'transpose'

linear_function_extract [original] %0 : $@differentiable(linear) (T) -> T
linear_function_extract [transpose] %0 : $@differentiable(linear) (T) -> T

Resolves TF-907.

@rxwei rxwei added the tensorflow This is for "tensorflow" branch PRs. label Oct 12, 2019
@rxwei rxwei requested a review from dan-zheng October 12, 2019 01:11
Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

LGTM!

Please add round-trip tests (parsing, (de)serialization, printing) à la differentiable_function_inst.sil.

@@ -7845,7 +7845,7 @@ class TryApplyInst final
};

// SWIFT_ENABLE_TENSORFLOW
/// `differentiable_function` - given a function and differentiation indices and
/// `differentiable_function` - given a function, differentiation indices and
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Oxford comma please (used below for linear_function) 🙂

Suggested change
/// `differentiable_function` - given a function, differentiation indices and
/// `differentiable_function` - given a function, differentiation indices, and

@rxwei
Copy link
Contributor Author

rxwei commented Oct 12, 2019

As mentioned in the PR description, this PR is work in progress.

@rxwei
Copy link
Contributor Author

rxwei commented Oct 12, 2019

There turns out to be a large portion of @differentiable(linear) type lowering that's not handled at all. I'll deal with that first.

@rxwei
Copy link
Contributor Author

rxwei commented Oct 14, 2019

Ok, everything is working now after various fixes in parsing and lowering. I will split this patch into multiple.

@rxwei rxwei marked this pull request as ready for review October 14, 2019 01:56
@rxwei rxwei force-pushed the linear-function-inst branch from b4ba4ff to 5af2b01 Compare October 15, 2019 00:20
@rxwei rxwei changed the title [AutoDiff] Introduce 'linear_function' instruction. [AutoDiff] Introduce 'linear_function' and 'linear_function_extract' instructions. Oct 15, 2019
@rxwei
Copy link
Contributor Author

rxwei commented Oct 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Oct 15, 2019

@swift-ci please test tensorflow

2 similar comments
@rxwei
Copy link
Contributor Author

rxwei commented Oct 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor Author

rxwei commented Oct 15, 2019

@swift-ci please test tensorflow

@rxwei rxwei self-assigned this Oct 15, 2019
@rxwei rxwei merged commit 740b63e into swiftlang:tensorflow Oct 15, 2019
@rxwei rxwei deleted the linear-function-inst branch October 15, 2019 03:50
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.

2 participants