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

[dygraph qat] Refine saving output scale to infer program #31784

Merged
merged 9 commits into from
Mar 24, 2021

Conversation

juncaipeng
Copy link
Contributor

PR types

Others

PR changes

Others

Describe

Refine saving output scale to infer program

@paddle-bot-old
Copy link

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


# Note that, the items have priority in corresponding_dict
corresponding_dict = {
'conv2d_tranpose': [['conv2d_tranpose'], None],
Copy link
Contributor

Choose a reason for hiding this comment

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

conv2d_transpose 对应是两个Op:conv2d_transpose / depthwise_ conv2d_transpose

另外:应该是conv2d_transpose,而不是conv2d_tranpose

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

for key, value in corresponding_dict.items():
if key in scale_name:
return (op.type in value[0]) and \
(len(value) == 1 or value[1] is None or value[1](op))
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么要添加判断value[1] is None or value[1](op)呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果有必要,可以新增lambda函数来判断静态图op是否满足特定条件,目前这里仅仅使用了op的名字,所以默认都是None

'BatchNorm': paddle.nn.BatchNorm,
'BatchNorm2D': paddle.nn.BatchNorm2D,
'GroupNorm': paddle.nn.GroupNorm,
'InstanceNorm2D': paddle.nn.InstanceNorm2D,
Copy link
Contributor

Choose a reason for hiding this comment

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

静态图量化中并不支持Instance_norm等Op,那动态图中新增了对于这些Op的支持,静态图量化中也请一并加上

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

if not self._is_scale_op_matched(scale_name, op, global_block):
op_idx += 1
else:
weight_ops = ["conv2d", "depthwise_conv2d", "matmul"]
Copy link
Contributor

Choose a reason for hiding this comment

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

weight_ops中还需添加conv2d_transposedepthwise_conv2d_transpose

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

Copy link
Contributor Author

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

Done tks

if not self._is_scale_op_matched(scale_name, op, global_block):
op_idx += 1
else:
weight_ops = ["conv2d", "depthwise_conv2d", "matmul"]
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


# Note that, the items have priority in corresponding_dict
corresponding_dict = {
'conv2d_tranpose': [['conv2d_tranpose'], None],
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

for key, value in corresponding_dict.items():
if key in scale_name:
return (op.type in value[0]) and \
(len(value) == 1 or value[1] is None or value[1](op))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果有必要,可以新增lambda函数来判断静态图op是否满足特定条件,目前这里仅仅使用了op的名字,所以默认都是None

'BatchNorm': paddle.nn.BatchNorm,
'BatchNorm2D': paddle.nn.BatchNorm2D,
'GroupNorm': paddle.nn.GroupNorm,
'InstanceNorm2D': paddle.nn.InstanceNorm2D,
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

gfwm2013
gfwm2013 previously approved these changes Mar 23, 2021
Copy link
Contributor

@gfwm2013 gfwm2013 left a comment

Choose a reason for hiding this comment

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

LGTM

@juncaipeng juncaipeng merged commit 84a5513 into PaddlePaddle:develop Mar 24, 2021
@juncaipeng juncaipeng deleted the refine_calc_output_scale2 branch March 24, 2021 06:40
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