Optimize mobile model on cloned module instead of in-place transformation#36621
Optimize mobile model on cloned module instead of in-place transformation#36621xcheng16 wants to merge 14 commits intogh/xcheng16/18/basefrom
Conversation
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
| insertPrePackedOps(m); | ||
| m = freeze_module(m); | ||
| FoldPrePackingOps(m); | ||
| auto moduleClone = module.clone(); |
There was a problem hiding this comment.
Do variable names follow camel case? From what I noticed no. If so change accordingly. Otherwise look great.
There was a problem hiding this comment.
good point, seems like not.
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
💊 Build failures summary and remediationsAs of commit 398a537 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 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 49 times. |
kimishpatel
left a comment
There was a problem hiding this comment.
LGTM. There are merge conflict. Plus import to phabricator.
AshkanAliabadi
left a comment
There was a problem hiding this comment.
When it comes making modifications in place vs not, what I have seen Python quantization modules do is to take an inplace argument, which if set to true, modifies the model in place, otherwise creates a copy. This is merely a suggestion, but following the principle of least surprise and API consistency I think we could follow the same principle. Again, just a suggestion, this is also fine as well.
| insertPrePackedOps(cloned_module); | ||
| cloned_module = freeze_module(cloned_module); | ||
| FoldPrePackingOps(cloned_module); | ||
| return cloned_module; |
There was a problem hiding this comment.
This function's return type is void, right? You are probably getting a compiler warning which PyTorch's compilation settings do not treat as error. Also if we are no longer modifying the parameter please pass it by const reference.
There was a problem hiding this comment.
It's still safer to pass the argument by const ref. Please consider that if there are no other complications. Otherwise we wouldn't have a way of knowing if we accidentally modify m.
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
I agree, but I think common expectation is to not do inplace? So if inplace is wanted, you have to be explicit about it. Also, something funny was happening when it was doing inplace mutation silently. For some reason it wasn't working until the module was serialized and then deserialized. That needs to be looked at, but this change at least make it cleaner and explicit. |
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 495164d Pull Request resolved: #36621
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: eb31ad0 Pull Request resolved: #36621
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: e5c292c Pull Request resolved: #36621
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: bbd7059 Pull Request resolved: #36621
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 98a01c5 Pull Request resolved: #36621
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
… transformation" Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21028406](https://our.internmc.facebook.com/intern/diff/D21028406) [ghstack-poisoned]
…tion Summary: Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: c463e70 Pull Request resolved: #36621
|
This pull request has been merged in eccb40f. |
…tion (pytorch#36621) Summary: Pull Request resolved: pytorch#36621 Instead of doing in-place transformation inside optimizeForMobile method, we would like to maintain the original structure for passed scriptedModule, so before optmization starts, we use the cloned module to do subsequent optimization process and return the optimized cloned module. Test Plan: unit test python test/test_mobile_optimizer.py Imported from OSS Differential Revision: D21028406 fbshipit-source-id: 756172ef99b1c1df6bb7d00e5deca85a4c239a87
Stack from ghstack:
Summary:
Instead of doing in-place transformation inside optimizeForMobile method,
we would like to maintain the original structure for passed scriptedModule,
so before optmization starts, we use the cloned module to do subsequent optimization
process and return the optimized cloned module.
Test Plan:
unit test
python test/test_mobile_optimizer.py
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D21028406