From 5135439b9d96d79ae3f73d34fa953cead78d8f94 Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Wed, 31 Mar 2021 15:36:50 +0800 Subject: [PATCH] fix check_output type bug (#206) --- tests/common_test.py | 4 ++++ tests/data/test_sampler.py | 3 ++- tests/transformers/bigbird/test_modeling.py | 4 +--- tests/transformers/bigbird/test_tokenizer.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/common_test.py b/tests/common_test.py index 7ca8c9fb77ccc5..9f811a64f37860 100644 --- a/tests/common_test.py +++ b/tests/common_test.py @@ -118,6 +118,10 @@ def _check_output_impl(self, msg=error_msg.format(paddle.get_device(), expected_result.shape, result.shape, self.__class__.__name__)) + else: + raise ValueError( + 'result type must be str, int, bool, set, np.bool, np.int32, ' + 'np.int64, np.str, float, np.ndarray, np.float32, np.float64') def check_output_equal(self, result, diff --git a/tests/data/test_sampler.py b/tests/data/test_sampler.py index 7ba0d4a29b6ea7..2e5d1f30fe6fda 100644 --- a/tests/data/test_sampler.py +++ b/tests/data/test_sampler.py @@ -56,7 +56,8 @@ def test_iter2(self): def test_list(self): train_batch_sampler = SamplerHelper(self.train_ds) list_sampler = train_batch_sampler.list() - self.check_output_equal(type(iter(list_sampler)), "listiterator") + self.check_output_equal( + type(iter(list_sampler)).__name__, "list_iterator") for i, sample in enumerate(list_sampler): self.check_output_equal(i, sample) diff --git a/tests/transformers/bigbird/test_modeling.py b/tests/transformers/bigbird/test_modeling.py index 35260408c496f3..72c22a8ba0844a 100644 --- a/tests/transformers/bigbird/test_modeling.py +++ b/tests/transformers/bigbird/test_modeling.py @@ -91,7 +91,6 @@ def setUp(self): 'bigbird-base-uncased'] self.config['num_layers'] = 2 self.config['vocab_size'] = 1024 - self.config['vocab_size'] = 1024 self.config['attn_dropout'] = 0.0 self.config['hidden_dropout_prob'] = 0.0 self.config['dim_feedforward'] = 1024 @@ -115,7 +114,7 @@ def test_forward(self): expected_output = np.array( [[0.38314182, -0.13412490], [0.32075390, 0.07187212]]) - self.check_output_equal(output, expected_output) + self.check_output_equal(output.numpy(), expected_output) class TestBigBirdForPretraining(CommonTest): @@ -124,7 +123,6 @@ def setUp(self): 'bigbird-base-uncased'] self.config['num_layers'] = 2 self.config['vocab_size'] = 1024 - self.config['vocab_size'] = 1024 self.config['attn_dropout'] = 0.0 self.config['hidden_dropout_prob'] = 0.0 self.config['dim_feedforward'] = 1024 diff --git a/tests/transformers/bigbird/test_tokenizer.py b/tests/transformers/bigbird/test_tokenizer.py index 122dc9ba7966db..65215ccdb0c282 100644 --- a/tests/transformers/bigbird/test_tokenizer.py +++ b/tests/transformers/bigbird/test_tokenizer.py @@ -126,7 +126,7 @@ def setUp(self): def test_empty_text(self): ids = self.tokenizer('') - self.check_output_equal(ids, []) + self.check_output_equal(ids == [], True) def test_bytes(self): byte_text = 'An extremely powerful film that certainly isnt '\