Skip to content

Commit

Permalink
Automatic set gmp_config (PaddlePaddle#1103)
Browse files Browse the repository at this point in the history
* Automatic set gmp_config

* Automatic set gmp_config

* add a note.

* add a note.
  • Loading branch information
zzjjay authored May 18, 2022
1 parent b05085e commit e6ae764
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion paddleslim/auto_compression/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ def _prepare_program(self, program, feed_target_names, fetch_targets,
feed_target_names, fetch_targets)

config_dict = dict(config._asdict())
if config_dict["prune_strategy"] == "gmp" and config_dict[
'gmp_config'] is None:
_logger.info(
"Calculating the iterations per epoch……(It will take some time)")
# NOTE:XXX: This way of calculating the iters needs to be improved.
iters_per_epoch = len(list(self.train_dataloader()))
total_iters = self.train_config.epochs * iters_per_epoch
config_dict['gmp_config'] = {
'stable_iterations': 0,
'pruning_iterations': 0.45 * total_iters,
'tunning_iterations': 0.45 * total_iters,
'resume_iteration': -1,
'pruning_steps': 100,
'initial_ratio': 0.15,
}
### add prune program
self._pruner = None
if 'prune' in strategy:
Expand Down Expand Up @@ -280,13 +295,14 @@ def _prepare_program(self, program, feed_target_names, fetch_targets,
test_program_info)
if self.train_config.sparse_model:
from ..prune.unstructured_pruner import UnstructuredPruner
# NOTE: The initialization parameter of this pruner doesn't work, it is only used to call the 'set_static_masks' function
self._pruner = UnstructuredPruner(
train_program_info.program,
mode='ratio',
ratio=0.75,
prune_params_type='conv1x1_only',
place=self._places)
self._pruner.set_static_masks()
self._pruner.set_static_masks() # Fixed model sparsity

self._exe.run(train_program_info.startup_program)

Expand Down

0 comments on commit e6ae764

Please sign in to comment.