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

[Dy2St] fix train step random failed on Windows #52580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion test/dygraph_to_static/test_train_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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__":
Expand Down
4 changes: 4 additions & 0 deletions test/dygraph_to_static/test_train_step_resnet18_adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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__":
Expand Down
4 changes: 4 additions & 0 deletions test/dygraph_to_static/test_train_step_resnet18_sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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__":
Expand Down