-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Centralize setting messageId in RequestCallback #57848
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
Conversation
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit d564aa9 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
| Job | Step | Action |
|---|---|---|
| Build | 🔁 rerun |
This comment was automatically generated by Dr. CI (expand for details).
Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group.
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
| return future; | ||
| } catch (std::exception& e) { | ||
| return asFuture(handleError(e, messageType, messageId)); | ||
| // Pass a dummy message ID since it will be overwritten anyways. |
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.
should we remove message id from handleError argument list?
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 feel free to do this in followup PRs.
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.
My long-term idea is to remove the ID entirely from Message. I believe the ID is only used by the RPC agent to match requests with responses, so in a sense it's an "external" information (it shouldn't be inside the Message, it should be a "tag" that's attached to it).
| message->setId(id); | ||
| return message; | ||
| }, | ||
| c10::getCustomClassType<c10::intrusive_ptr<Message>>()); |
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.
IIUC, this does some type conversion + map lookup + branching. I wonder if it make sense to keel this c10::ClassTypePtr in Message implementation and reuse it in other places?
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 wouldn't worry about performance here. It's true that we need to do a map lookup and some bookkeeping, but only the first time, as the result is then cached for subsequent uses. See the static local variable here
pytorch/aten/src/ATen/core/ivalue.h
Lines 1161 to 1169 in df44f01
| template <typename T> | |
| const c10::ClassTypePtr& getCustomClassType() { | |
| // Classes are never unregistered from getCustomClassTypeMap and the | |
| // hash lookup can be a hot path, so just cache. | |
| // For the same reason, it's fine If this ends up getting duplicated across | |
| // DSO boundaries for whatever reason. | |
| static c10::ClassTypePtr cache = getCustomClassTypeImpl<T>(); | |
| return cache; | |
| } |
Moreover, since that function is templated, the type will be resolved at compile time. Hence a reasonable compiler will inline that code and this callsite will basically just become one memory access (plus a check if the cache has been initialized).
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.
LGTM
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/) [ghstack-poisoned]
Pull Request resolved: pytorch#57848 This PR looks large, but all it does is add a dozen lines and remove a lot of other ones. One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic. ghstack-source-id: 129567065 Differential Revision: [D28224477](https://our.internmc.facebook.com/intern/diff/D28224477/)
|
This pull request has been merged in 4ac18f6. |
Stack from ghstack:
This PR looks large, but all it does is add a dozen lines and remove a lot of other ones.
One first advantage of using Futures is that we can easily chain some "post-processing" to them. Until now we needed to pass the message ID around everywhere because it was set separately by each method. Instead, we could simply add a follow-up step to the final future which sets this ID, and remove all the former logic.
Differential Revision: D28224477