From 3a792129e9f04619d48c1101a1189bf43ee0f1bd Mon Sep 17 00:00:00 2001 From: feifei-111 <2364819892@qq.com> Date: Fri, 16 Jun 2023 06:32:47 +0000 Subject: [PATCH 1/3] update --- test/dygraph_to_static/test_to_tensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/dygraph_to_static/test_to_tensor.py b/test/dygraph_to_static/test_to_tensor.py index e96c5247a0d52..873765af98032 100644 --- a/test/dygraph_to_static/test_to_tensor.py +++ b/test/dygraph_to_static/test_to_tensor.py @@ -15,6 +15,7 @@ import unittest import numpy +from dygraph_to_static_util import ast_only_test import paddle from paddle.fluid import core @@ -148,6 +149,7 @@ def test_to_tensor_badreturn(self): self.assertTrue(a.stop_gradient == b.stop_gradient) self.assertTrue(a.place._equals(b.place)) + @ast_only_test def test_to_tensor_err_log(self): paddle.disable_static() x = paddle.to_tensor([3]) From f57bd262f85a1a7f3daf16e38e7fb871cf82b95d Mon Sep 17 00:00:00 2001 From: feifei-111 <2364819892@qq.com> Date: Fri, 16 Jun 2023 06:38:08 +0000 Subject: [PATCH 2/3] update --- test/dygraph_to_static/test_train_step.py | 4 +++- test/dygraph_to_static/test_train_step_resnet18_adam.py | 4 +++- test/dygraph_to_static/test_train_step_resnet18_sgd.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/dygraph_to_static/test_train_step.py b/test/dygraph_to_static/test_train_step.py index 2fbb8005e4ece..d92c6068bc5ae 100644 --- a/test/dygraph_to_static/test_train_step.py +++ b/test/dygraph_to_static/test_train_step.py @@ -17,6 +17,7 @@ from functools import partial import numpy as np +from dygraph_to_static_util import enable_fallback_guard import paddle @@ -433,4 +434,5 @@ def setUp(self): if __name__ == "__main__": - unittest.main() + with enable_fallback_guard("False"): + unittest.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 c8b34fe84f113..95fd040282b92 100644 --- a/test/dygraph_to_static/test_train_step_resnet18_adam.py +++ b/test/dygraph_to_static/test_train_step_resnet18_adam.py @@ -15,6 +15,7 @@ import platform import unittest +from dygraph_to_static_util import enable_fallback_guard from test_train_step import ( TestTrainStepTinyModel, loss_fn_tiny_model, @@ -40,4 +41,5 @@ def setUp(self): if __name__ == "__main__": - unittest.main() + with enable_fallback_guard("False"): + unittest.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 a73d945aa9524..f6139e62dc216 100644 --- a/test/dygraph_to_static/test_train_step_resnet18_sgd.py +++ b/test/dygraph_to_static/test_train_step_resnet18_sgd.py @@ -15,6 +15,7 @@ import platform import unittest +from dygraph_to_static_util import enable_fallback_guard from test_train_step import ( TestTrainStepTinyModel, loss_fn_tiny_model, @@ -40,4 +41,5 @@ def setUp(self): if __name__ == "__main__": - unittest.main() + with enable_fallback_guard("False"): + unittest.main() From 0778ade2ceab9c3d6fe4ac1b1135b08ea2ab1299 Mon Sep 17 00:00:00 2001 From: feifei-111 <2364819892@qq.com> Date: Fri, 16 Jun 2023 07:48:49 +0000 Subject: [PATCH 3/3] update --- test/dygraph_to_static/seq2seq_dygraph_model.py | 6 +++--- test/dygraph_to_static/test_se_resnet.py | 2 ++ test/dygraph_to_static/test_spec_names.py | 5 ++++- test/dygraph_to_static/test_to_tensor.py | 14 +++++++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/test/dygraph_to_static/seq2seq_dygraph_model.py b/test/dygraph_to_static/seq2seq_dygraph_model.py index 3b9f343ca9fad..06b8d8a8b56c0 100644 --- a/test/dygraph_to_static/seq2seq_dygraph_model.py +++ b/test/dygraph_to_static/seq2seq_dygraph_model.py @@ -297,7 +297,7 @@ def forward(self, inputs): loss = paddle.nn.functional.softmax_with_cross_entropy( logits=dec_output, label=label, soft_label=False ) - loss = paddle.squeeze(loss, axes=[2]) + loss = paddle.squeeze(loss, axis=[2]) max_tar_seq_len = paddle.shape(tar)[1] tar_mask = paddle.static.nn.sequence_lod.sequence_mask( tar_sequence_length, maxlen=max_tar_seq_len, dtype='float32' @@ -835,13 +835,13 @@ def forward(self, inputs): loss = paddle.nn.functional.softmax_with_cross_entropy( logits=dec_output, label=label, soft_label=False ) - loss = paddle.squeeze(loss, axes=[2]) + loss = paddle.squeeze(loss, axis=[2]) max_tar_seq_len = paddle.shape(tar)[1] tar_mask = paddle.static.nn.sequence_lod.sequence_mask( tar_sequence_length, maxlen=max_tar_seq_len, dtype='float32' ) loss = loss * tar_mask loss = paddle.mean(loss, axis=[0]) - loss = fluid.layers.reduce_sum(loss) + loss = paddle.sum(loss) return loss diff --git a/test/dygraph_to_static/test_se_resnet.py b/test/dygraph_to_static/test_se_resnet.py index 05b2f6a517039..a0d18e5801169 100644 --- a/test/dygraph_to_static/test_se_resnet.py +++ b/test/dygraph_to_static/test_se_resnet.py @@ -20,6 +20,7 @@ import unittest import numpy as np +from dygraph_to_static_util import ast_only_test from predictor_utils import PredictorTools import paddle @@ -561,6 +562,7 @@ def verify_predict(self): ), ) + @ast_only_test def test_check_result(self): pred_1, loss_1, acc1_1, acc5_1 = self.train( self.train_reader, to_static=False diff --git a/test/dygraph_to_static/test_spec_names.py b/test/dygraph_to_static/test_spec_names.py index 5698763ecdd2a..8294c6c2af4c1 100644 --- a/test/dygraph_to_static/test_spec_names.py +++ b/test/dygraph_to_static/test_spec_names.py @@ -14,6 +14,8 @@ import unittest +from dygraph_to_static_util import enable_fallback_guard + import paddle from paddle.nn import Layer @@ -101,4 +103,5 @@ def to_idx(name): if __name__ == '__main__': - unittest.main() + with enable_fallback_guard("False"): + unittest.main() diff --git a/test/dygraph_to_static/test_to_tensor.py b/test/dygraph_to_static/test_to_tensor.py index 873765af98032..65764e002d09a 100644 --- a/test/dygraph_to_static/test_to_tensor.py +++ b/test/dygraph_to_static/test_to_tensor.py @@ -15,7 +15,7 @@ import unittest import numpy -from dygraph_to_static_util import ast_only_test +from dygraph_to_static_util import ast_only_test, sot_only_test import paddle from paddle.fluid import core @@ -161,6 +161,18 @@ def test_to_tensor_err_log(self): in str(e) ) + @sot_only_test + def test_to_tensor_err_log_sot(self): + paddle.disable_static() + x = paddle.to_tensor([3]) + try: + a = paddle.jit.to_static(case8)(x) + except Exception as e: + self.assertTrue( + "Can't constructs a 'paddle.Tensor' with data type " + in str(e) + ) + class TestStatic(unittest.TestCase): def test_static(self):