Skip to content

在Upsample和interpolate函数中加入recompute_scale_factor参数 #71997

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

Merged
merged 12 commits into from
Apr 22, 2025

Conversation

Qin-sx
Copy link
Contributor

@Qin-sx Qin-sx commented Mar 31, 2025

PR Category

User Experience

PR Types

Improvements

Description

Upsample参数实际调用了interpolate参数。
参考Pytorch,recompute_scale_factor为True时计算output size,然后重置scale参数。

API文档修改:PaddlePaddle/docs#7205
PaConvert修改:PaddlePaddle/PaConvert#567

Qin-sx added 2 commits March 31, 2025 16:39
	modified:   python/paddle/nn/functional/common.py
	modified:   python/paddle/nn/layer/common.py
	new file:   test/legacy_test/test_interp_recompute_scale_factor.py
	modified:   test/legacy_test/test_interp_recompute_scale_factor.py
Copy link

paddle-bot bot commented Mar 31, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Mar 31, 2025
Qin-sx added 2 commits March 31, 2025 21:41
	modified:   python/paddle/nn/functional/common.py
	modified:   python/paddle/nn/layer/common.py
@Qin-sx
Copy link
Contributor Author

Qin-sx commented Mar 31, 2025

对应文档修改

	modified:   test/legacy_test/CMakeLists.txt
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

paconvert也加下测试,在paconvert/tests目录,这个会和pytorch的运行结果作对比

@@ -493,6 +500,15 @@ def interpolate(
"align_corners option can only be set with the interpolating modes: linear | bilinear | bicubic | trilinear"
)

if (
recompute_scale_factor is not None
and recompute_scale_factor
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.

收到,已修改。

Qin-sx added 2 commits April 1, 2025 21:47
	modified:   test/legacy_test/test_interp_recompute_scale_factor.py
	modified:   python/paddle/nn/functional/common.py
@Qin-sx
Copy link
Contributor Author

Qin-sx commented Apr 1, 2025

PaConvert对应PR

@@ -493,6 +500,11 @@ def interpolate(
"align_corners option can only be set with the interpolating modes: linear | bilinear | bicubic | trilinear"
)

if recompute_scale_factor and size is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

这个放到下面的

if out_shape is not 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.

收到,已修改。

@@ -645,7 +657,7 @@ def _is_list_or_tuple_(data):
attrs['out_h'] = out_shape[1]
attrs['out_w'] = out_shape[2]

else:
elif scale is not None and recompute_scale_factor is not True:
Copy link
Contributor

Choose a reason for hiding this comment

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

分支逻辑梳理一下,是否是:

if out_shape is not None:
    pass
elif scale is not None:
    if recompute_scale_factor:
        pass
    else:
        pass
else:
    raise error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,已按此修改。

	modified:   python/paddle/nn/functional/common.py
@@ -550,8 +562,6 @@ def _is_list_or_tuple_(data):

out_shape = size
scale = scale_factor
if out_shape is not None and scale is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

这个为什么删除?

@@ -493,6 +500,11 @@ def interpolate(
"align_corners option can only be set with the interpolating modes: linear | bilinear | bicubic | trilinear"
)

if recompute_scale_factor and size is not None:
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.

抱歉,这个上面的看错了,已修改。

	modified:   python/paddle/nn/functional/common.py
@Qin-sx Qin-sx requested a review from zhwesky2010 April 8, 2025 14:14
@@ -833,6 +833,7 @@ set_tests_properties(test_multiprocess_dataloader_iterable_dataset_static
set_tests_properties(test_lstm_cudnn_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_stack_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_bilinear_interp_v2_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_interp_recompute_scale_factor PROPERTIES TIMEOUT 120)
Copy link
Contributor

Choose a reason for hiding this comment

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

这个耗时比较长,有办法精简下case缩短下时间不?

	modified:   test/legacy_test/CMakeLists.txt
	modified:   test/legacy_test/test_interp_recompute_scale_factor.py
Copy link
Contributor

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

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM
@Qin-sx 中文文档也同步修改

@Qin-sx
Copy link
Contributor Author

Qin-sx commented Apr 14, 2025

LGTM @Qin-sx 中文文档也同步修改

您好,中文文档应该已经修改了
PaddlePaddle/docs#7205

Copy link

paddle-ci-bot bot commented Apr 21, 2025

Sorry to inform you that 44860c7's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@luotao1
Copy link
Contributor

luotao1 commented Apr 21, 2025

请merge下develop,重新跑下CI

@luotao1 luotao1 merged commit 33912da into PaddlePaddle:develop Apr 22, 2025
38 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants