Changes to transition to generic API for ops with weight prepacking#35010
Changes to transition to generic API for ops with weight prepacking#35010kimishpatel wants to merge 12 commits intogh/kimishpatel/5/basefrom
Conversation
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 01e11d3 Pull Request resolved: #35010
|
To note: This PR has not yet done the following: |
dzhulgakov
left a comment
There was a problem hiding this comment.
Looks like on the right track!
Why do you have many formatting changes? Is it different version of clang-format?
| groups, | ||
| {}, | ||
| {}); | ||
| Tensor run(const ContextConv2D& context, const Tensor& input) { |
There was a problem hiding this comment.
maybe minor thing - but why no make it a method?
There was a problem hiding this comment.
I kept how it was in the original diff TBH. Yes it can be a method and in this case it might make sense. I will just keep it a TODO for future refactoring instead of doing it in the diff.
| return output.contiguous(input.suggest_memory_format()); | ||
| } | ||
|
|
||
| c10::intrusive_ptr<xnnpack::Conv2dOpContext> Conv2dPrePack::operator()( |
There was a problem hiding this comment.
nit: you don't need this trampoline - you can register xnnpack::XNNPackConv2dOpContext::create_context directly with RegisterOps (it doesn't need to be a functor)
There was a problem hiding this comment.
I tried that in the first diff itself and something I ran into that would not let me compile, cannot remember what. I will try again and see if there is a way around else report the error back here.
|
|
||
| class LinearOpContext : public torch::jit::CustomClassHolder { | ||
| protected: | ||
| Tensor orig_weight_; |
There was a problem hiding this comment.
this duplicates all weights for serialization, I guess xnnpack doesn't have "unpack" method, does it?
There was a problem hiding this comment.
This is correct. My plan was to have the weights set to null inside setstate conditioned on some flags such as lite_interpreter run etc., that ensure we will not be serializing this. Is that the right approach?
There was a problem hiding this comment.
@dzhulgakov, so I think we dont need to use trampoline. However, given that we are doing all this to make a generic API, it makes sense to hide backend specific context creation behind something, which in this PR turns out to be just a trampoline. However I am gonna stack a PR on top of this which will check global context to see which engine we want to use for packing (for now xnnpack) and direct context creation appropriately. I will refactor this code so that both setstate method and PrePack op are directed to a common method for context creaton.
There was a problem hiding this comment.
I'm not sure what the right approach is here. If we set the weights to null, that means we can't re-save the model, right?
There was a problem hiding this comment.
Yes, but if we know we will not need to, e.g. when we know we are doing inference in lite interpreter, it should ok, right?
There was a problem hiding this comment.
Yeah, but what about people using the full JIT. This is okay for now, but we should keep thinking about better solutions.
There was a problem hiding this comment.
Keeping the weights around is fine, we can gate freeing them with mobile interpreter flag indeed (we kind of do that for qnnpack on mobile I think).
💊 CircleCI build failures summary and remediationsAs of commit 38e2eb4 (more details on the Dr. CI page): ✅ None of the build failures appear to be your fault 💚
🚧 2 upstream failures:These were probably caused by upstream breakages:
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 on the GitHub issue tracker. This comment has been revised 31 times. |
Possibly. I ended apply clang-format on all the files that I touched. |
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 2143c10 Pull Request resolved: #35010
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
dreiss
left a comment
There was a problem hiding this comment.
Formatting changes need to be in a separate diff. This is impossible to review asis.
I shouldnt have run clang-format on this. This is going to take a while to fix. |
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 3cdde9d Pull Request resolved: #35010
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: b8aaea5 Pull Request resolved: #35010
|
|
||
| class LinearOpContext : public torch::jit::CustomClassHolder { | ||
| protected: | ||
| Tensor orig_weight_; |
There was a problem hiding this comment.
Yeah, but what about people using the full JIT. This is okay for now, but we should keep thinking about better solutions.
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Also had to add BC test changes to whitelist the ops added. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 5ca10a0 Pull Request resolved: #35010
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Also had to add BC test changes to whitelist the ops added. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 9d05d87 Pull Request resolved: #35010
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Also had to add BC test changes to whitelist the ops added. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: b55a94d Pull Request resolved: #35010
…repacking" semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D20526416](https://our.internmc.facebook.com/intern/diff/D20526416) [ghstack-poisoned]
semantics. Summary: This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Also had to add BC test changes to whitelist the ops added. Test Plan: python test/test_xnnpack_integration.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: b75cb64 Pull Request resolved: #35010
|
This pull request has been merged in e1c092f. |
1 similar comment
|
This pull request has been merged in e1c092f. |
|
What's the plan? are we going to use this for quantized ops as well? |
I don't think so. Changes are mainly to abstract away xnnpack specific namespace from ops and make it generic. For example if we want to use gpu as the backend instead of xnnpack. |
Not my plan. Quantized ops need to have output scale/zero as part of the interface, so IMO they should follow this same pattern but be separate. |
|
folding quantized prepack is pretty much the same I think: #35077 So is this for the non quantized use case only? |
|
Oh sorry, it might be confusing, I'm just talking about prepack folding. Found this PR when after I rebase my PRs and see the name of |
Not sure what you mean by FoldPrepackingOps name changed. Also the rest of the op registration namespace changed but that should not impact any JIT passes. |
| n->kind() == Symbol::fromQualString("prepacked::conv2d_clamp_prepack")); | ||
| }; | ||
| FoldPrePackingOps(m, filter_fn, "xnnpack_prepack_folding"); | ||
| PrePackingOpsFolder(m, filter_fn, "prepack_folding"); |
There was a problem hiding this comment.
I'm talking about the function name is changed from FoldPrePackingOps to PrePackingOpsFolder, which leads me to the PR, but it is not important. I'm just trying to understand what is the use case this function is targeting, is this only for non-quantized prepacking ops?
There was a problem hiding this comment.
Aah thanks for pointing out :). Shouldn't have changed that as part of this PR. But to answer your question, no. It should be generic as we had discussed originally when the PR for this pass was under review. It should still be a generally usable pass that is can be applied after freezing, regardless. However the naming either FoldPrePackingOps or PrePackingOpsFolder does suggest that it is for prepacking ops, including quantized. But I understand the concern, if that is the concern, that the naming may suggest that it is applied to ops that are in prepacked namespace even though that is not the case.
There was a problem hiding this comment.
Yeah the implementation is applicable to quantized ops as well. Do we want to do use the same function for quantized prepacking ops as well(since now it is changed to a generic function)?
There was a problem hiding this comment.
I think that was the original plan, right? I dont think anything about that has changed, except naming. So I would say yes we should.
There was a problem hiding this comment.
I mean yeah, I can use PrePackingOpsFolder to implement a pass to fold quantized ops.
My question is should we merge that to the current new FoldPrePackingOps here, or is this still function still just for xnnpack?
There was a problem hiding this comment.
resolved in chat, this is prepack folding for fp32 ops.
…ytorch#35010) Summary: Pull Request resolved: pytorch#35010 semantics. This PR moves all the xnnpack specific interfces to a generic interface. Accordingly removes xnnpac specific reference from API and some variable names. What has not yet changed: TODO: USE_XNNPACK is still used. This can be removed where no XNNPACK specific things are done. e.g., RegisterOpContext.cpp and xnnpack_rewrite.cpp. Also the filename and structure also remains. Some of the generic class definition can be moved non-XNNPACK specific folder. Test Plan: python test/test_xnnpack_integration.py Imported from OSS Differential Revision: D20526416 fbshipit-source-id: 2e1725345c44bbb26bdc448097a7384eca121387
Stack from ghstack:
semantics.
Summary:
This PR moves all the xnnpack specific interfces to a generic interface.
Accordingly removes xnnpac specific reference from API and some variable
names.
What has not yet changed:
TODO:
USE_XNNPACK is still used. This can be removed where no XNNPACK
specific things are done. e.g., RegisterOpContext.cpp and
xnnpack_rewrite.cpp.
Also the filename and structure also remains. Some of the generic class
definition can be moved non-XNNPACK specific folder.
Test Plan:
python test/test_xnnpack_integration.py
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D20526416