|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
16 | 16 | import unittest
|
17 |
| -from typing import Optional, Tuple, Dict, Any |
| 17 | +from dataclasses import Field, dataclass, fields |
| 18 | +from typing import Any, Dict, Optional, Tuple |
| 19 | + |
18 | 20 | import paddle
|
19 | 21 | from paddle import Tensor
|
20 | 22 |
|
21 |
| -from dataclasses import dataclass, asdict, fields, Field |
22 | 23 | from paddlenlp.transformers import (
|
23 |
| - ErnieGramModel, |
24 |
| - ErnieGramPretrainedModel, |
| 24 | + ErnieGramForQuestionAnswering, |
25 | 25 | ErnieGramForSequenceClassification,
|
26 | 26 | ErnieGramForTokenClassification,
|
27 |
| - ErnieGramForQuestionAnswering, |
| 27 | + ErnieGramModel, |
| 28 | + ErnieGramPretrainedModel, |
28 | 29 | )
|
29 | 30 |
|
30 |
| -from ..test_modeling_common import ids_tensor, floats_tensor, random_attention_mask, ModelTesterMixin |
31 | 31 | from ...testing_utils import slow
|
| 32 | +from ..test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask |
32 | 33 |
|
33 | 34 |
|
34 | 35 | @dataclass
|
35 | 36 | class ErnieGramTestModelConfig:
|
36 | 37 | """ernie-gram model config which keep consist with pretrained_init_configuration sub fields"""
|
37 | 38 |
|
38 | 39 | attention_probs_dropout_prob: float = 0.1
|
39 |
| - emb_size: int = 768 |
| 40 | + emb_size: int = 8 |
40 | 41 | hidden_act: str = "gelu"
|
41 | 42 | hidden_dropout_prob: float = 0.1
|
42 |
| - hidden_size: int = 768 |
| 43 | + hidden_size: int = 8 |
43 | 44 | initializer_range: float = 0.02
|
44 | 45 | max_position_embeddings: int = 512
|
45 |
| - num_attention_heads: int = 12 |
46 |
| - num_hidden_layers: int = 12 |
| 46 | + num_attention_heads: int = 2 |
| 47 | + num_hidden_layers: int = 2 |
47 | 48 | type_vocab_size: int = 2
|
48 | 49 | vocab_size: int = 1801
|
49 | 50 |
|
@@ -387,7 +388,6 @@ def test_inference_with_past_key_value(self):
|
387 | 388 | with paddle.no_grad():
|
388 | 389 | output = model(input_ids, attention_mask=attention_mask, use_cache=True, return_dict=True)
|
389 | 390 |
|
390 |
| - past_key_value = output.past_key_values[0][0] |
391 | 391 | expected_shape = [1, 11, 768]
|
392 | 392 | self.assertEqual(output[0].shape, expected_shape)
|
393 | 393 | expected_slice = paddle.to_tensor(
|
|
0 commit comments