-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Dygraph post trainging quantization #33445
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
Conversation
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 for set_tests_properties
|
||
class ImperativePTQ(object): | ||
""" | ||
Applying static post_training quantization to the dgraph model. |
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.
有没有更专业的词来表示dgraph model
?
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.
直接默认是model吧~~
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. |
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.
这些参数并没有出现在__init__参数列表中。
另外,需要详细说明下默认情况下input和weight各用的是什么quantizer。
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.
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. |
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.
缺少对inplace
的解释。
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.
Done tks
Args: | ||
model(paddle.nn.Layer): The model to be quantized. | ||
Returns: | ||
None |
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.
如果inplace == False
的话,是不是return一个model比较好?
我看最后一行有return model,这里需要更新下。
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.
Done tks
assert isinstance(model, paddle.nn.Layer), \ | ||
"The model must be the instance of paddle.nn.Layer." | ||
|
||
if not inplace: |
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.
什么情况下需要inplace==False呢
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.
如果需要保留原始输入FP32模型,用于和量化模型进行对比精度,可以直接设置inplace=False
|
||
hook = ptq_hooks.quant_forward_post_hook | ||
hook_handle = layer.register_forward_post_hook(hook) | ||
quant_config.hook_handle = hook_handle |
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.
后续会不会添加更多的hook?所以hook_handle
这个名字是不是可以叫『quant_forward_post_hook』?
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.
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( |
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.
在调用统计激活的hook之前,有没有对weight做量化操作?
The PTQ config shows how to quantize the inputs and outputs. | ||
""" | ||
|
||
def __init__(self, activation_quantizer, weight_quantizer): |
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.
请补充参数说明文档。
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.
Done
return expanded_quantized_bins | ||
|
||
|
||
def safe_entropy(reference_distr_P, P_sum, candidate_distr_Q, Q_sum): |
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.
这些方法在静态图PTQ中没被用到么?不能直接复用?
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.
Done
@@ -0,0 +1,288 @@ | |||
# copyright (c) 2018 paddlepaddle authors. all rights reserved. |
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.
2018->2021
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.
Done
PR types
New features
PR changes
Others
Describe
Dygraph post trainging quantization