neural_compressor.compression.pruner.model_slim.pattern_analyzer
Analyze.
Classes
Searcher class which searches patterns with a pre-defined recipe. |
|
Static graph searcher class which searches patterns with PyTorch static graph and its input/output information. |
|
Static graph searcher for consecutive linear layers. |
|
Static graph searcher for multi-head attention modules. |
|
Static graph searcher for multi-head attention modules. |
|
Static graph searcher for multi-head attention modules. |
Functions
|
Get a multi-level descent module of module. |
|
Get the module which contains layer1 and layer2 (nearest father nodes) |
|
Print the auto slim logs. |
Module Contents
- neural_compressor.compression.pruner.model_slim.pattern_analyzer.get_attributes(module, attrs: str)[source]
Get a multi-level descent module of module.
- Parameters:
module (torch.nn.Module) – The torch module.
attrs (str) – The attributes’ calling path.
- Returns:
The target attribute of the module.
- Return type:
attr
- neural_compressor.compression.pruner.model_slim.pattern_analyzer.get_common_module(layer1: str, layer2: str)[source]
Get the module which contains layer1 and layer2 (nearest father nodes)
- neural_compressor.compression.pruner.model_slim.pattern_analyzer.print_iterables(data_iters)[source]
Print the auto slim logs.
- class neural_compressor.compression.pruner.model_slim.pattern_analyzer.RecipeSearcher(model, recipe: dict)[source]
Searcher class which searches patterns with a pre-defined recipe.
A Recipe is a dict type data which contains the root module’s name and its sub-modules’ levelwise calling way. For example, for the self-attention module in Huggingface bert-model, if we want to obtain its linear ops (query, key, value and output), the recipe should be like: recipe_samples = {
‘BertAttention’: [“self.query”, “self.key”, “self.value”, “output.dense”]
}
- Parameters:
model (torch.nn.Module) – The PyTorch model for searching.
recipe (dict) – A dict containing information of the searching pattern.
- class neural_compressor.compression.pruner.model_slim.pattern_analyzer.JitBasicSearcher(model, dataloader=None, placeholder_shape=None, placeholder_dtype=None)[source]
Static graph searcher class which searches patterns with PyTorch static graph and its input/output information.
By converting a PyTorch Model into a static version using torch.jit.trace()/script(), we can trace some special pattern in the model and optimize them automatically. This class provide some basic functions for jit searcher Including generating dummy inputs, generating static graph, analyzing static graph.
- Parameters:
model (torch.nn.Module) – The PyTorch model for searching.
- class neural_compressor.compression.pruner.model_slim.pattern_analyzer.Linear2LinearSearcher(model, dataloader=None, placeholder_shape=None, placeholder_dtype=None)[source]
Static graph searcher for consecutive linear layers.
Use the static graph to detect some special pattern in a module, there is no need for user to define layer name. Automatically search linear layers which can be optimized.
- Parameters:
model (torch.nn.Module) – The PyTorch model for searching.
- class neural_compressor.compression.pruner.model_slim.pattern_analyzer.SelfMHASearcher(model, dataloader=None, placeholder_shape=None, placeholder_dtype=None)[source]
Static graph searcher for multi-head attention modules.
Use the static graph to detect some special pattern in a module, there is no need for user to define layer name. Automatically search multi-head attention modules which can be optimized.
- Parameters:
model (torch.nn.Module) – The PyTorch model for searching.
- class neural_compressor.compression.pruner.model_slim.pattern_analyzer.ClassifierHeadSearcher(model)[source]
Static graph searcher for multi-head attention modules.
Use the static graph to detect final classifier head in a module, there is no need for user to define layer name. Automatically search multi-head attention modules which can be optimized.
- Parameters:
model (torch.nn.Module) – The PyTorch model for searching.
- class neural_compressor.compression.pruner.model_slim.pattern_analyzer.ClassifierHeadSearcherTF(model)[source]
Static graph searcher for multi-head attention modules.
Use the static graph to detect final classifier head in a module, there is no need for user to define layer name. Automatically search multi-head attention modules which can be optimized.
- Parameters:
model (tf.keras.Model) – The Keras model for searching.