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

模型静态量化时出错 #767

Closed
ZEROICEWANG opened this issue May 20, 2021 · 5 comments
Closed

模型静态量化时出错 #767

ZEROICEWANG opened this issue May 20, 2021 · 5 comments
Assignees

Comments

@ZEROICEWANG
Copy link

我在对模型进行静态量化时,程序报错

报错信息如下

2021-05-20 15:02:44,389-INFO: Load model and set data loader ...
2021-05-20 15:02:47,652-INFO: Collect quantized variable names ...
2021-05-20 15:02:47,692-INFO: Preparation stage ...
2021-05-20 15:02:54,276-INFO: Run batch: 0
2021-05-20 15:02:54,277-INFO: Finish preparation stage, all batch:1
2021-05-20 15:02:54,348-INFO: Sampling stage ...
2021-05-20 15:03:58,629-INFO: Run batch: 0
2021-05-20 15:03:58,630-INFO: Finish sampling stage, all batch: 1
2021-05-20 15:03:58,637-INFO: Calculate KL threshold ...
2021-05-20 15:19:03,373-INFO: Update the program ...
Traceback (most recent call last):
  File "F:/graduation_project_data/PyCharm Project/CPD_MNV3_Paddle/slim/slim.py", line 136, in <module>
    batch_size=20)
  File "E:\Anaconda3\envs\Paddle\lib\site-packages\paddleslim\quant\quanter.py", line 407, in quant_post_static
    post_training_quantization.quantize()
  File "E:\Anaconda3\envs\Paddle\lib\site-packages\paddle\fluid\contrib\slim\quantization\post_training_quantization.py", line 382, in quantize
    self._update_program()
  File "E:\Anaconda3\envs\Paddle\lib\site-packages\paddle\fluid\contrib\slim\quantization\post_training_quantization.py", line 735, in _update_program
    freeze_pass.apply(graph)
  File "E:\Anaconda3\envs\Paddle\lib\site-packages\paddle\fluid\contrib\slim\quantization\quantization_pass.py", line 1167, in apply
    self._insert_post_channel_dequant_op(graph, op_node)
  File "E:\Anaconda3\envs\Paddle\lib\site-packages\paddle\fluid\contrib\slim\quantization\quantization_pass.py", line 1211, in _insert_post_channel_dequant_op
    original_var_name)
AssertionError: The scale of parameter conv2d_209.w_0 is not a list.

Process finished with exit code -1073740791 (0xC0000409)

在使用Nettron打开模型结构图时,对比发现时我写的一个多层特征融合处发生了错误,错误对应的卷积为self.conv5
模型静态图推理和动态图推理都没有异常,只有在量化的时候出现了这个问题,请问是哪里设置的有问题吗?

代码如下

class aggregation(nn.Layer):
    def __init__(self, channel):
        super(aggregation, self).__init__()
        self.relu = paddle.nn.ReLU(True)

        self.upsample = paddle.nn.UpsamplingBilinear2D(scale_factor=2)
        self.conv_upsample1 = nn.Conv2D(channel, channel, 3, padding=1)
        self.conv_upsample2 = nn.Conv2D(channel, channel, 3, padding=1)
        self.conv_upsample3 = nn.Conv2D(channel, channel, 3, padding=1)
        self.conv_upsample4 = nn.Conv2D(channel, channel, 3, padding=1)
        self.conv_upsample5 = nn.Conv2D(2 * channel, 2 * channel, 3, padding=1)

        self.conv_concat2 = nn.Conv2D(2 * channel, 2 * channel, 3, padding=1)
        self.conv_concat3 = nn.Conv2D(3 * channel, 3 * channel, 3, padding=1)
        self.conv4 = nn.Conv2D(3 * channel, 3 * channel, 3, padding=1)
        self.conv5 = nn.Conv2D(3 * channel, 1, 1)

    def forward(self, x1, x2, x3):
        # x1: 1/32 x2: 1/16 x3: 1/8
        x1_1 = x1
        x2_1 = self.conv_upsample1(self.upsample(x1)) * x2
        x3_1 = self.conv_upsample2(self.upsample(self.upsample(x1))) \
               * self.conv_upsample3(self.upsample(x2)) * x3

        x2_2 = paddle.concat((x2_1, self.conv_upsample4(self.upsample(x1_1))), 1)
        x2_2 = self.conv_concat2(x2_2)

        x3_2 = paddle.concat((x3_1, self.conv_upsample5(self.upsample(x2_2))), 1)
        x3_2 = self.conv_concat3(x3_2)

        x = self.conv4(x3_2)
        x = self.conv5(x)

        return x
@juncaipeng
Copy link
Contributor

@ZEROICEWANG 从log看不出来具体问题,请问使用哪个版本的paddleslim和paddlepaddle?同时请提供一下复现单侧。

@ZEROICEWANG
Copy link
Author

已经排查到问题出现的原因,在进行卷及操作时,若是out_channel为1,则会出现这个问题,大于1则不会出现这个问题,希望你们能够尽快修复这个bug

@ZEROICEWANG
Copy link
Author

paddlepaddle-gpu 2.0.2.post100
paddleslim 2.0.0

@XGZhang11
Copy link
Collaborator

您好,bug已经修复,PaddlePaddle/Paddle#33753

@ZEROICEWANG
Copy link
Author

您好,bug已经修复,PaddlePaddle/Paddle#33753

在paddle2.0+paddleslim2.0与paddle2.1+paddleslim2.1上都做了测试,还是存在该问题

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

No branches or pull requests

4 participants