Created by: pangyoki
PR types
Others
PR changes
APIs
Describe
reason for test_distribution failure
-
Because
assignop does not support the input of numpy.ndarray whose dtype isFP64. When users setFP64 numpy.ndarrayas the parameters ofUniformandNormalclasses. We need to useassignop to convert it toFP32 Tensor. And then usecastop to convert it to aFP64 Tensor. There is a loss of accuracy in this conversion. Refer to PR https://github.com/PaddlePaddle/Paddle/pull/26767 . -
In test_distribution, compare the output of paddle and output of numpy to verify the correction. In
Uniform(low, high), the formula to calculate the entropy isentropy(low, high) = log (high - low). iflowandhighare very close,high - lowwill be close to0, and small precision loss will become large error because of usinglog.
solution
In the realization of the original Uniform unittest, the range of low is [-1, 1), the range of high is [-5, 5).
To avoid low and high being too close, set low in the range of [-1, 1), and set high in range of [5, 15).
What's more, add a unittest to discuss the situation that high < low.
log_prob unittest of Normal class also fails, change the tolerance from 1e-6 to 1e-4.
tolerance: 1e-6 -> 1e-4