Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update on "[quant][graphmode][fx] Support quantization for standalone…
… module" Summary: Sometimes user need to quantize a submodule as one unit, and this submodule will be lowered to a different backend like accelerator. The submodule will be quantized with the same fx based graph mode quantization functions and will be connected with the rest of the model automatically. APIs: ```python class StandaloneModule(torch.nn.Module): def __init__(self): super().__init__() self.conv = torch.nn.Conv2d(1, 1, 1) def forward(self, x): return self.conv(x) class CustomTracer(Tracer): def is_leaf_module(self, m, module_qualified_name): return (m.__module__.startswith('torch.nn') and not isinstance(m, torch.nn.Sequential)) or \ isinstance(m, StandaloneModule) class ModelThatUsesStandaloneModule(...): def __init__(self): super().__init__() self.standalone = StandaloneModule() def forward(self, x): return self.standalone(x) m = ModelThatUsesStandaloneModule() qconfig_dict = {"": qconfig, "standalone_module_name": ["standalone"]} m = prepare_fx(m, qconfig_dict) calibrate(m, data) m = convert_fx(m) m.standalone = lower_to_acclerator(m.standalone) ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23580642](https://our.internmc.facebook.com/intern/diff/D23580642) [ghstack-poisoned]
- Loading branch information
Showing
51 changed files
with
713 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.