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

Support user-defined activation/weight quantize and preprocess. #28570

Merged
merged 5 commits into from
Nov 18, 2020

Conversation

baiyfbupt
Copy link
Contributor

@baiyfbupt baiyfbupt commented Nov 12, 2020

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
-----------------------------------------------------------------------------------------------

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@baiyfbupt baiyfbupt changed the title Dy qat Support user-defined activation/weight quantize and preprocess. Nov 12, 2020
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Nov 13, 2020
@PaddlePaddle PaddlePaddle unlocked this conversation Nov 13, 2020
Copy link
Contributor

@juncaipeng juncaipeng left a 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中支持,这两个参数是否需要、是否暴露给用户,值得商榷。

@baiyfbupt
Copy link
Contributor Author

baiyfbupt commented Nov 17, 2020

weight_preprocess and act_preprocess 会保存到预测模型中,建议尝试对量化的层注册forward hook进行预处理。

用户定义的weight_quantize和act_quantize没办法在paddlelite和paddleinference中支持,这两个参数是否需要、是否暴露给用户,值得商榷。

  • forward_pre_hook中进行预处理无法在反向传播时更新可学习参数,PACT等带有可学习参数的方法不适用

  • 这里是留一个快速验证新型量化方法是否有效的接口,用户可以快速写一个量化方式进行量化训练实验验证,如果有效再考虑新增op。这里还不需要预测库支持

Copy link
Contributor

@juncaipeng juncaipeng left a comment

Choose a reason for hiding this comment

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

LGTM

@baiyfbupt baiyfbupt merged commit 5050e76 into PaddlePaddle:develop Nov 18, 2020
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