From ab37c8e9a1f05e4593ccefccf74089d17e0def89 Mon Sep 17 00:00:00 2001 From: Shijie <505749828@qq.com> Date: Tue, 9 Aug 2022 19:23:31 +0800 Subject: [PATCH] Fix random seed for test_distribution_* UTs (#45003) --- .../unittests/distribution/test_distribution_beta_static.py | 1 + .../unittests/distribution/test_distribution_categorical.py | 2 ++ .../unittests/distribution/test_distribution_constraint.py | 2 ++ .../unittests/distribution/test_distribution_dirichlet.py | 2 ++ .../distribution/test_distribution_dirichlet_static.py | 1 + .../unittests/distribution/test_distribution_expfamily.py | 2 ++ .../distribution/test_distribution_expfamily_static.py | 1 + .../unittests/distribution/test_distribution_independent.py | 2 ++ .../distribution/test_distribution_independent_static.py | 1 + .../tests/unittests/distribution/test_distribution_normal.py | 2 ++ .../unittests/distribution/test_distribution_transform.py | 3 +++ .../distribution/test_distribution_transform_static.py | 2 ++ .../tests/unittests/distribution/test_distribution_uniform.py | 2 ++ .../tests/unittests/distribution/test_distribution_variable.py | 2 ++ python/paddle/fluid/tests/unittests/distribution/test_kl.py | 2 ++ .../fluid/tests/unittests/distribution/test_kl_static.py | 2 ++ 16 files changed, 29 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_beta_static.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_beta_static.py index 83b66f5c2b2..6fa6b276929 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_beta_static.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_beta_static.py @@ -23,6 +23,7 @@ import parameterize as param from config import ATOL, RTOL from parameterize import xrand +np.random.seed(2022) paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_categorical.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_categorical.py index 24c21d1bd45..741fcab0438 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_categorical.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_categorical.py @@ -23,6 +23,8 @@ from paddle.fluid import layers from test_distribution import DistributionNumpy +np.random.seed(2022) + class CategoricalNumpy(DistributionNumpy): diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_constraint.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_constraint.py index b927aef8e9b..d061576c836 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_constraint.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_constraint.py @@ -21,6 +21,8 @@ from paddle.distribution import constraint import config import parameterize as param +np.random.seed(2022) + @param.param_cls((param.TEST_CASE_NAME, 'value'), [('NotImplement', np.random.rand(2, 3))]) diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet.py index 8188b2231f2..9645598d964 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet.py @@ -22,6 +22,8 @@ import config from config import ATOL, DEVICES, RTOL import parameterize as param +np.random.seed(2022) + @param.place(DEVICES) @param.param_cls( diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet_static.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet_static.py index c4630bbd84b..66103e4a917 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet_static.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_dirichlet_static.py @@ -21,6 +21,7 @@ import scipy.stats from config import ATOL, DEVICES, RTOL from parameterize import TEST_CASE_NAME, parameterize_cls, place, xrand +np.random.seed(2022) paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily.py index cc4b8430913..a1fea64f165 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily.py @@ -22,6 +22,8 @@ import config import mock_data as mock import parameterize +np.random.seed(2022) + @parameterize.place(config.DEVICES) @parameterize.parameterize_cls( diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily_static.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily_static.py index 63f1fa81bf1..a2ebaca46a8 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily_static.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_expfamily_static.py @@ -22,6 +22,7 @@ import config import mock_data as mock import parameterize +np.random.seed(2022) paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent.py index 4f0639a0380..036d621f5c6 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent.py @@ -21,6 +21,8 @@ import scipy.stats import config import parameterize as param +np.random.seed(2022) + @param.place(config.DEVICES) @param.param_cls( diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent_static.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent_static.py index e0196ecbf13..950e137be1d 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent_static.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_independent_static.py @@ -21,6 +21,7 @@ import scipy.stats import config import parameterize as param +np.random.seed(2022) paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_normal.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_normal.py index 9e597c3d363..5023905caa7 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_normal.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_normal.py @@ -23,6 +23,8 @@ from paddle.fluid import layers from test_distribution import DistributionNumpy +np.random.seed(2022) + class NormalNumpy(DistributionNumpy): diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform.py index 8311a10f4d5..7f179ca5728 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform.py @@ -22,6 +22,9 @@ from paddle.distribution import constraint, transform, variable import config import parameterize as param +np.random.seed(2022) +paddle.seed(2022) + @param.place(config.DEVICES) class TestTransform(unittest.TestCase): diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform_static.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform_static.py index 00a1f409dad..0375bc22921 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform_static.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_transform_static.py @@ -21,6 +21,8 @@ from paddle.distribution import transform, variable, constraint import config import parameterize as param +np.random.seed(2022) +paddle.seed(2022) paddle.enable_static() diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_uniform.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_uniform.py index 3fbb382a240..c592e53e9be 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_uniform.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_uniform.py @@ -23,6 +23,8 @@ from paddle.fluid import layers from test_distribution import DistributionNumpy +np.random.seed(2022) + class UniformNumpy(DistributionNumpy): diff --git a/python/paddle/fluid/tests/unittests/distribution/test_distribution_variable.py b/python/paddle/fluid/tests/unittests/distribution/test_distribution_variable.py index 94558395e00..b0b8e8fd6fd 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_distribution_variable.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_distribution_variable.py @@ -22,6 +22,8 @@ from paddle.distribution import constraint import config import parameterize as param +paddle.seed(2022) + @param.param_cls( (param.TEST_CASE_NAME, 'is_discrete', 'event_rank', 'constraint'), diff --git a/python/paddle/fluid/tests/unittests/distribution/test_kl.py b/python/paddle/fluid/tests/unittests/distribution/test_kl.py index 0a957c540be..6c00a6a3273 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_kl.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_kl.py @@ -25,6 +25,8 @@ import config import mock_data as mock import parameterize as param +np.random.seed(2022) +paddle.seed(2022) paddle.set_default_dtype('float64') diff --git a/python/paddle/fluid/tests/unittests/distribution/test_kl_static.py b/python/paddle/fluid/tests/unittests/distribution/test_kl_static.py index 3bd62e1334b..b62a51c7366 100644 --- a/python/paddle/fluid/tests/unittests/distribution/test_kl_static.py +++ b/python/paddle/fluid/tests/unittests/distribution/test_kl_static.py @@ -25,6 +25,8 @@ import config import parameterize as param import mock_data as mock +np.random.seed(2022) +paddle.seed(2022) paddle.enable_static() -- GitLab