-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Support user-defined activation/weight quantize and preprocess. #28570
Conversation
Thanks for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weight_preprocess and act_preprocess 会保存到预测模型中,建议尝试对量化的层注册forward hook进行预处理。
用户定义的weight_quantize和act_quantize没办法在paddlelite和paddleinference中支持,这两个参数是否需要、是否暴露给用户,值得商榷。
python/paddle/fluid/contrib/slim/quantization/imperative/qat.py
Outdated
Show resolved
Hide resolved
python/paddle/fluid/contrib/slim/tests/test_imperative_qat_user_defined.py
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
APIs
Describe
Support user-defined quantification and preprocessing methods, such as PACT.
QAT model without using PACT
----------------------------------------------------------------------------------------------- Layer (type) Input Shape Output Shape Param # =============================================================================================== FakeQuantMovingAverage-1 [[1, 1, 28, 28]] [1, 1, 28, 28] 3 FakeChannelWiseQuantDequantAbsMax-1 [[6, 1, 3, 3]] [6, 1, 3, 3] 6 QuantizedConv2D-1 [[1, 1, 28, 28]] [1, 6, 28, 28] 60 Pool2D-1 [[1, 6, 28, 28]] [1, 6, 14, 14] 0 FakeQuantMovingAverage-2 [[1, 6, 14, 14]] [1, 6, 14, 14] 3 FakeChannelWiseQuantDequantAbsMax-2 [[16, 6, 5, 5]] [16, 6, 5, 5] 16 QuantizedConv2D-2 [[1, 6, 14, 14]] [1, 16, 10, 10] 2,416 Pool2D-2 [[1, 16, 10, 10]] [1, 16, 5, 5] 0 FakeQuantMovingAverage-3 [[1, 400]] [1, 400] 3 FakeChannelWiseQuantDequantAbsMax-3 [[400, 120]] [400, 120] 120 QuantizedLinear-1 [[1, 400]] [1, 120] 48,120 FakeQuantMovingAverage-4 [[1, 120]] [1, 120] 3 FakeChannelWiseQuantDequantAbsMax-4 [[120, 84]] [120, 84] 84 QuantizedLinear-2 [[1, 120]] [1, 84] 10,164 FakeQuantMovingAverage-5 [[1, 84]] [1, 84] 3 FakeChannelWiseQuantDequantAbsMax-5 [[84, 10]] [84, 10] 10 QuantizedLinear-3 [[1, 84]] [1, 10] 850 =============================================================================================== Total params: 61,861 Trainable params: 61,610 Non-trainable params: 251 ----------------------------------------------------------------------------------------------- Input size (MB): 0.00 Forward/backward pass size (MB): 0.55 Params size (MB): 0.24 Estimated Total Size (MB): 0.79 -----------------------------------------------------------------------------------------------
PACT QAT model:
----------------------------------------------------------------------------------------------- Layer (type) Input Shape Output Shape Param # =============================================================================================== PACT-1 [[1, 1, 28, 28]] [1, 1, 28, 28] 1 FakeQuantMovingAverage-1 [[1, 1, 28, 28]] [1, 1, 28, 28] 3 FakeChannelWiseQuantDequantAbsMax-1 [[6, 1, 3, 3]] [6, 1, 3, 3] 6 QuantizedConv2D-1 [[1, 1, 28, 28]] [1, 6, 28, 28] 60 Pool2D-1 [[1, 6, 28, 28]] [1, 6, 14, 14] 0 PACT-2 [[1, 6, 14, 14]] [1, 6, 14, 14] 1 FakeQuantMovingAverage-2 [[1, 6, 14, 14]] [1, 6, 14, 14] 3 FakeChannelWiseQuantDequantAbsMax-2 [[16, 6, 5, 5]] [16, 6, 5, 5] 16 QuantizedConv2D-2 [[1, 6, 14, 14]] [1, 16, 10, 10] 2,416 Pool2D-2 [[1, 16, 10, 10]] [1, 16, 5, 5] 0 PACT-3 [[1, 400]] [1, 400] 1 FakeQuantMovingAverage-3 [[1, 400]] [1, 400] 3 FakeChannelWiseQuantDequantAbsMax-3 [[400, 120]] [400, 120] 120 QuantizedLinear-1 [[1, 400]] [1, 120] 48,120 PACT-4 [[1, 120]] [1, 120] 1 FakeQuantMovingAverage-4 [[1, 120]] [1, 120] 3 FakeChannelWiseQuantDequantAbsMax-4 [[120, 84]] [120, 84] 84 QuantizedLinear-2 [[1, 120]] [1, 84] 10,164 PACT-5 [[1, 84]] [1, 84] 1 FakeQuantMovingAverage-5 [[1, 84]] [1, 84] 3 FakeChannelWiseQuantDequantAbsMax-5 [[84, 10]] [84, 10] 10 QuantizedLinear-3 [[1, 84]] [1, 10] 850 =============================================================================================== Total params: 61,866 Trainable params: 61,615 Non-trainable params: 251 ----------------------------------------------------------------------------------------------- Input size (MB): 0.00 Forward/backward pass size (MB): 0.57 Params size (MB): 0.24 Estimated Total Size (MB): 0.81 -----------------------------------------------------------------------------------------------