Fuse module enhancements#26457
Fuse module enhancements#26457raghuramank100 wants to merge 5 commits intogh/raghuramank100/25/basefrom
Conversation
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/) [ghstack-poisoned]
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/) ghstack-source-id: 90402269 Pull Request resolved: #26457
dzhulgakov
left a comment
There was a problem hiding this comment.
Looking good, some more suggestions
| """ | ||
| return torch.nn._intrinsic.LinearReLU(linear, relu) | ||
|
|
||
| def fuse_conv_bn(conv, bn): |
There was a problem hiding this comment.
this function (and probably fuse_conv_bn_eval) misses setting the training mode. Something like result.train(original.training)
There was a problem hiding this comment.
There is no need to do that here, we just create a sequential here with the original modules, so all attributes are preserved
torch/quantization/fuse_modules.py
Outdated
| _set_module(model, modules_to_fuse[0], new_mod) | ||
|
|
||
| for item in modules_to_fuse[1:]: | ||
| _set_module(model, item, torch.nn.Identity()) |
There was a problem hiding this comment.
for cleanness - set the training mode here too
torch/quantization/fuse_modules.py
Outdated
| for item in modules_to_fuse[1:]: | ||
| _set_module(model, item, torch.nn.Identity()) | ||
|
|
||
| def fuse_modules(model, modules_to_fuse): |
There was a problem hiding this comment.
I wonder whether we should do special handling for Sequential. The good thing about sequantials is that we know what forward looks like. So we could just iterate through them and try to find a match.
I'm also fine doing it later in a separate PR as it doesn't appear to be a critical feature.
There was a problem hiding this comment.
This is useful only when we have a sequential module at the leaf of the module tree having fusable modules, so lets do this in a later PR
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/) [ghstack-poisoned]
Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion ghstack-source-id: 91046110 Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/)
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/) [ghstack-poisoned]
dzhulgakov
left a comment
There was a problem hiding this comment.
Minor comments - otherwise good to go
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/) [ghstack-poisoned]
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/) [ghstack-poisoned]
Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Differential Revision: [D17466382](https://our.internmc.facebook.com/intern/diff/D17466382/)
|
This pull request has been merged in dddae3f. |
Summary: Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Summary: Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Summary: Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Summary: Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Summary: Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Summary: Pull Request resolved: #26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Summary: Pull Request resolved: pytorch#26457 Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict. Also add support for Conv-Relu and linear-relu fusion Also support inplace and out of place fusion of models. ghstack-source-id: 91076386 Test Plan: buck test caffe2/test:quantization -- 'test_fusion_sequential_model_train \(test_quantization\.FusionTest\)' --print-passing-details buck test caffe2/test:quantization -- 'test_fusion_sequential_model_eval \(test_quantization\.FusionTest\)' --print-passing-details Differential Revision: D17466382 fbshipit-source-id: 0a548f8f4c366f3ecc59db693bac725ccd62328e
Stack from ghstack:
Enhancement to fuse module to support sequentials, fuse list can now be just like the state dict.
Also add support for Conv-Relu and linear-relu fusion
Differential Revision: D17466382