-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Operator developer guidance #72470
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
Operator developer guidance #72470
Conversation
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) [ghstack-poisoned]
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit cccc60d (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:
|
CI Flow Status⚛️ CI FlowRuleset - Version:
|
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) [ghstack-poisoned]
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) [ghstack-poisoned]
Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 148565616 Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/)
raziel
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.
I think this needs a bit more refinement.
Try to read it as if you knew nothing... or better as if it was code and by following every step you would actually end up with a proper upgrader PR.
| @@ -0,0 +1,95 @@ | |||
| # Guidance for Operator Developer | |||
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 should have an intro on what the base concepts are: operator upgrader, BC and BC breaking, ...
Keep it short and simple.
You may already have something in the design review.
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.
Added
|
|
||
| 2. Make changes to the operator and write an upgrader. | ||
| 1. Make the operator change. | ||
| 2. Write an upgrader in `caffe2/torch/csrc/jit/operator_upgraders/upgraders_entry.cpp` file inside a map `kUpgradersEntryMap`. The softly enforced naming format is `<operator_name>_<operator_overload>_<start>_<end>`. For example, the below example means that `linspace.out `and` linspace` at versions from 0 to 7 need to be replaced by these upgraders. |
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.
will this render ok?
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.
Resolve
| The steps to write upgrader: | ||
|
|
||
| 1. Prepare a model before making changes to the operator, following the process: | ||
| 1. add a module in `test/jit/fixtures_srcs/fixtures_src.py`. The reason why switching to commit is that, an old model with the old operator before the change is needed to ensure the upgrader is working as expected. In `test/jit/fixtures_srcs/generate_models.py`, add the module and its corresponding changed operator like following |
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.
| 1. add a module in `test/jit/fixtures_srcs/fixtures_src.py`. The reason why switching to commit is that, an old model with the old operator before the change is needed to ensure the upgrader is working as expected. In `test/jit/fixtures_srcs/generate_models.py`, add the module and its corresponding changed operator like following | |
| 1. Add a module in `test/jit/fixtures_srcs/fixtures_src.py`. The reason why switching to commit is that an old model with the old operator before the change is needed to ensure the upgrader is working as expected. In `test/jit/fixtures_srcs/generate_models.py`, add the module and its corresponding changed operator like following |
| The steps to write upgrader: | ||
|
|
||
| 1. Prepare a model before making changes to the operator, following the process: | ||
| 1. add a module in `test/jit/fixtures_srcs/fixtures_src.py`. The reason why switching to commit is that, an old model with the old operator before the change is needed to ensure the upgrader is working as expected. In `test/jit/fixtures_srcs/generate_models.py`, add the module and its corresponding changed operator like following |
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 does this mean?
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.
Add more explanation and hope it's clearer.
| python test/jit/fixtures_src/generate_models.py | ||
| ``` | ||
|
|
||
| 3. Commit the change and submit a pr |
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.
| 3. Commit the change and submit a pr | |
| 3. Commit the change and submit a pull request. |
|
|
||
| The steps to write upgrader: | ||
|
|
||
| 1. Prepare a model before making changes to the operator, following the process: |
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.
Here you mean a test model, right?
Otherwise it's not clear what this model is mean to do or why. Please briefly explain.
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.
Add the reason why a test model is needed.
| "aten::linspace(Scalar start, Scalar end, int? steps=None, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor"}}}, | ||
| ``` | ||
|
|
||
| 4. After rebuild PyTorch, run the following command and it will auto generate a change to `caffe2/torch/csrc/jit/mobile/upgrader_mobile.cpp`. After rebuild PyTorch from source (`python setup.py`), run |
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.
| 4. After rebuild PyTorch, run the following command and it will auto generate a change to `caffe2/torch/csrc/jit/mobile/upgrader_mobile.cpp`. After rebuild PyTorch from source (`python setup.py`), run | |
| 4. After rebuilding PyTorch, run the following command to auto generate a change to `caffe2/torch/csrc/jit/mobile/upgrader_mobile.cpp`. After rebuild PyTorch from source (`python setup.py`), run |
This needs to be clearer: "auto generate a change" <--- a change that does what
We should have a step before that explicitly indicates and describes how to rebuild pytorch (or links to a page that describes that).
Also, this reads as if you have to rebuild pytorch twice.
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.
- "auto generate a change to upgrader_mobile.cpp" -> "auto update the file upgrader_mobile.cpp"
- Add the link to build pytorch
- Add the first time to build in step 1
| python pytorch/tools/codegen/operator_versions/gen_mobile_upgraders.py | ||
| ``` | ||
|
|
||
| 5. Add test: |
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.
Is this a test or tests?
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 was tests..now it's a test
| --- | ||
| **NOTE** | ||
|
|
||
| Adding default arguments is not BC breaking and it doesn't requirement. For example, the following change is not BC breaking, and doesn't require upgrader: |
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.
| Adding default arguments is not BC breaking and it doesn't requirement. For example, the following change is not BC breaking, and doesn't require upgrader: | |
| Adding arguments with a default value to an operator is not BC breaking, and thus does not require upgrader. For example, the following change to operator `foo` is backwards compatible: |
|
|
||
| 2. Make changes to the operator and write an upgrader. | ||
| 1. Make the operator change. | ||
| 2. Write an upgrader in `caffe2/torch/csrc/jit/operator_upgraders/upgraders_entry.cpp` file inside a map `kUpgradersEntryMap`. The softly enforced naming format is `<operator_name>_<operator_overload>_<start>_<end>`. For example, the below example means that `linspace.out `and` linspace` at versions from 0 to 7 need to be replaced by these upgraders. |
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 we should explain what version is? Because for general public, it is not very clear
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.
Add more explanation.
| } | ||
| ``` | ||
|
|
||
| 2. Bump the `kProducedFileFormatVersion` by 1 and provide the reasons under `caffe2/caffe2/versions.h ` |
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 think you also need to bump kMaxProducedFileFormatVersion
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.
Resolve
| constexpr uint64_t kProducedFileFormatVersion = 0x9L; | ||
| ``` | ||
|
|
||
| 3. In `caffe2/torch/csrc/jit/operator_upgraders/version_map.cpp`, add changes like below. You will need to make sure that the entry is **SORTED** according to the version bump number. |
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 mention how the below example is formatted according to what we describe here
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.
Added an example to explain
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) [ghstack-poisoned]
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 148776976 Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/)
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 148895783 Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/)
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 149033187 Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/)
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 149066628 Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/)
Use markdown to write an upgrader guidance Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/) Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964) [ghstack-poisoned]
Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Differential Revision: [D34054964](https://our.internmc.facebook.com/intern/diff/D34054964/)
Summary: Pull Request resolved: #72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0
|
Hey @cccclai. |
raziel
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.
I just reviewed the top since this is a closed PR and cannot make suggestions in the content itself better for me to continue my review once you start a new PR.
| @@ -0,0 +1,205 @@ | |||
| # Guidance for Operator Developer | |||
|
|
|||
| PyTorch’s operators sometimes require changes to maintain the high quality user experience (UX) that PyTorch is known for. These changes can be backward compatibility (BC) breaking, where older programs will no longer run as expected on the latest version of PyTorch (an old writer / new reader problem) or forward compatibility (FC) breaking, where new programs will not run on older versions of PyTorch (a new writer / old reader problem). An upgrader is a method to use the new operator to mimic the old operator behavior. When a new runtime loads an old model with the old operator, the upgrader will replace the old operator in the model with the new operator. The replacement will only happen for old models, and it does not need to consider the new models. Please refer to the documentation [PyTorch Operator Versioning](https://github.com/pytorch/rfcs/blob/master/RFC-0017-PyTorch-Operator-Versioning.md) for more details. | |||
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.
A few things:
- I would rephrase old write / new reader to actually talk about program and runtime.
- We talk about FC but we should clarify upgraders are just for BC>
- "The replacement will only happen for old models, and it does not need to consider the new models." => Shouldn't this just be as simple as "upgraders only apply to instances of old operators to make sure they comply with the new operator contract"?
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.
Address on the new pr
|
|
||
| PyTorch’s operators sometimes require changes to maintain the high quality user experience (UX) that PyTorch is known for. These changes can be backward compatibility (BC) breaking, where older programs will no longer run as expected on the latest version of PyTorch (an old writer / new reader problem) or forward compatibility (FC) breaking, where new programs will not run on older versions of PyTorch (a new writer / old reader problem). An upgrader is a method to use the new operator to mimic the old operator behavior. When a new runtime loads an old model with the old operator, the upgrader will replace the old operator in the model with the new operator. The replacement will only happen for old models, and it does not need to consider the new models. Please refer to the documentation [PyTorch Operator Versioning](https://github.com/pytorch/rfcs/blob/master/RFC-0017-PyTorch-Operator-Versioning.md) for more details. | ||
|
|
||
| After you change to operator either the operator schema is BC-breaking way or the semantics of the operator, you will need to write an “upgrader” to make the change non-BC breaking iff they are used in TorchScript or mobile. In general, you can know your operator is BC breaking, if it fails `test/forward_backward_compatibility/check_forward_backward_compatibility.py ` |
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.
There's typos here: "After you change to operator either the operator schema is BC-breaking way or the semantics of the operator"
Also, this should at least include some examples on what's BC breaking.
"change non-BC breaking iff they are used in TorchScript or mobile"
Just for mobile? Also how could anybody know that: they can't so this is not optional.
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.
Address on the new pr
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Summary: Pull Request resolved: pytorch/pytorch#72470 Use markdown to write an upgrader guidance ghstack-source-id: 149079223 Test Plan: CI Reviewed By: iseeyuan, tugsbayasgalan Differential Revision: D34054964 fbshipit-source-id: 80f907701a9d44bcd6b5c22d01a471c26669bfb0 (cherry picked from commit eaed7627f526cab932273d24002a4f8e4a92c824)
Stack from ghstack:
Use markdown to write an upgrader guidance
Differential Revision: D34054964
Differential Revision: D34054964