Skip to content

[PyTorchEdge] promote prim ops by using ops table for mobile runtime#64816

Closed
pavithranrao wants to merge 11 commits intogh/pavithranrao/18/basefrom
gh/pavithranrao/18/head
Closed

[PyTorchEdge] promote prim ops by using ops table for mobile runtime#64816
pavithranrao wants to merge 11 commits intogh/pavithranrao/18/basefrom
gh/pavithranrao/18/head

Conversation

@pavithranrao
Copy link
Contributor

@pavithranrao pavithranrao commented Sep 10, 2021

Stack from ghstack:

Differential Revision: D30819926

NOTE FOR REVIEWERS: This PR has internal Facebook specific changes or comments, please review them on Phabricator!

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]
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Sep 10, 2021

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 1a77cb7 (more details on the Dr. CI page):


  • 1/2 failures introduced in this PR
  • 1/2 broken upstream at merge base ddf952b on Sep 10 from 7:19am to 8:34am

1 failure not recognized by patterns:

Job Step Action
GitHub Actions linux-xenial-py3.6-gcc5.4 / build-docs (cpp) Unknown 🔁 rerun

🚧 1 fixed upstream failure:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

If your commit is older than viable/strict, run these commands:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

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.

Click here to manually regenerate this comment.

@facebook-github-bot facebook-github-bot added cla signed oncall: jit Add this issue/PR to JIT oncall triage queue labels Sep 10, 2021
pavithranrao pushed a commit that referenced this pull request Sep 10, 2021
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]
pavithranrao pushed a commit that referenced this pull request Sep 13, 2021
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]
pavithranrao pushed a commit that referenced this pull request Sep 14, 2021
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]
pavithranrao pushed a commit that referenced this pull request Sep 15, 2021
…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]
pavithranrao pushed a commit that referenced this pull request Sep 16, 2021
…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/)!
Copy link
Contributor

@iseeyuan iseeyuan left a comment

Choose a reason for hiding this comment

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

LGTM. Some minor inline comments.


#include <ATen/core/function_schema.h>
#include <ATen/core/ivalue.h>
#include <torch/csrc/jit/mobile/prim_ops_registery.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

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_;
Copy link
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

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]
pavithranrao pushed a commit that referenced this pull request Sep 16, 2021
…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/)!
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 3c003aa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants