未验证 提交 00f32af3 编写于 作者: W Weilong Wu 提交者: GitHub

[Eager, Performance optimization] optimize isclose and allclose interface (#46221)

上级 27fe77bc
...@@ -393,12 +393,7 @@ def allclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=False, name=None): ...@@ -393,12 +393,7 @@ def allclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=False, name=None):
""" """
if in_dygraph_mode(): if in_dygraph_mode():
# NOTE(dev): Pass tol as Tensor to fix precision loss problem, because return _C_ops.allclose(x, y, rtol, atol, equal_nan)
# C++ backend will cast it into float32 if passing float from python.
as_tensor = lambda x: paddle.to_tensor(
[x], dtype='float64', place='cpu')
return _C_ops.allclose(x, y, as_tensor(rtol), as_tensor(atol),
equal_nan)
if _in_legacy_dygraph(): if _in_legacy_dygraph():
return _legacy_C_ops.allclose(x, y, 'rtol', str(rtol), 'atol', return _legacy_C_ops.allclose(x, y, 'rtol', str(rtol), 'atol',
str(atol), 'equal_nan', equal_nan) str(atol), 'equal_nan', equal_nan)
...@@ -998,11 +993,7 @@ def isclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=False, name=None): ...@@ -998,11 +993,7 @@ def isclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=False, name=None):
""" """
if in_dygraph_mode(): if in_dygraph_mode():
# NOTE(dev): Pass tol as Tensor to fix precision loss problem, because return _C_ops.isclose(x, y, rtol, atol, equal_nan)
# C++ backend will cast it into float32 if passing float from python.
as_tensor = lambda x: paddle.to_tensor(
[x], dtype='float64', place='cpu')
return _C_ops.isclose(x, y, as_tensor(rtol), as_tensor(atol), equal_nan)
if _in_legacy_dygraph(): if _in_legacy_dygraph():
return _legacy_C_ops.isclose(x, y, 'rtol', str(rtol), 'atol', str(atol), return _legacy_C_ops.isclose(x, y, 'rtol', str(rtol), 'atol', str(atol),
'equal_nan', equal_nan) 'equal_nan', equal_nan)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册