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

Extended graph lowering to use the stateless if/while ops when the if true/else body or while body funcs do not have stateful ops. #18509

Merged
merged 4 commits into from
Aug 10, 2018

Conversation

mhong
Copy link
Contributor

@mhong mhong commented Aug 4, 2018

This is a potential performance optimization, where stateless ops can be pruned
away if TF-level graph compiler (e.g. grappler) can prove doing so is safe.

Updated TF repo commit hash to incorporate the new stateless if/while ops: tensorflow/tensorflow@8453e23.

@mhong
Copy link
Contributor Author

mhong commented Aug 4, 2018

This PR can only be tested after the TF level code change is submitted, for adding the stateless op/while ops. I will add reviewers after that.

@@ -3131,7 +3133,10 @@ TFGraphFunctionLowering::lowerConditionalRegion(ConditionalSESERegion *r) {
// .Attr("Tin: list(type) >= 0")
// .Attr("Tout: list(type) >= 0")
auto opLocString = getUniqueName(loc, "op");
auto *op = TF_NewOperation(graphFn.getGraph(), "If", opLocString.c_str());
bool usesideEffectingIf = trueFnHasSideEffects || falseFnHasSideEffects;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: camelcase useSideEffectingIf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

tensorflow-copybara pushed a commit to tensorflow/tensorflow that referenced this pull request Aug 9, 2018
… be used,

when the if then/else body of If or the While body funcs do not have stateful
ops.

The are lowered to the same XLA ops.

One use case is in the S4TF compiler: swiftlang/swift#18509

PiperOrigin-RevId: 207977126
Mingsheng Hong added 4 commits August 9, 2018 10:45
… true/else

body or while body funcs do not have stateful ops.

This is a potential performance optimization, where stateless ops can be pruned
away if TF-level graph compiler (e.g. grappler) can prove doing so is safe.
@mhong
Copy link
Contributor Author

mhong commented Aug 9, 2018

@swift-ci please test tensorflow

@mhong mhong changed the title [WIP] Extended graph lowering to use the stateless if/while ops when the if true/else body or while body funcs do not have stateful ops. Extended graph lowering to use the stateless if/while ops when the if true/else body or while body funcs do not have stateful ops. Aug 9, 2018
@mhong
Copy link
Contributor Author

mhong commented Aug 9, 2018

This PR is now ready for review.

@@ -3167,7 +3169,10 @@ TFGraphFunctionLowering::lowerConditionalRegion(ConditionalSESERegion *r) {
// .Attr("Tin: list(type) >= 0")
// .Attr("Tout: list(type) >= 0")
auto opLocString = getUniqueName(loc, "op");
auto *op = TF_NewOperation(graphFn.getGraph(), "If", opLocString.c_str());
bool useSideEffectingIf = trueFnHasSideEffects || falseFnHasSideEffects;
Copy link
Contributor

Choose a reason for hiding this comment

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

Both trueFnHasSideEffects and falseFnHasSideEffects are hard-coded false above. What would happen if there's a side-effecting operation in the body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are output params of buildGraphFunction(). Does that clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, there are test cases that generate (the stateful) "If" and "While" ops

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying.

@mhong
Copy link
Contributor Author

mhong commented Aug 9, 2018

Copy link
Contributor

@lattner lattner left a comment

Choose a reason for hiding this comment

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

Makes sense. Does TF have an internal (e.g. Grappler) optimizations for While/If that have to be extended for the new stateless forms?

@mhong
Copy link
Contributor Author

mhong commented Aug 10, 2018

I'm not aware of specific optimizations targeting If/While, but in general Grappler can optimize stateless ops more (e.g. can prune away stateless ops when we run a graph function that produce no return values). So using these new stateless versions of the ops could trigger such optimization.

@mhong
Copy link
Contributor Author

mhong commented Aug 10, 2018

Thanks all for the review!

@mhong mhong merged commit 061eb5c into swiftlang:tensorflow Aug 10, 2018
@mhong mhong deleted the stateless_if_while branch August 10, 2018 16:28
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.

None yet

4 participants