diff --git a/docs/en/advanced_guides/tutorials/how_to_make_your_model_prunable.md b/docs/en/advanced_guides/tutorials/how_to_make_your_model_prunable.md new file mode 100644 index 000000000..40fc87931 --- /dev/null +++ b/docs/en/advanced_guides/tutorials/how_to_make_your_model_prunable.md @@ -0,0 +1,11 @@ +# How to make your model prunable by MMRazor + +We make much effort to make MMRazor can prune models automatically. However, there are also some cases we need help to handle. In this tutorial, we will show you how to make your model prunable by MMRazor when MMRazor can't take it automatically. + +We introduce you to how MMRazor prunes a model and what requirements are needed for the models in each step. + +1. First, we need a demo input for your model to conduct forward. We have implemented some demo inputs for some models. You can implement your demo input if they can't satisfy your model. Please refer to [demo input](../../../../mmrazor/models/task_modules/demo_inputs/demo_inputs.py) for more details. +2. We will trace your model using Fx tracer. Fx tracer requires models to satisfy some requirements to make sure the models are traceable. MMRazor has a modified fx tracer to make it more robust by automatically wrapping untraceable parts. However, it's also limited. It would help to change your model to make it traceable when tracing fails. Please refer to [fx tracer](https://pytorch.org/docs/stable/fx.html) for more details. +3. Then, we will convert the traced graph to a ChannelGraph. ChannelGraph is used to analyze the channel dependency with ChannelNodes. Please implement ChannelNodes for the ops that are not pre-defined in MMRazor. Please refer to [ChannelNode](../../../../mmrazor/structures/graph/channel_nodes.py) for more details. + +The above steps should be able to solve most of problems, if not, please feel free to open an issue. diff --git a/docs/en/user_guides/pruning_user_guide.md b/docs/en/user_guides/pruning_user_guide.md index a49b9de4d..317556da9 100644 --- a/docs/en/user_guides/pruning_user_guide.md +++ b/docs/en/user_guides/pruning_user_guide.md @@ -142,6 +142,7 @@ Please refer to the following documents for more details. - Development tutorials - [How to prune your model](../advanced_guides/tutorials/how_to_prune_your_model.md) - [How to use config tool of pruning](../advanced_guides/tutorials/how_to_use_config_tool_of_pruning.md) + - [How to make your model prunable](../advanced_guides/tutorials/how_to_make_your_model_prunable.md) - READMEs - [MutableChannel](../../../mmrazor/models/mutables/mutable_channel/MutableChannel.md) - [ChannelMutator](../../../mmrazor/models/mutables/mutable_channel/units/mutable_channel_unit.ipynb) diff --git a/tools/pruning/get_channel_units.py b/tools/pruning/get_channel_units.py index cb3f890ed..903080e47 100644 --- a/tools/pruning/get_channel_units.py +++ b/tools/pruning/get_channel_units.py @@ -43,7 +43,11 @@ def parse_args(): def main(): args = parse_args() config = Config.fromfile(args.config) - default_scope = config['default_scope'] + + if 'default_scope' in config: + default_scope = config['default_scope'] + else: + default_scope = 'mmrazor' model = MODELS.build(config['model']) if isinstance(model, BaseAlgorithm):