Skip to content

Conversation

juncaipeng
Copy link
Contributor

@juncaipeng juncaipeng commented Jun 9, 2021

PR types

New features

PR changes

Others

Describe

Dygraph post trainging quantization

@PaddlePaddle PaddlePaddle deleted a comment from paddle-bot-old bot Jun 10, 2021
Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM for set_tests_properties

@juncaipeng juncaipeng merged commit 2b6fc10 into PaddlePaddle:develop Jun 22, 2021
@juncaipeng juncaipeng deleted the dygraph_ptq_2 branch June 22, 2021 02:22

class ImperativePTQ(object):
"""
Applying static post_training quantization to the dgraph model.
Copy link
Contributor

Choose a reason for hiding this comment

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

有没有更专业的词来表示dgraph model

Copy link
Contributor Author

Choose a reason for hiding this comment

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

直接默认是model吧~~

Comment on lines +42 to +44
algo(str): The algorithm in post_training quantizaion to be used.
activation_bits(int): quantization bit number for activations.
weight_bits(int): quantization bit number for weights.
Copy link
Contributor

Choose a reason for hiding this comment

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

这些参数并没有出现在__init__参数列表中。
另外,需要详细说明下默认情况下input和weight各用的是什么quantizer。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done tks

Add hook to the leaf layer to calculate the threshold of inputs and outputs.
Args:
model(paddle.nn.Layer): The model to be quantized.
Copy link
Contributor

Choose a reason for hiding this comment

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

缺少对inplace的解释。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done tks

Args:
model(paddle.nn.Layer): The model to be quantized.
Returns:
None
Copy link
Contributor

Choose a reason for hiding this comment

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

如果inplace == False的话,是不是return一个model比较好?

我看最后一行有return model,这里需要更新下。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done tks

assert isinstance(model, paddle.nn.Layer), \
"The model must be the instance of paddle.nn.Layer."

if not inplace:
Copy link
Contributor

Choose a reason for hiding this comment

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

什么情况下需要inplace==False呢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果需要保留原始输入FP32模型,用于和量化模型进行对比精度,可以直接设置inplace=False


hook = ptq_hooks.quant_forward_post_hook
hook_handle = layer.register_forward_post_hook(hook)
quant_config.hook_handle = hook_handle
Copy link
Contributor

Choose a reason for hiding this comment

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

后续会不会添加更多的hook?所以hook_handle这个名字是不是可以叫『quant_forward_post_hook』?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

hook = ptq_hooks.quant_forward_post_hook
hook_handle = layer.register_forward_post_hook(hook)
quant_config.hook_handle = hook_handle
layer._forward_post_hooks.move_to_end(
Copy link
Contributor

Choose a reason for hiding this comment

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

在调用统计激活的hook之前,有没有对weight做量化操作?

The PTQ config shows how to quantize the inputs and outputs.
"""

def __init__(self, activation_quantizer, weight_quantizer):
Copy link
Contributor

Choose a reason for hiding this comment

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

请补充参数说明文档。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return expanded_quantized_bins


def safe_entropy(reference_distr_P, P_sum, candidate_distr_Q, Q_sum):
Copy link
Contributor

Choose a reason for hiding this comment

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

这些方法在静态图PTQ中没被用到么?不能直接复用?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,288 @@
# copyright (c) 2018 paddlepaddle authors. all rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

2018->2021

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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.

4 participants