Created by: pangyoki
PR types
Others
PR changes
APIs
Describe
reason for test_distribution failure
-
Because
assign
op does not support the input of numpy.ndarray whose dtype isFP64
. When users setFP64 numpy.ndarray
as the parameters ofUniform
andNormal
classes. We need to useassign
op to convert it toFP32 Tensor
. And then usecast
op 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)
. iflow
andhigh
are very close,high - low
will 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