-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[API Compatibility] add out parameter to sqrt
#74795
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
|
你的PR提交成功,感谢你对开源项目的贡献! |
|
/re-run all-failed |
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.
这个删的单测都是老IR下的吧
是的,单测是根据之前ci报错删的, |
|
/re-run all-failed |
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.
这个加了test_sqrt 单测吗,不加的话会影响覆盖率过不了
| 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() | ||
|
|
||
|
|
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.
@zhwesky2010 已经加了单测的。
| create_test_zero_size_class(TestSilu) | ||
| create_test_zero_size_class(TestReciprocal) | ||
| create_test_zero_size_class(TestSquare) | ||
| create_test_zero_size_class(TestSqrt) |
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.
@DanielSun11 看看这里删掉合理么?我看是两个月前 #72821 刚加的
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.
建议不删。改一下TestSqrt中的check_prim=True 绕过对老静态图的检查
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.
这几个非 _deprecated 的单测,我看了下 #67640,看起来删掉是合理的,PIR 下不再是这种写法了
这里没问题,只是 NOTE 下
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.
可以将 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) |
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.
建议不删。改一下TestSqrt中的check_prim=True 绕过对老静态图的检查
| F.mish(x_fp16) | ||
|
|
||
|
|
||
| class TestSqrtOutAPI(unittest.TestCase): |
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.
需要加一下torch参数别名的单测,验证下动态图和静态图是否支持别名功能
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, 已补充动静态图下的torch别名测试;create_test_zero_size_class(TestSqrt)已恢复,并更改TestSqrt的check_prim=False
|
@aquagull CI挂了,删了单测没过,看下CI尽快修复。 |
done |
|
class TestSqrt(TestActivation, TestParameter):中的所有的check_prim改成False呀。不然会继续运行老动态图 |
这个合入的pr更改了,我这里已经merge了这个。 |
|
/re-run all-failed |
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 deleting UT
|
/re-run all-failed |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
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
PR Category
User Experience
PR Types
Others
Description
sqrt下沉至C++层,不再兼容老IR。sqrt的老IR单测。cc @wanghuancoder @zhwesky2010
pcard-71500