chop.passes.graph.pruning#
add_pruning_metadata_analysis_pass#
- chop.passes.graph.analysis.pruning.calculate_sparsity.add_pruning_metadata_analysis_pass(graph, pass_args: dict = {})[source]#
Add post-pruning metadata analysis pass to the given graph, the graph must have been pruned.
- Parameters:
graph (MaseGraph) – The MaseGraph to which the pruning metadata analysis pass will be added.
pass_args – Additional arguments for the pruning metadata analysis pass.
This pass requires a dummy_in and a bool value for add_value. If add value is true, the mask values would be added to meta data. :type pass_args: dict
pass_args = { 'dummy_in': torch.tensor(...), 'add_meta': True # bool value whether to add the natural sparsity to the metadata }
- Returns:
The updated graph and sparsity information.
The returned dict contains {‘weight_sparsity’: float, ‘activation_sparsity’: float} :rtype: tuple(MaseGraph, dict)
add_natural_sparsity_metadata_analysis_pass#
- chop.passes.graph.analysis.pruning.calculate_natural_sparsity.add_natural_sparsity_metadata_analysis_pass(graph, pass_args: dict = {})[source]#
Add natural sparsity metadata analysis pass to the given MaseGraph. This is normally used to inspect on the natural sparsity values on both weights and activations.
- Parameters:
graph (MaseGraph) – The MaseGraph to which the analysis pass will be added.
pass_args – Additional arguments for the analysis pass.
{‘dummy_in’: tensor, ‘add_meta’ bool}, add_meta controls whether he natural sparsity would be registered in mase metadata. :type pass_args: dict
pass_args = { 'dummy_in': torch.tensor(...), 'add_meta': True # bool value whether to add the natural sparsity to the metadata }
- Returns:
The updated MaseGraph and sparsity information.
The returned dict contains {name (str): sparsity_value (float)} :rtype: tuple
Examples:
A sample output dict:
{ 'avg_activation': tensor(0.6709), 'avg_weight': tensor(1.0000), 'conv1_activation': (6144, tensor(1.)), 'conv1_weight': (9408, tensor(1.)), 'fc_activation': (1024, tensor(0.6289)), 'fc_weight': (5120, tensor(1.)), 'layer1.0.conv1_activation': (8192, tensor(0.8810)), 'layer1.0.conv1_weight': (36864, tensor(1.)), ... }
hook_inspection_analysis_pass#
- chop.passes.graph.analysis.pruning.hook_inspector.hook_inspection_analysis_pass(graph, pass_args: dict = {})[source]#
Remove and provide hook information of the modules.
- Parameters:
graph (MaseGraph) – The MaseGraph to which the pruning metadata analysis pass will be added.
pass_args (dict) – Additional arguments for the pruning metadata analysis pass. This pass does not need any values, so an empty dictionary is fine
pass_args can be None or an empty dictionary.
- Returns:
The updated graph and sparsity information. The returned dict contains {‘module_name’: (hook_id, hook_fn)}
- Return type:
tuple(MaseGraph, dict)
Examples:
A sample output dict:
{ 'feature_layers.0_0': ( 0, <function get_activation_hook.<locals>.sparsify_input at 0x7f9544528c10>), 'feature_layers.3_1': ( 1, <function get_activation_hook.<locals>.sparsify_input at 0x7f9544528ca0>), 'feature_layers.7_2': ( 2, <function get_activation_hook.<locals>.sparsify_input at 0x7f9544528d30>), }