Repository navigation
【Hackathon 6th No. 7】Add sinc / sinc_ API to Paddle -part - #63521
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
| Returns: | ||
| out (Tensor): The Tensor of elementwise computed normalized sinc result. | ||
| """ | ||
| if not isinstance(x, (paddle.Tensor, Variable, paddle.pir.Value)): |
There was a problem hiding this comment.
propose adding dtype judgment, also adding in test_sinc.py.
| if not isinstance(x, (paddle.Tensor, Variable, paddle.pir.Value)): | ||
| raise TypeError(f"x must be tensor type, but got {type(x)}") | ||
|
|
||
| if x.dtype not in [ |
There was a problem hiding this comment.
maybe you can use "check_variable_and_dtype", this will make your code look more concise.
|
The CI-Coverage check for python code included the last two line of signbit API accidentally. |
| signbit, | ||
| sin, | ||
| sin_, | ||
| sinc, |
There was a problem hiding this comment.
also add it in the list of all
| res = paddle.sinc(x) | ||
| static_result = exe.run(feed={'x': x_data}, fetch_list=[res])[0] | ||
|
|
||
| def test_inplace(self): |
There was a problem hiding this comment.
the type error of inplace API also should be test.
| 'sinh_', | ||
| 'round', | ||
| 'sinc', | ||
| 'sinc_' 'round', |
| check_variable_and_dtype( | ||
| x, | ||
| "x", | ||
| [ |
There was a problem hiding this comment.
should we support bfloat16?
| "sinc", | ||
| ) | ||
|
|
||
| tmp = paddle.where(x != 0, x, paddle.full_like(x, 1.0e-20)) |
There was a problem hiding this comment.
why use 1.0e-20, if data type of x is float16, will there be underflow?
There was a problem hiding this comment.
1.0e-20 is used in numpy.sinc, but there is underflow problem when data type is float16.
Fixed the problem using paddle.isnan before returning the final value.
There was a problem hiding this comment.
Can we support backward gradient calculation, especially when x=0?
There was a problem hiding this comment.
shall we add test case for calculating gradient
There was a problem hiding this comment.
shall we add test case for calculating gradient
I will add it
There was a problem hiding this comment.
Can we support backward gradient calculation, especially when x=0?
when x=0,the gradient should be 0:
by LHopital's rule,
The torch example:
x = torch.rand(2,3)
x[0,0] = 0.0
x.requires_grad = True
s = torch.sinc(x).sum()
s.backward()
x.grad
# tensor([[ 0.0000, -1.2824, -1.0302],
# [-1.3687, -1.0435, -1.1842]])The current implementation using paddle.where can return gradient value 0 if x = 0
| check_variable_and_dtype( | ||
| x, | ||
| "x", | ||
| [ |
There was a problem hiding this comment.
should we support bfloat16?
| "sinc_", | ||
| ) | ||
|
|
||
| paddle.where_(x != 0, x, paddle.full_like(x, 1.0e-20)) |
There was a problem hiding this comment.
Fixed the problem using paddle.isnan before returning the final value.
@NKNaN 看下这里的覆盖率,如果本地单测有覆盖到,请截图贴上。
|
|
@NKNaN 看下这里的覆盖率,如果本地单测有覆盖到,请截图贴上。 这个是 isreal 的内容,不知道为啥这三行也会算到 coverage 检测里面 |
收到,已经豁免了 |

PR Category
User Experience
PR Types
New features
Description
Add sinc / sinc_ API to Paddle