Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

[Compression v2] Auto-Compress Pruner #4280

Merged
merged 10 commits into from
Nov 26, 2021

Conversation

J-shang
Copy link
Contributor

@J-shang J-shang commented Oct 28, 2021

Need discussion about the interface about admm_params in AutoCompressPruner.__init__(), ref to the usage in AutoCompressPruner example, it has too many params to pass in... And ADMM will have more complex interfaces in the future...

TODO:

  • test & doc

Known Issue:
Loss increases during multi-GPU training.

Auto Compress Pruner
--------------------

For each round, AutoCompressPruner prune the model for the same sparsity to achive the overall sparsity:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for the same ..." -> for a fixed sparsity ratio (e.g., 20%) to achieve the overall sparsity (e.g., 80%).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to

For total iteration number :math:N, AutoCompressPruner prune the model that survive the previous iteration for a fixed sparsity ratio (e.g., :math:1-{(1-0.8)}^{(1/N)}) to achieve the overall sparsity (e.g., :math:0.8)

.. code-block:: bash

1. Generate sparsities distribution using SimulatedAnnealingPruner
2. Perform ADMM-based structured pruning to generate pruning result for the next round.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "for the next round"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to

for the next iteration

docs/en_US/Compression/v2_pruning_algo.rst Show resolved Hide resolved
The origin unwrapped pytorch model to be pruned.
config_list : List[Dict]
The origin config list provided by the user. Note that this config_list is directly config the origin model.
This means the sparsity provided by the origin_masks should also be recorded in the origin_config_list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you want to express with sentences?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the model already has 0.2 sparsity by origin_masks and the user wants a total 0.8 sparsity, set sparsity=0.8, not 0.6

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recorded -> counted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how could user provide origin_masks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I forgot I have removed this API in iterative pruner for simplifying, users need to use the scheduler to support origin_masks right now.
I will remove this line.

keep_intermediate_result : bool
If keeping the intermediate result, including intermediate model and masks during each iteration.
finetuner : Optional[Callable[[Module], None]]
The finetuner handled all finetune logic, use a pytorch module as input, will be called in each iteration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handled -> handles, use -> take

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

", will be ..." -> ". It will be called at the end of each iteration, usually for neutralizing the accuracy loss brought by the pruning in this iteration."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it

speed_up : bool
If set True, speed up the model in each iteration.
dummy_input : Optional[torch.Tensor]
If `speed_up` is True, `dummy_input` is required for trace the model in speed up.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for trace" -> "for tracing"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it

finetuner : Optional[Callable[[Module], None]]
The finetuner handled all finetune logic, use a pytorch module as input, will be called in each iteration.
speed_up : bool
If set True, speed up the model in each iteration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> If set True, speed up the model at the end of each iteration to make the pruned model compact.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix it

Supported pruning algorithm ['level', 'l1', 'l2', 'fpgm', 'slim', 'apoz', 'mean_activation', 'taylorfo', 'admm'].
This iterative pruner will use the chosen corresponding pruner to prune the model in each iteration.
pruning_params : Dict
If the pruner corresponding to the chosen pruning_algorithm has extra parameters, put them as a dict to pass in.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the pruner corresponding to the chosen pruning_algorithm" -> "the chosen one-shot pruner"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> If the chosen pruning_algorithm has extra parameters,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@J-shang J-shang force-pushed the compression_v2_autocompress branch from a8ad839 to d15fa2d Compare November 10, 2021 10:33
@QuanluZhang QuanluZhang merged commit ef4459e into microsoft:master Nov 26, 2021
@J-shang J-shang deleted the compression_v2_autocompress branch December 15, 2021 03:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants