[jit] refactor tryMatchSchema#26499
Conversation
eellison
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Why on schema size of 1 are we not trying allow_conversions ?
There was a problem hiding this comment.
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.
| // error strings. If we discover it did error, then we replay it, recording | ||
| // the errors. | ||
| if (!render_errors) { | ||
| return matchSchemas( |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
pytorch/torch/csrc/jit/script/compiler.cpp
Line 236 in 264c438
| << "The following variants are available:\n" | ||
| << prefixLine(failure_messages.str(), " ") | ||
| << "\nThe original call is"; | ||
| throw ErrorReport(loc) << failure_messages.str(); |
| 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); |
There was a problem hiding this comment.
keep comment around ?
we inline builtin calls because they are normally very small // wrappers and are not useful for keeping around to debug
There was a problem hiding this comment.
Context: i ran into this when trying to add a builtin_functions with a loop that failed and the comment was helpful
eellison
left a comment
There was a problem hiding this comment.
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) { |
| // error strings. If we discover it did error, then we replay it, recording | ||
| // the errors. | ||
| if (!render_errors) { | ||
| return matchSchemas( |
There was a problem hiding this comment.
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:
pytorch/torch/csrc/jit/script/compiler.cpp
Line 236 in 264c438
| 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); |
There was a problem hiding this comment.
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
seems to be real |
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
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
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
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
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
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
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
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
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
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
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