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

fix the precision problem of test_distribution #27524

Merged
merged 5 commits into from
Sep 29, 2020

Conversation

pangyoki
Copy link
Contributor

@pangyoki pangyoki commented Sep 23, 2020

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 is FP64.
    When users set FP64 numpy.ndarray as the parameters of Uniform and Normal classes. We need to use assign op to convert it to FP32 Tensor. And then use cast op to convert it to a FP64 Tensor.
    There is a loss of accuracy in this conversion.
    Refer to PR fix dtype not matching bug in log_prob and probs method of Distribution class #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 is entropy(low, high) = log (high - low).
    if low and high are very close, high - low will be close to 0, and small precision loss will become large error because of using log.

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

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@pangyoki pangyoki changed the title increase tolerance of test_distribution fix test_distribution by increasing tolerance Sep 24, 2020
@pangyoki pangyoki changed the title fix test_distribution by increasing tolerance fix the precision problem of test_distribution Sep 27, 2020
@zhiqiu zhiqiu merged commit 90eb554 into PaddlePaddle:develop Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants