diff --git a/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py b/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py index 9cd3c6a8fb554407699c95f9933cce24cd9426c2..d624495f71df7a21a277dbeaf0f8b36866149876 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py @@ -18,10 +18,11 @@ import unittest import numpy as np import paddle from collections import OrderedDict +from paddle.fluid.framework import _test_eager_guard class TestLayerDict(unittest.TestCase): - def test_layer_dict(self): + def func_layer_dict(self): layers = OrderedDict([ ('conv1d', paddle.nn.Conv1D(3, 2, 3)), ('conv2d', paddle.nn.Conv2D(3, 2, 3)), @@ -89,7 +90,12 @@ class TestLayerDict(unittest.TestCase): layers_dicts.update(list_format_layers) check_layer_dict() - def test_layer_dict_error_inputs(self): + def test_layer_dict(self): + with _test_eager_guard(): + self.func_layer_dict() + self.func_layer_dict() + + def func_layer_dict_error_inputs(self): layers = [ ('conv1d', paddle.nn.Conv1D(3, 2, 3), "conv1d"), ('conv2d', paddle.nn.Conv2D(3, 2, 3)), @@ -100,6 +106,11 @@ class TestLayerDict(unittest.TestCase): self.assertRaises(AssertionError, layers_dicts.update, 1) + def test_layer_dict_error_inputs(self): + with _test_eager_guard(): + self.func_layer_dict_error_inputs() + self.func_layer_dict_error_inputs() + if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py b/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py index 39cbed865b737b7d20e89940e33de1c8370b1a32..349f18fe799857dd9c6ba2e49c716f7d24f8ee05 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import unittest import paddle.fluid as fluid import numpy as np import paddle +from paddle import _C_ops +from paddle.fluid.framework import _test_eager_guard class MyLayer(fluid.Layer): @@ -41,15 +43,7 @@ class MyLayer(fluid.Layer): def forward(self, x): for i, p in enumerate(self.params): - tmp = self._helper.create_variable_for_type_inference('float32') - self._helper.append_op( - type="mul", - inputs={"X": x, - "Y": p}, - outputs={"Out": tmp}, - attrs={"x_num_col_dims": 1, - "y_num_col_dims": 1}) - x = tmp + x = _C_ops.mul(x, p) return x @@ -80,8 +74,11 @@ class TestImperativeContainerParameterList(unittest.TestCase): loss.backward() def test_paramter_list(self): - self.paramter_list(True) + with _test_eager_guard(): + self.paramter_list(False) + self.paramter_list(True) self.paramter_list(False) + self.paramter_list(True) if __name__ == '__main__':