[PyTorchEdge] promote prim ops by using ops table for mobile runtime#64816
[PyTorchEdge] promote prim ops by using ops table for mobile runtime#64816pavithranrao wants to merge 11 commits intogh/pavithranrao/18/basefrom
Conversation
Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 1a77cb7 (more details on the Dr. CI page):
1 failure not recognized by patterns:
🚧 1 fixed upstream failure:These were probably caused by upstream breakages that were already fixed.
Please rebase on the
|
Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! ghstack-source-id: 137753081 Pull Request resolved: #64816
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
Pull Request resolved: #64816 ghstack-source-id: 137952271 Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)!
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
Pull Request resolved: #64816 ghstack-source-id: 138035484 Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)!
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…for mobile runtime Pull Request resolved: #64816 ghstack-source-id: 138158141 Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)!
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…for mobile runtime Pull Request resolved: #64816 ghstack-source-id: 138209848 Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)!
iseeyuan
left a comment
There was a problem hiding this comment.
LGTM. Some minor inline comments.
torch/csrc/jit/mobile/function.h
Outdated
|
|
||
| #include <ATen/core/function_schema.h> | ||
| #include <ATen/core/ivalue.h> | ||
| #include <torch/csrc/jit/mobile/prim_ops_registery.h> |
There was a problem hiding this comment.
If it's only used in function.cpp, it's better to move it to the cpp file.
| std::function<void(Stack&)>& getPrimOpsFn(const std::string& name); | ||
|
|
||
| class prim_op_fn_register { | ||
| std::string prim_ops_name_; |
There was a problem hiding this comment.
Could you try to remove this quickly and see if it still works?
| mobile::prim_op_fn_register("prim::Uninitialized", unInitialized), | ||
| mobile::prim_op_fn_register("aten::to.prim_dtype", toPrimDType), | ||
| mobile::prim_op_fn_register("prim::is_cuda", isCuda) | ||
| // TODO: (@pavithran) size is overloaded with int[] and Tensor |
There was a problem hiding this comment.
It may be some legacy code. There are two operators: aten::size and aten::Size. The only difference is the cap S. You may need to look at which one need to be promoted.
…le runtime" Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)! [ghstack-poisoned]
…for mobile runtime Pull Request resolved: #64816 ## Context: Promoting prim ops: Certain prim ops are frequent than others (like tupleIndex, raiseException, ...). These ops are frequent that they are chosen to be promoted as first class instructions. To promote it requires multiple steps and support from TS team as it changes how the bytecode is serialized and deserialized. So to prevent multiple bytecode version bumps and provided stability while these changes happen, an iterim iterative process is proposed which uses a table to lookup for "promoted" op's function. This allows us to rapidly update the ops list and test on production model without having to change the bytecode. In case of failure, we can quickly revert this change. ## Observation The ops are chosen based on the notebook N1135657 which examines the top frequent ops. ## Fix An iterim solution of having a static table, which when given a prim op name returns a function to be applied on the stack. This helps us check in `function.cpp` to get the "promoted" op. As a fall back, the "promoted" op still resides in `register_prim_ops.cpp` so that the function of prim op is never missed. ghstack-source-id: 138261338 Differential Revision: [D30819926](https://our.internmc.facebook.com/intern/diff/D30819926/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D30819926/)!
|
This pull request has been merged in 3c003aa. |
Stack from ghstack:
Differential Revision: D30819926
NOTE FOR REVIEWERS: This PR has internal Facebook specific changes or comments, please review them on Phabricator!