diff --git a/test/dygraph_to_static/test_train_step.py b/test/dygraph_to_static/test_train_step.py index 36cff5a7f3990..2fbb8005e4ece 100644 --- a/test/dygraph_to_static/test_train_step.py +++ b/test/dygraph_to_static/test_train_step.py @@ -58,6 +58,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 5 + self.rtol = 1e-4 def get_train_step_losses(self, func, steps): losses = [] @@ -87,7 +88,9 @@ def test_train_step(self): for dygraph_loss, static_loss in zip(dygraph_losses, static_losses): dygraph_loss = dygraph_loss.numpy() static_loss = static_loss.numpy() - np.testing.assert_allclose(dygraph_loss, static_loss, rtol=1e-4) + np.testing.assert_allclose( + dygraph_loss, static_loss, rtol=self.rtol + ) class TestTrainStepTinyModelAdadelta(TestTrainStepTinyModel): @@ -99,6 +102,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelAdagrad(TestTrainStepTinyModel): @@ -110,6 +114,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelAdam(TestTrainStepTinyModel): @@ -121,6 +126,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelAdamax(TestTrainStepTinyModel): @@ -132,6 +138,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelAdamW(TestTrainStepTinyModel): @@ -143,6 +150,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLamb(TestTrainStepTinyModel): @@ -156,6 +164,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelMomentum(TestTrainStepTinyModel): @@ -167,6 +176,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelRMSProp(TestTrainStepTinyModel): @@ -178,6 +188,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRNoamDecay(TestTrainStepTinyModel): @@ -191,6 +202,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRPiecewiseDecay(TestTrainStepTinyModel): @@ -206,6 +218,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRNaturalExpDecay(TestTrainStepTinyModel): @@ -221,6 +234,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRInverseTimeDecay(TestTrainStepTinyModel): @@ -234,6 +248,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRPolynomialDecay(TestTrainStepTinyModel): @@ -250,6 +265,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRLinearWarmup(TestTrainStepTinyModel): @@ -267,6 +283,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRExponentialDecay(TestTrainStepTinyModel): @@ -280,6 +297,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRMultiStepDecay(TestTrainStepTinyModel): @@ -297,6 +315,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRStepDecay(TestTrainStepTinyModel): @@ -313,6 +332,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRLambdaDecay(TestTrainStepTinyModel): @@ -328,6 +348,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRReduceOnPlateau(TestTrainStepTinyModel): @@ -344,6 +365,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRCosineAnnealingDecay(TestTrainStepTinyModel): @@ -359,6 +381,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRMultiplicativeDecay(TestTrainStepTinyModel): @@ -374,6 +397,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLROneCycleLR(TestTrainStepTinyModel): @@ -387,6 +411,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 class TestTrainStepTinyModelLRCyclicLR(TestTrainStepTinyModel): @@ -404,6 +429,7 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 if __name__ == "__main__": diff --git a/test/dygraph_to_static/test_train_step_resnet18_adam.py b/test/dygraph_to_static/test_train_step_resnet18_adam.py index 8506349b43577..c8b34fe84f113 100644 --- a/test/dygraph_to_static/test_train_step_resnet18_adam.py +++ b/test/dygraph_to_static/test_train_step_resnet18_adam.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import platform import unittest from test_train_step import ( @@ -33,6 +34,9 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 + if platform.system() == 'Windows': + self.rtol = 1e-3 if __name__ == "__main__": diff --git a/test/dygraph_to_static/test_train_step_resnet18_sgd.py b/test/dygraph_to_static/test_train_step_resnet18_sgd.py index 8760c1e5adc9e..a73d945aa9524 100644 --- a/test/dygraph_to_static/test_train_step_resnet18_sgd.py +++ b/test/dygraph_to_static/test_train_step_resnet18_sgd.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import platform import unittest from test_train_step import ( @@ -33,6 +34,9 @@ def setUp(self): self.loss_fn = loss_fn_tiny_model self.train_step_func = train_step_tiny_model self.steps = 3 + self.rtol = 1e-4 + if platform.system() == 'Windows': + self.rtol = 1e-3 if __name__ == "__main__":