Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an example to apply ASP on existed BERT training scripts #579

Merged
merged 3 commits into from
Jun 22, 2021

Conversation

mingxu1067
Copy link
Contributor

PR types

New features

PR changes

Models

Description

Added an example to apply Automatic SParsity (ASP) module (new feature of PaddlePaddle) on BERT GLUE finetuning.
That is only few line insertion needed to enable training in ASP workflow.

  1. Setup layers which would like to keep dense.
  2. Wrap optimizer by sparsity.decorate(), which would insert weight masking operations.
  3. Pruning models to desired sparse pattern (default is 2:4 sparse pattern ) before training start.

Please refer to ASP PR on PaddlePaddle for more details.

Note: We also implemented Distributed API for ASP, and it's under reviewing (here). After merged, we would also provided an example on multi-devices BERT pretraining.

@ZeyuChen
Copy link
Member

Thanks for your contributions! @guoshengCS Please review the code.


# Keep Pooler and task-specific layer dense.
# Please note, excluded_layers must be set before calling `optimizer.minimize()`.
sparsity.set_excluded_layers(main_program, ['linear_72', 'linear_73',])
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using model.bert.pooler.dense.full_name(), model.classifier.full_name() to replace 'linear_72', 'linear_73', which might be more meaningful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a great suggestion. Updated.

Copy link
Contributor

@guoshengCS guoshengCS left a comment

Choose a reason for hiding this comment

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

LGTM

@ZeyuChen
Copy link
Member

Thanks for your contribution! @mingxu1067

@ZeyuChen ZeyuChen merged commit bf28087 into PaddlePaddle:develop Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants