-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Divide by 0 Error] add normalize check #49977
[Divide by 0 Error] add normalize check #49977
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/nn/functional/norm.py
Outdated
|
||
if x.size == 0: | ||
raise ValueError("input size should not be 0") | ||
|
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.
这个判断应放在C++中进行。如果放在python端,在动态图下会影响到API性能~
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.
我看报错也在PNormKernel
内所以跟#49966 放在一起
--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
0 p_norm_ad_func(paddle::experimental::Tensor const&, float, int, float, bool, bool)
1 paddle::experimental::p_norm(paddle::experimental::Tensor const&, float, int, float, bool, bool)
2 void phi::PNormKernel<float, phi::CPUContext>(phi::CPUContext const&, phi::DenseTensor const&, float, int, float, bool, bool, phi::DenseTensor*)
3 Eigen::internal::TensorExecutor<Eigen::TensorAssignOp<Eigen::TensorReshapingOp<Eigen::DSizes<int, 2> const, Eigen::TensorMap<Eigen::Tensor<float, 1, 1, long>, 0, Eigen::MakePointer> >, Eigen::TensorCwiseUnaryOp<Eigen::internal::bind2nd_op<Eigen::internal::scalar_pow_op<float, float> >, Eigen::TensorReductionOp<Eigen::internal::SumReducer<float>, Eigen::DSizes<int, 1> const, Eigen::TensorCwiseUnaryOp<Eigen::internal::bind2nd_op<Eigen::internal::scalar_pow_op<float, float> >, Eigen::TensorCwiseUnaryOp<Eigen::internal::scalar_abs_op<float const>, Eigen::TensorReshapingOp<Eigen::DSizes<int, 3> const, Eigen::TensorMap<Eigen::Tensor<float const, 1, 1, long>, 0, Eigen::MakePointer> const> const> const> const, Eigen::MakePointer> const> const> const, Eigen::DefaultDevice, true, (Eigen::internal::TiledEvaluation)0>::run(Eigen::TensorAssignOp<Eigen::TensorReshapingOp<Eigen::DSizes<int, 2> const, Eigen::TensorMap<Eigen::Tensor<float, 1, 1, long>, 0, Eigen::MakePointer> >, Eigen::TensorCwiseUnaryOp<Eigen::internal::bind2nd_op<Eigen::internal::scalar_pow_op<float, float> >, Eigen::TensorReductionOp<Eigen::internal::SumReducer<float>, Eigen::DSizes<int, 1> const, Eigen::TensorCwiseUnaryOp<Eigen::internal::bind2nd_op<Eigen::internal::scalar_pow_op<float, float> >, Eigen::TensorCwiseUnaryOp<Eigen::internal::scalar_abs_op<float const>, Eigen::TensorReshapingOp<Eigen::DSizes<int, 3> const, Eigen::TensorMap<Eigen::Tensor<float const, 1, 1, long>, 0, Eigen::MakePointer> const> const> const> const, Eigen::MakePointer> const> const> const&, Eigen::DefaultDevice const&)
----------------------
Error Message Summary:
----------------------
FatalError: `Erroneous arithmetic operation` is detected by the operating system.
[TimeInfo: *** Aborted at 1675180076 (unix time) try "date -d @1675180076" if you are using GNU date ***]
[SignalInfo: *** SIGFPE (@0x7f16555110ef) received by PID 26694 (TID 0x7f165b2e9740) from PID 1431376111 ***]
Floating point exception (core dumped)
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
import numpy as np | ||
|
||
import paddle | ||
|
||
|
||
class TestSparseEmbeddingAPIError(unittest.TestCase): | ||
def test_errors(self): | ||
with paddle.fluid.dygraph.guard(): | ||
# The size of input in sparse_embedding should not be 0. | ||
def test_0_size(): | ||
array = np.array([], dtype=np.float32) | ||
x = paddle.to_tensor( | ||
np.reshape(array, [1, 1, 0]), dtype='float32' | ||
) | ||
paddle.nn.functional.normalize(x) | ||
|
||
self.assertRaises(ValueError, test_0_size) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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.
这个单测不需要新建文件。放到python/paddle/fluid/tests/unittests/test_normalize.py下即可。
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
请解决下Mac流水线中单测失败的问题
|
done |
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 types
Others
PR changes
Others
Describe