Skip to content

Conversation

@eellison
Copy link
Contributor

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

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Dec 13, 2018
Copy link
Member

Choose a reason for hiding this comment

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

Why a copy?

Copy link
Member

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.

Copy link
Member

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?

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 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

Copy link
Member

@suo suo Dec 14, 2018

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

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

maybe static constexpr?

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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 * ?

Copy link
Member

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.

Copy link
Member

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.

@eellison eellison force-pushed the improve_unknown_bulitin_function_error branch from bde3723 to 31c9ae8 Compare December 19, 2018 21:22
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

@suo suo left a comment

Choose a reason for hiding this comment

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

remember to format :)

Copy link
Member

Choose a reason for hiding this comment

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

formatting

Copy link
Member

Choose a reason for hiding this comment

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

this comment appears outdated

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

const

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

what's this for?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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

@eellison eellison force-pushed the improve_unknown_bulitin_function_error branch from 488e87d to 413cba6 Compare December 28, 2018 20:21
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

mrshenli pushed a commit to mrshenli/pytorch that referenced this pull request Jan 6, 2019
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
@ezyang ezyang added the merged label Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants