KEMBAR78
[API Compatibility] add `out` parameter to `sqrt` by aquagull · Pull Request #74795 · PaddlePaddle/Paddle · GitHub
Skip to content

Conversation

@aquagull
Copy link
Contributor

@aquagull aquagull commented Aug 20, 2025

PR Category

User Experience

PR Types

Others

Description

  1. sqrt 下沉至C++层,不再兼容老IR。
  2. 删除了依赖sqrt的老IR单测。

cc @wanghuancoder @zhwesky2010
pcard-71500

@paddle-bot
Copy link

paddle-bot bot commented Aug 20, 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.

@aquagull aquagull marked this pull request as ready for review August 21, 2025 08:54
@aquagull
Copy link
Contributor Author

/re-run all-failed

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.

这个删的单测都是老IR下的吧

@aquagull
Copy link
Contributor Author

aquagull commented Aug 22, 2025

这个删的单测都是老IR下的吧

是的,单测是根据之前ci报错删的,deprecated后缀的单测文件是直接删去了,没有deprecated后缀的文件我是只删除老IR单测的。

@aquagull
Copy link
Contributor Author

/re-run all-failed

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.

这个是不是没有加单测,覆盖率没过呢

@aquagull aquagull requested a review from zhwesky2010 August 25, 2025 06:37
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.

这个加了test_sqrt 单测吗,不加的话会影响覆盖率过不了

Comment on lines 5643 to 5695
class TestSqrtOutAPI(unittest.TestCase):
def test_out_in_dygraph(self):
paddle.disable_static()
np.random.seed(2024)
x = paddle.to_tensor(
np.random.rand(5, 7).astype('float32'), stop_gradient=False
)

def run_case(case_type):
out_buf = paddle.zeros_like(x)
out_buf.stop_gradient = False

if case_type == 'return':
y = paddle.sqrt(x)
elif case_type == 'input_out':
paddle.sqrt(x, out=out_buf)
y = out_buf
elif case_type == 'both_return':
y = paddle.sqrt(x, out=out_buf)
elif case_type == 'both_input_out':
_ = paddle.sqrt(x, out=out_buf)
y = out_buf
else:
raise AssertionError

ref = paddle._C_ops.sqrt(x)
np.testing.assert_allclose(
y.numpy(), ref.numpy(), rtol=1e-6, atol=1e-6
)

loss = (y * 2).mean()
loss.backward()
return y.numpy(), x.grad.numpy()

# run four scenarios
y1, g1 = run_case('return')
x.clear_gradient()
y2, g2 = run_case('input_out')
x.clear_gradient()
y3, g3 = run_case('both_return')
x.clear_gradient()
y4, g4 = run_case('both_input_out')

np.testing.assert_allclose(y1, y2, rtol=1e-6, atol=1e-6)
np.testing.assert_allclose(y1, y3, rtol=1e-6, atol=1e-6)
np.testing.assert_allclose(y1, y4, rtol=1e-6, atol=1e-6)
np.testing.assert_allclose(g1, g2, rtol=1e-6, atol=1e-6)
np.testing.assert_allclose(g1, g3, rtol=1e-6, atol=1e-6)
np.testing.assert_allclose(g1, g4, rtol=1e-6, atol=1e-6)

paddle.enable_static()


Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zhwesky2010 已经加了单测的。

zhwesky2010
zhwesky2010 previously approved these changes Aug 26, 2025
@zhwesky2010 zhwesky2010 requested review from SigureMo and zyfncg August 26, 2025 04:07
create_test_zero_size_class(TestSilu)
create_test_zero_size_class(TestReciprocal)
create_test_zero_size_class(TestSquare)
create_test_zero_size_class(TestSqrt)
Copy link
Member

@SigureMo SigureMo Aug 26, 2025

Choose a reason for hiding this comment

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

@DanielSun11 看看这里删掉合理么?我看是两个月前 #72821 刚加的

Copy link
Contributor

Choose a reason for hiding this comment

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

建议不删。改一下TestSqrt中的check_prim=True 绕过对老静态图的检查

Copy link
Member

Choose a reason for hiding this comment

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

这几个非 _deprecated 的单测,我看了下 #67640,看起来删掉是合理的,PIR 下不再是这种写法了

这里没问题,只是 NOTE 下

Copy link
Contributor

Choose a reason for hiding this comment

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

可以将 class TestSqrt(TestActivation, TestParameter):中的check_prim=True 改成False 而并非直接删除单测

create_test_zero_size_class(TestSilu)
create_test_zero_size_class(TestReciprocal)
create_test_zero_size_class(TestSquare)
create_test_zero_size_class(TestSqrt)
Copy link
Contributor

Choose a reason for hiding this comment

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

建议不删。改一下TestSqrt中的check_prim=True 绕过对老静态图的检查

F.mish(x_fp16)


class TestSqrtOutAPI(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

需要加一下torch参数别名的单测,验证下动态图和静态图是否支持别名功能

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, 已补充动静态图下的torch别名测试;create_test_zero_size_class(TestSqrt)已恢复,并更改TestSqrtcheck_prim=False

@zhwesky2010 zhwesky2010 self-requested a review August 26, 2025 07:25
zhwesky2010
zhwesky2010 previously approved these changes Aug 26, 2025
@zhwesky2010
Copy link
Contributor

@aquagull CI挂了,删了单测没过,看下CI尽快修复。

@zhwesky2010 zhwesky2010 self-requested a review August 26, 2025 11:32
zyfncg
zyfncg previously approved these changes Aug 26, 2025
@zhwesky2010 zhwesky2010 requested a review from zyfncg August 26, 2025 11:42
@aquagull aquagull dismissed stale reviews from zyfncg and zhwesky2010 via f9a84b0 August 26, 2025 12:00
@aquagull
Copy link
Contributor Author

@aquagull CI挂了,删了单测没过,看下CI尽快修复。

done

@DanielSun11
Copy link
Contributor

class TestSqrt(TestActivation, TestParameter):中的所有的check_prim改成False呀。不然会继续运行老动态图

@aquagull
Copy link
Contributor Author

class TestSqrt(TestActivation, TestParameter):中的所有的check_prim改成False呀。不然会继续运行老动态图

这个合入的pr更改了,我这里已经merge了这个。

@aquagull
Copy link
Contributor Author

/re-run all-failed

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 for deleting UT

@aquagull
Copy link
Contributor Author

/re-run all-failed

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@80e69d8). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #74795   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         1           
  Lines              ?         1           
  Branches           ?         0           
===========================================
  Hits               ?         1           
  Misses             ?         0           
  Partials           ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aquagull
Copy link
Contributor Author

/re-run all-failed

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

@zhwesky2010 zhwesky2010 merged commit 348fa91 into PaddlePaddle:develop Aug 27, 2025
228 of 249 checks passed
@aquagull aquagull deleted the sqrt branch September 12, 2025 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants