Propagate and report the file/line number of registrations on errors.#36264
Propagate and report the file/line number of registrations on errors.#36264ezyang wants to merge 16 commits intogh/ezyang/712/basefrom
Conversation
Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
💊 Build failures summary and remediationsAs of commit 32dff1e (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following build failures do not appear to be due to upstream breakages:
|
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: a5aa0dd Pull Request resolved: #36264
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 702bf0d Pull Request resolved: #36264
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 05456fd Pull Request resolved: #36264
| if (ns_.has_value()) name.setNamespaceIfNotSet(ns_->c_str()); | ||
| TORCH_CHECK(!(f.dispatch_key_.has_value() && dispatch_key_.has_value()), "Cannot specify a different dispatch key inside a TORCH_LIBRARY_IMPL; please declare a separate TORCH_LIBRARY_IMPL for your dispatch key"); | ||
| if (ns_.has_value()) { | ||
| TORCH_CHECK(name.setNamespaceIfNotSet(ns_->c_str()), "Attempted to impl ", toString(name), " which is explicitly qualified with a namespace inside a TORCH_LIBRARY, which is not allowed. If TORCH_LIBRARY's namespace matches the explicitly given namespace, remove the qualifier; otherwise, please place it in an separate TORCH_LIBRARY_IMPL block to make it clear that you are overriding behavior for an operator in a different library. Registration site was ", file_, ":", line_); |
There was a problem hiding this comment.
WDYT about wrapping these messages? I guess the idea is to keep them out of the way of the code, but they can be informative and the side scrolling gets pretty crazy. YMMV I guess.
There was a problem hiding this comment.
At this point it will be kind of annoying to adjust the formatting in the stack diff because of merge conflicts. I could do this after though.
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
| listeners_->callOnOperatorRegistered(op); | ||
| } else { | ||
| checkSchemaCompatibility(op, schema); | ||
| checkSchemaCompatibility(op, schema, debug); |
There was a problem hiding this comment.
nit: I'd probably also add the std::move here. It doesn't change anything because the checkSchemaCompatibility function takes a reference, but that's not immediately visible at the call site, so the call site is easier to check for consistent std::move usage if we just add it everywhere where it is valid. That also future-proofs in case checkSchemaCompatibility decides to take it by value later.
There was a problem hiding this comment.
This doesn't make sense to me. Semantically, it doesn't make any sense for schema compatibility to take ownership of the schema. It is after all just going to read the schema, not store it anywhere. Isn't adding a std::move here "just because" it's the terminal use obscuring the semantic meaning of the code here?
| } | ||
|
|
||
| RegistrationHandleRAII Dispatcher::registerFallback(DispatchKey dispatchKey, KernelFunction kernel) { | ||
| RegistrationHandleRAII Dispatcher::registerFallback(DispatchKey dispatchKey, KernelFunction kernel, std::string debug) { |
There was a problem hiding this comment.
you're not using debug here, right? In that case, you could also make it a const&.
General recommendation: If a function takes an argument by value or by const& should not depend on the call site but only on if the function internally takes ownership (e.g. moves the value further) or not. The API contract (i.e. what the call site needs to know) for by-value and const& is the same, it's just a compiler optimization. Both calling conventions look the same at the call site, so by reading you cannot distinguish them. That means the call site should ignore if the function takes an argument by value or as const& and just std::move it in whenever that is valid (and the type is large enough so moving in general makes sense).
There was a problem hiding this comment.
This one should morally take it by move; the problem is I'm not actually saving debug information for fallbacks (but I should!) There's a more generic problem which should get fixed at some point, which is we're not doing adequate error checking for fallbacks, c.f. this existing comment:
RegistrationHandleRAII Dispatcher::registerFallback(DispatchKey dispatchKey, KernelFunction kernel, std::string debug) {
// TODO: fallbacks clobber each other completely unsafely, unlike regular
// kernels
| OperatorName name_; | ||
| c10::optional<FunctionSchema> schema_; | ||
| c10::optional<std::string> debug_; | ||
| // INVARIANT: schema_.has_value() == debug_.has_value() |
There was a problem hiding this comment.
should we explicitly model this instead by having a c10::optional<SchemaInfo> with
struct SchemaInfo final {
FunctionSchema schema;
std::string debug;
}
That would make the invariant be enforced by the compiler instead of having to rely on the comment here.
There was a problem hiding this comment.
I considered it, but adding another struct seemed annoying. Up to you.
|
|
||
| void setNamespaceIfNotSet(const char* ns) { | ||
| name_.setNamespaceIfNotSet(ns); | ||
| bool setNamespaceIfNotSet(const char* ns) { |
There was a problem hiding this comment.
nit: comment on when this returns true/false. Or even better, make it return an enum with two possible (and descriptive) values.
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
… on errors." Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D20929260](https://our.internmc.facebook.com/intern/diff/D20929260) [ghstack-poisoned]
Pretty simple 1-2 PR: - Start recording the passed in __FILE__ and __LINE__ from the new API in Library, and propagate it to the existing debug strings - Extend OperatorEntry to record a debug string corresponding to where the schema came from - Print out these newly recorded debug strings wherever possible Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 61e4f5f Pull Request resolved: pytorch#36264
|
Folded into #36258 |
Stack from ghstack:
Pretty simple 1-2 PR:
new API in Library, and propagate it to the existing debug
strings
to where the schema came from
Signed-off-by: Edward Z. Yang ezyang@fb.com
Differential Revision: D20929260