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

Add intepolte_v2 for Paddle2.0 #26520

Merged
merged 16 commits into from
Aug 27, 2020
Merged

Conversation

tink2123
Copy link
Contributor

@tink2123 tink2123 commented Aug 21, 2020

PR types

Performance optimization

PR changes

APIs

Describe

Update interpolate API

  • Support list in scale_factor
  • Modify parameter default values

新增interpolate_v2 原因:
修改了scale_factor参数的类型,没有办法和之前的OP做到兼容。旧的模型参数无法被新的OP加载,因此增加一个V2 版本。

@paddle-bot-old
Copy link

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

input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = round(H_{in} * scale_{factor})
W_out = round(W_{in} * scale_{factor})

Bilinear interpolation:
Copy link
Contributor

Choose a reason for hiding this comment

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

remove :alias from docstring

Copy link
Contributor

Choose a reason for hiding this comment

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

Variable -> Tensor

Copy link
Contributor

Choose a reason for hiding this comment

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

update code samples to 2.0 API

@@ -327,7 +322,10 @@ def interpolate(input,

if align_mode != 0 and align_mode != 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

add fast path for dygraph mode

@@ -327,7 +322,10 @@ def interpolate(input,

if align_mode != 0 and align_mode != 1:
raise ValueError("align_mode can only be 0 or 1")

if align_corners != 0 and resample == 'NEAREST':
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

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

also enforce in v2 op.

else:
raise TypeError(
"Attr(scale)'s type should be float, int or Variable.")

"Attr(scale)'s type should be float, int, list or Variable.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable -> Tensor

https://en.wikipedia.org/wiki/Trilinear_interpolation.

Parameters:
input (Variable): 3-D, 4-D or 5-D Tensor, its data type is float32, float64, or uint8,
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable

.. code-block:: python
import paddle
import numpy as np
import paddle.fluid.dygraph as dg
Copy link
Contributor

Choose a reason for hiding this comment

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

update to 2.0 API

This op upsamples a batch of images, using nearest neighbours' pixel values.
The input must be a 4-D Tensor of the shape (num_batches, channels, in_h, in_w),
and the upsampling only applies on the two dimensions(height and width).
**Warning:** the parameter :attr:`actual_shape` will be deprecated in the
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

# [2L, 3L, 12L, 12L]
"""

def __init__(self, size=None, scale_factor=None, data_format='NCHW'):
Copy link
Contributor

Choose a reason for hiding this comment

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

name

self.mode = mode.lower()
self.data_format = data_format

def forward(self, input):
Copy link
Contributor

Choose a reason for hiding this comment

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

input -> x

inputs=inputs,
outputs={"Out": out},
attrs=attrs)
return out


def upsample(input,
Copy link
Contributor

Choose a reason for hiding this comment

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

input -> x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Above problems has been fixed, please review again


input_data = np.random.rand(2,3,6,10).astype("float32")
x = paddle.to_tensor(input_data)
output = F.interpolate(x=x, size=[12,12])
Copy link
Contributor

Choose a reason for hiding this comment

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

是否需要多举个例子说明不同mode的区别

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~ thx!

interpolating functions of three variables (e.g. D-direction,
H-direction and W-direction in this op) on a rectilinear 3D grid.
The linear interpolation is performed on three directions.
Align_corners and align_mode are optional parameters,the calculation method
Copy link
Contributor

Choose a reason for hiding this comment

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

Align -> align

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, thx~

jzhang533
jzhang533 previously approved these changes Aug 25, 2020
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

lgtm

willthefrog
willthefrog previously approved these changes Aug 25, 2020
@willthefrog willthefrog self-requested a review August 25, 2020 11:30
@tink2123 tink2123 dismissed stale reviews from willthefrog and jzhang533 via 0e003f2 August 25, 2020 11:51
Copy link
Contributor

@willthefrog willthefrog left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1
Copy link
Contributor

luotao1 commented Aug 27, 2020

2020-08-27 14:24:06 1. It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 (Recommend) or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py, which manages the white list of upgrading the precision of op test to float64. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. 
2020-08-27 14:24:06 2. It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_threshold_white_list.py, which manages the white list of error threshold for op test with float64 precision. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. 
2020-08-27 14:24:06 5. Please use the default precision parameters of 'atol, rtol, eps, max_relative_error'. If you don't use the default value, you must have one RD (Xreki (Recommend), luotao1, lanxianghit or phlrain) approval for the usage of other values. The detailed information is in the link: https://github.cor/PaddlePaddle/Paddle/wiki/OP-test-accuracy-requirements. The error line is 
2020-08-27 14:24:06 +            self.check_output(atol=1e-7)
2020-08-27 14:24:06 +            self.check_output(atol=1e-5)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 +            self.check_output_with_place(place=core.CPUPlace(), atol=1e-7)
2020-08-27 14:24:06 +            self.check_output_with_place(place=core.CPUPlace(), atol=1e-5)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 There are 6 approved errors.
2020-08-27 14:24:06 ****************

@XiaoguangHu01 @lanxianghit 因为这个OP不符合精度规范,请问可以豁免么?
@tink2123 可以说下原因

@tink2123
Copy link
Contributor Author

2020-08-27 14:24:06 1. It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 (Recommend) or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py, which manages the white list of upgrading the precision of op test to float64. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. 
2020-08-27 14:24:06 2. It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_threshold_white_list.py, which manages the white list of error threshold for op test with float64 precision. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. 
2020-08-27 14:24:06 5. Please use the default precision parameters of 'atol, rtol, eps, max_relative_error'. If you don't use the default value, you must have one RD (Xreki (Recommend), luotao1, lanxianghit or phlrain) approval for the usage of other values. The detailed information is in the link: https://github.cor/PaddlePaddle/Paddle/wiki/OP-test-accuracy-requirements. The error line is 
2020-08-27 14:24:06 +            self.check_output(atol=1e-7)
2020-08-27 14:24:06 +            self.check_output(atol=1e-5)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 +            self.check_output_with_place(place=core.CPUPlace(), atol=1e-7)
2020-08-27 14:24:06 +            self.check_output_with_place(place=core.CPUPlace(), atol=1e-5)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 There are 6 approved errors.
2020-08-27 14:24:06 ****************

@XiaoguangHu01 @lanxianghit 因为这个OP不符合精度规范,请问可以豁免么?
@tink2123 可以说下原因

这个问题应该是因为 numpy 和 c++ 在非整数计算插值的时候精度达不到要求。这次没有改旧的OP,之前的版本一直就在白名单里,新版本也需要加上才能过单测。对比过pytorch和paddle的输出结果,精度误差在1e-6可以对齐。

@XiaoguangHu01
Copy link
Contributor

2020-08-27 14:24:06 1. It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 (Recommend) or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_accuracy_white_list.py, which manages the white list of upgrading the precision of op test to float64. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. 
2020-08-27 14:24:06 2. It is an Op accuracy problem, please take care of it. You must have one RD (juncaipeng (Recommend), zhangting2020 or luotao1) approval for the python/paddle/fluid/tests/unittests/white_list/op_threshold_white_list.py, which manages the white list of error threshold for op test with float64 precision. For more information, please refer to: https://github.com/PaddlePaddle/Paddle/wiki/Upgrade-OP-Precision-to-Float64. 
2020-08-27 14:24:06 5. Please use the default precision parameters of 'atol, rtol, eps, max_relative_error'. If you don't use the default value, you must have one RD (Xreki (Recommend), luotao1, lanxianghit or phlrain) approval for the usage of other values. The detailed information is in the link: https://github.cor/PaddlePaddle/Paddle/wiki/OP-test-accuracy-requirements. The error line is 
2020-08-27 14:24:06 +            self.check_output(atol=1e-7)
2020-08-27 14:24:06 +            self.check_output(atol=1e-5)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 +            self.check_output_with_place(place=core.CPUPlace(), atol=1e-7)
2020-08-27 14:24:06 +            self.check_output_with_place(place=core.CPUPlace(), atol=1e-5)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 +        self.check_output_with_place(place=core.CPUPlace(), atol=1)
2020-08-27 14:24:06 There are 6 approved errors.
2020-08-27 14:24:06 ****************

@XiaoguangHu01 @lanxianghit 因为这个OP不符合精度规范,请问可以豁免么?
@tink2123 可以说下原因

这个问题应该是因为 numpy 和 c++ 在非整数计算插值的时候精度达不到要求。这次没有改旧的OP,之前的版本一直就在白名单里,新版本也需要加上才能过单测。对比过pytorch和paddle的输出结果,精度误差在1e-6可以对齐。

确认可以先加入白名单。跟之前的op保持一致。@luotao1

Copy link
Collaborator

@raindrops2sea raindrops2sea left a comment

Choose a reason for hiding this comment

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

增补一个pr注释说明一下新增v2 op的考量。

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM

@ceci3 ceci3 merged commit 89d7d86 into PaddlePaddle:develop Aug 27, 2020
@tink2123 tink2123 changed the title add intepolte_v2 Add intepolte_v2 for Paddle2.0 Oct 19, 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.

None yet

8 participants