Skip to content

[AutoDiff] Be able to parse linear argument in @differentiating attribute #25257

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

Conversation

bartchr808
Copy link
Contributor

@bartchr808 bartchr808 commented Jun 5, 2019

This PR is following this one about @differentiable(linear).

One thing to note in my tests is how I consider the linear argument. @differentiating(linear) should be allowed as a user may create a function called linear, so there are 2 scenarios a user can be in:

  1. @differentiating(linear) -> Differentiating a function called linear.
  2. @differentiating(linear, linear) -> Differentiating a linear function called linear

Also, we previously weren't handling the case of trailing commas in the @differentiating attribute, so I made sure we were this time and also added corresponding tests.

@bartchr808 bartchr808 added the tensorflow This is for "tensorflow" branch PRs. label Jun 5, 2019
@bartchr808 bartchr808 requested review from rxwei and dan-zheng June 5, 2019 06:27
@@ -829,12 +829,12 @@ ParserResult<DifferentiableAttr>
Parser::parseDifferentiableAttribute(SourceLoc atLoc, SourceLoc loc) {
StringRef AttrName = "differentiable";
SourceLoc lParenLoc = loc, rParenLoc = loc;


bool linear;
Copy link
Contributor Author

@bartchr808 bartchr808 Jun 5, 2019

Choose a reason for hiding this comment

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

Small update I wanted to do from last PR. Since linear is first argument in @differentiable, I also wanted it to be the first one declared.

@@ -1504,6 +1504,8 @@ ERROR(attr_differentiable_expected_label,none,
// differentiating
ERROR(attr_differentiating_expected_original_name,PointsToFirstBadToken,
"expected an original function name", ())
ERROR(attr_differentiating_expected_linear_wrt,none,
"expected either 'linear' or 'wrt:'", ())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"expected either 'linear' or 'wrt:'", ())
ERROR(attr_differentiating_expected_label_linear_or_wrt,none,
"expected either 'linear' or 'wrt:'", ())

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe this suggestion was applied before the code was merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I thought this was a name change of the variable. Before it was attr_differentiating_expected_linear_wrt but now I changed it to attr_differentiating_expected_label_linear_or_wrt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also about the indentation of the second line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops will fix this in the new PR misinterpreted the suggestion


// expected-error @+2 {{expected ')' in 'differentiating' attribute}}
// expected-error @+1 {{expected declaration}}
@differentiating(foo, wrt: x,)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a @differentiating(foo, wrt: x, linear) test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes thanks for catching this test case! Will add it tomorrow morning 😴😄

@bartchr808
Copy link
Contributor Author

@swift-ci please test tensorflow

@bartchr808 bartchr808 changed the title [AutoDiff] [Forward Mode] Be able to parse linear argument in @differentiating attribute [AutoDiff] Be able to parse linear argument in @differentiating attribute Jun 5, 2019
@bartchr808 bartchr808 merged commit cec88da into swiftlang:tensorflow Jun 5, 2019
@bartchr808 bartchr808 deleted the differentiating-linear-attr branch June 5, 2019 20:14
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.

3 participants