-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Print out operator suggestions for unknown builtin op #15183
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
Print out operator suggestions for unknown builtin op #15183
Conversation
torch/csrc/jit/operator.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, getAllOperators() makes me think that whatever you're going to do once you've gotten them all should probably just be a method on OperatorRegistry…since that's the thing we have that represents the set of all operators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we implement this with SmallVector as discussed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could... I think part of the reason of using an existing implementation is to avoid the cognitive overhead of rethinking & retesting it. The more you change the implementation the less that applies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that you should be rethinking and retesting code that you are copying from elsewhere. Like, maybe for a templated mess like optional it's not worth, but this function isn't so complicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow fb standards:
- capitalize "compute"
- Move the impl to a cpp file. The current way you're doing it will create ODR violations if we try to include this file from multiple TUs.
torch/csrc/jit/script/compiler.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe static constexpr?
torch/csrc/jit/script/compiler.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: split this into multiple lines
torch/csrc/jit/script/compiler.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: close_operators.begin()->first seems more readable
torch/csrc/jit/script/compiler.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying every operator name is unnecessary. if computeEditDistance took an ArrayRef or const chart * you can avoid it entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's being passed as a const std::string reference. How is that different than const char * ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copy is made in the line I indicated, when you invoke the copy constructor of std::string.
const auto would have copied the const char *, which is just a pointer that you could then pass to computeEditDistance without a copy.
torch/csrc/jit/script/compiler.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need select and rank the operators in two different functions. Why can't there be a single function that returns the n closest ops? Doing that with a priority queue with the comparator being edit distance is a more explicit way to accomplish what you're doing here.
bde3723 to
31c9ae8
Compare
torch/csrc/jit/operator.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why std::multimap over std::vector? It looks like the keys aren't actually used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that it prints out the closer suggestions first
suo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember to format :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
torch/csrc/jit/operator.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment appears outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of these should be const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're passing around a very complicated data structure (std::multimap<int64_t, std::pair<Symbol, std::vector<std::shared_ptr<Operator>>>) when you only need std::vector<Symbol>. I don't think it's good to spill the guts of your implementation out like that.
If you want to return them in order, just use a std::priority_queue to maintain ordering and return the underlying container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a type conversion from (int a, int b, int c) -> []int. Just as the other type conversions, it should only be run on the second pass when allow_conversions is true. I think you have an issue raised about this logic IIRC.
I ran into a bug bc of it when testing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! Can you add a test that checks this to avoid regression in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm i think the error actually was in a different PR, the torch.tensor one and accidentally made it's way in here. Removing from this PR and adding a test in that one
…ic into operator.cpp
488e87d to
413cba6
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eellison is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eellison is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: This improves the error message for "unknown builtin op" to suggest similarly named ops. Currently it prints out all operators with a name within two edits. Related issue: pytorch#13409 Pull Request resolved: pytorch#15183 Differential Revision: D13578509 Pulled By: eellison fbshipit-source-id: 5c73408eda1f7aa456f5bd28790c34df0c76aeca
This improves the error message for "unknown builtin op" to suggest similarly named ops.
Currently it prints out all operators with a name within two edits.
Related issue: #13409