Adding support for inlining if branches#10084
Adding support for inlining if branches#10084eellison wants to merge 4 commits intopytorch:masterfrom
Conversation
|
@pytorchbot retest this please |
1 similar comment
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
1 similar comment
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
zdevito
left a comment
There was a problem hiding this comment.
I have some questions about how the recomputeMutatedVariables works inline. I think it can be made significantly simpler.
| }; | ||
|
|
||
| for (Node *orig : body->nodes()) { | ||
| Node *clone = graph->insertNode(graph->createClone(orig, get_value)); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| return maybe_value && *maybe_value; | ||
| } | ||
|
|
||
| void lowerIf(Node *n) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| } | ||
|
|
||
| //returns true if the mutated variables are changed | ||
| bool recomputeMutatedVariables(Node *n) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| auto initial_outputs = true_block->outputs().size(); | ||
| for (size_t i = 0; i < true_block->outputs().size();) { | ||
| //neither block mutates output i | ||
| if (!mutated_variables.count(true_block->outputs()[i]) && |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| if (constant_inputs) { | ||
| lowerIf(n); | ||
| } else if (changed) { | ||
| changed = recomputeMutatedVariables(n); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
ae421d1 to
ac365bb
Compare
…ing which mutated variables are returned
ac365bb to
2d854fb
Compare
|
@pytorchbot retest this please |
4 similar comments
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
2d854fb to
55bf9a4
Compare
|
@pytorchbot retest this please |
1 similar comment
|
@pytorchbot retest this please |
zdevito
left a comment
There was a problem hiding this comment.
This looks good now. One minor thing about cleaning up prim::Loop loop-carried dependencies, but the patch is still correct without it and can be merged.
| if (constant_inputs) { | ||
| inlineIf(n); | ||
| } else { | ||
| removeExtraNodeOutputs(n); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
| WithInsertPoint guard(n); | ||
| for (size_t i = 0; i < outputs.size(); ++i) { | ||
| auto new_output = graph->insertConstant(outputs[i]); | ||
| auto new_output = insertConstant(*graph, outputs[i]); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| bool isTrueConstant(Value *val) { | ||
| at::optional<bool> maybe_value = constant_as<bool>(val); | ||
| return maybe_value && *maybe_value; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@pytorchbot retest this please |
|
@pytorchbot retest this please |
1 similar comment
|
@pytorchbot retest this please |
facebook-github-bot
left a comment
There was a problem hiding this comment.
eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Inlining if branches which have constant inputs. If an if node gets inlined, the set of mutated variables returned by its ancestors may have changed. In the following example the block should
return a mutated set of (a) and not (a, b).
To calculate this we recursively update mutate variables in if branches from the leaf nodes up.