Skip to content
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

Merged
merged 3 commits into from
Feb 3, 2023

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Jan 21, 2023

@paddle-bot
Copy link

paddle-bot bot commented Jan 21, 2023

你的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.

Comment on lines 80 to 83

if x.size == 0:
raise ValueError("input size should not be 0")

Copy link
Contributor

Choose a reason for hiding this comment

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

这个判断应放在C++中进行。如果放在python端,在动态图下会影响到API性能~

Copy link
Member Author

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)

Comment on lines 1 to 37
# 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()
Copy link
Contributor

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下即可。

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1
Copy link
Contributor

luotao1 commented Feb 1, 2023

请解决下Mac流水线中单测失败的问题

2023-02-01 01:59:21             	895 - test_normalize (Failed)

@gouzil
Copy link
Member Author

gouzil commented Feb 1, 2023

请解决下Mac流水线中单测失败的问题

2023-02-01 01:59:21             	895 - test_normalize (Failed)

done

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1 luotao1 merged commit 620ce8b into PaddlePaddle:develop Feb 3, 2023
@gouzil gouzil deleted the fix-normalize-divide-by-0 branch February 28, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants