Skip to content

[jit] refactor tryMatchSchema#26499

Closed
zdevito wants to merge 12 commits intogh/zdevito/112/basefrom
gh/zdevito/112/head
Closed

[jit] refactor tryMatchSchema#26499
zdevito wants to merge 12 commits intogh/zdevito/112/basefrom
gh/zdevito/112/head

Conversation

@zdevito
Copy link
Contributor

@zdevito zdevito commented Sep 19, 2019

Stack from ghstack:

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

  • tryMatchSchemas was added since the overload logic got copy/pasted
    into three separate locations.

  • With this change, tryMatchSchema is no longer public, as it is not needed
    outside of tryMatchSchemas

  • emitBuiltinFunction no longer needs a requires argument (it was always true)

  • Argument order for all the schema matching stuff now puts the 'self'
    builtin override last. This is only rarely used and was inconsistent with
    matchSchema

  • Removed OverloadedFunctionValue and OverloadedMethodValue, this functionality was folded into FunctionValue and MethodValue to keep the number of sugared values low.

Differential Revision: D17488297

@zdevito zdevito requested a review from apaszke as a code owner September 19, 2019 21:49
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: pybind Related to our Python bindings / interactions with other Python libraries labels Sep 19, 2019
@zdevito zdevito requested a review from eellison September 19, 2019 21:51
Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks great!! Pasta be gone 🚫 🍝

I have a couple comments / questions

const c10::optional<NamedValue>& self,
bool render_errors) {
TORCH_INTERNAL_ASSERT(schemas.size() > 0);
if (schemas.size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why on schema size of 1 are we not trying allow_conversions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

matchSchema does do conversions. This is avoiding the duplicate work of first trying without conversions, which is only done when there is multiple schema in order to prioritize non-converting matches first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add comment

// error strings. If we discover it did error, then we replay it, recording
// the errors.
if (!render_errors) {
return matchSchemas(
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 understand this - if we have reached this point in the code, none of the schemas match, can't we just throw the error ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We start with render_errors=false, optimistically assuming that we will succeed and not spending time doing error message formatting for an overload that won't happen. If we reach here we know there will be an error, but we have not rendered the error messages, so we replay the match to render the errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is just to cut down on compile time. It would be nice to hide the render_errors argument from the api since any invocation outside of this file shouldn't need to know about this.

Related: we ran into a compile - slow down in compiler.cpp with eagerly concatenating strings and it was solved by buffering up the concatenation with lambdas:

auto runner = this;

<< "The following variants are available:\n"
<< prefixLine(failure_messages.str(), " ")
<< "\nThe original call is";
throw ErrorReport(loc) << failure_messages.str();
Copy link
Contributor

Choose a reason for hiding this comment

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

unreachable code

return emitBuiltinNode(matched.second, loc, graph, name);
} else {
Function* fn = builtin_functions[matched.first - variants.size()];
return insertGraph(graph, *fn->graph(), matched.second.inputs).at(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

keep comment around ?

we inline builtin calls because they are normally very small // wrappers and are not useful for keeping around to debug

Copy link
Contributor

Choose a reason for hiding this comment

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

Context: i ran into this when trying to add a builtin_functions with a loop that failed and the comment was helpful

Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks good. I think we should probably hide the render_errors arg with an impl pattern or something

const c10::optional<NamedValue>& self,
bool render_errors) {
TORCH_INTERNAL_ASSERT(schemas.size() > 0);
if (schemas.size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add comment

// error strings. If we discover it did error, then we replay it, recording
// the errors.
if (!render_errors) {
return matchSchemas(
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is just to cut down on compile time. It would be nice to hide the render_errors argument from the api since any invocation outside of this file shouldn't need to know about this.

Related: we ran into a compile - slow down in compiler.cpp with eagerly concatenating strings and it was solved by buffering up the concatenation with lambdas:

auto runner = this;

return emitBuiltinNode(matched.second, loc, graph, name);
} else {
Function* fn = builtin_functions[matched.first - variants.size()];
return insertGraph(graph, *fn->graph(), matched.second.inputs).at(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Context: i ran into this when trying to add a builtin_functions with a loop that failed and the comment was helpful

[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
[jit] refactor tryMatchSchema

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 26499 gh/zdevito/112/head
@facebook-github-bot
Copy link
Contributor

@zdevito merged this pull request in 51656ee.

@ezyang
Copy link
Contributor

ezyang commented Oct 11, 2019

Oct 10 07:42:45 test_interface (__main__.TestClassType) ... terminate called after throwing an instance of 'std::runtime_error'
Oct 10 07:42:45   what():  pybind11_object_dealloc(): Tried to deallocate unregistered instance!
Oct 10 07:42:45 Traceback (most recent call last):
Oct 10 07:42:45   File "test/run_test.py", line 458, in <module>
Oct 10 07:42:45     main()
Oct 10 07:42:45   File "test/run_test.py", line 450, in main
Oct 10 07:42:45     raise RuntimeError(message)
Oct 10 07:42:45 RuntimeError: test_jit failed! Received signal: SIGIOT

seems to be real

@ezyang
Copy link
Contributor

ezyang commented Oct 11, 2019

zdevito added a commit that referenced this pull request Oct 11, 2019
We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema
zdevito added a commit that referenced this pull request Oct 11, 2019
We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 27725 gh/zdevito/123/head
zdevito added a commit that referenced this pull request Oct 11, 2019
We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema
zdevito added a commit that referenced this pull request Oct 11, 2019
refactor tryMatchSchema (#26499)

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 27773 gh/zdevito/125/head
zdevito added a commit that referenced this pull request Oct 11, 2019
refactor tryMatchSchema (#26499)

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 27773 gh/zdevito/125/head
zdevito added a commit that referenced this pull request Oct 14, 2019
refactor tryMatchSchema (#26499)

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 27773 gh/zdevito/125/head
zdevito added a commit that referenced this pull request Oct 14, 2019
refactor tryMatchSchema (#26499)

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

gh-metadata: pytorch pytorch 27773 gh/zdevito/125/head
facebook-github-bot pushed a commit that referenced this pull request Oct 15, 2019
Summary:
Pull Request resolved: #27773

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

Test Plan: Imported from OSS

Differential Revision: D17885425

Pulled By: zdevito

fbshipit-source-id: 064bc9fa4bd57b2e5366fff9f3c6ab9b9945e08b
@facebook-github-bot facebook-github-bot deleted the gh/zdevito/112/head branch October 28, 2019 22:23
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary:
Pull Request resolved: pytorch#26499

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

Test Plan: Imported from OSS

Differential Revision: D17488297

Pulled By: zdevito

fbshipit-source-id: a32d838ce35544972fa8767557acc22149081b55
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary:
Pull Request resolved: pytorch#27773

We've changed how these functions are used over time, so I cleaned up
the header file API to match. In particular:

* tryMatchSchemas was added since the overload logic got copy/pasted
into three separate locations.
* With this change, tryMatchSchema is no longer public, as it is not needed
  outside of tryMatchSchemas
* emitBuiltinFunction no longer needs a requires argument (it was always true)

* Argument order for all the schema matching stuff now puts the 'self'
builtin override last. This is only rarely used and was inconsistent with
matchSchema

Test Plan: Imported from OSS

Differential Revision: D17885425

Pulled By: zdevito

fbshipit-source-id: 064bc9fa4bd57b2e5366fff9f3c6ab9b9945e08b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: pybind Related to our Python bindings / interactions with other Python libraries oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants