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

Add Embedding quantization #4159

Merged
merged 4 commits into from
Dec 29, 2022
Merged

Conversation

LiuChiachi
Copy link
Contributor

@LiuChiachi LiuChiachi commented Dec 19, 2022

PR types

New features

PR changes

APIs

Description

Add Embedding quantization

PYTHONPATH=/liujiaqi/PaddleNLP:/liujiaqi/PaddleSlim python compress_seq_cls.py    \
    --dataset   "clue cluewsc2020"     \
    --model_name_or_path ernie-3.0-tiny-nano-v2-zh   \
    --per_device_train_batch_size 32   \
    --output_dir ./test  \
    --per_device_eval_batch_size 32    \
    --num_train_epochs 5   \
    --width_mult_list 2/3   \
    --batch_size_list 4   \
    --algo_list 'abs_max'   \
    --strategy 'dynabert ptq embeddings'  \
    --onnx_format False

@paddle-bot
Copy link

paddle-bot bot commented Dec 19, 2022

Thanks for your contribution!

@codecov
Copy link

codecov bot commented Dec 19, 2022

Codecov Report

Merging #4159 (9cfb4f9) into develop (c73a3a0) will decrease coverage by 0.01%.
The diff coverage is 8.10%.

@@             Coverage Diff             @@
##           develop    #4159      +/-   ##
===========================================
- Coverage    36.39%   36.38%   -0.02%     
===========================================
  Files          419      419              
  Lines        59059    59089      +30     
===========================================
+ Hits         21496    21499       +3     
- Misses       37563    37590      +27     
Impacted Files Coverage Δ
paddlenlp/trainer/trainer_compress.py 8.70% <8.10%> (+0.07%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

self.quant(input_dir, args.strategy)
elif args.strategy == "qat":
output_dir_list = self.quant(input_dir, "ptq")
print(output_dir_list)
Copy link
Collaborator

Choose a reason for hiding this comment

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

print可以删除

Copy link
Contributor Author

Choose a reason for hiding this comment

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

感谢提醒,已经删除

@@ -138,7 +153,7 @@ def _dynabert(self, model, output_dir):
ofa_model = _dynabert_training(
self, ofa_model, model, teacher_model, train_dataloader, eval_dataloader, args.num_train_epochs
)

self.reset_optimizer_and_scheduler()
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里reset优化器和学习率的原因是什么了?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里是dynabert的部分,训练完毕后reset 了优化器和学习率,目的是如果后面接入了 qat,防止qat的优化器和学习率是接着dynabert的部分来的而不是自己独立的从头开始。


input_dir = os.path.dirname(input_prefix)

paddle.fluid.io.save_inference_model(
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里建议不要再使用fluid相关的API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

目前只有这个 API 可以直接使用,新版本的paddle.static.save_inference_model输入需要feed_var,fluid API 只需要feed_var_names,而feed_var_names可以通过上面load_inference_model给出

@LiuChiachi LiuChiachi requested a review from wawltor December 28, 2022 12:00
Copy link
Collaborator

@wawltor wawltor left a comment

Choose a reason for hiding this comment

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

LGTM

@wawltor wawltor merged commit 5d542a2 into PaddlePaddle:develop Dec 29, 2022
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.

2 participants