Skip to content

Commit 6c183a8

Browse files
authored
update ut (#37089)
1 parent 32c3e61 commit 6c183a8

File tree

3 files changed

+61
-93
lines changed

3 files changed

+61
-93
lines changed

python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def run_test(self, quant=False, *args, **kwargs):
260260

261261
self.assertTrue(status)
262262

263-
def inference_config_str(self, config) -> bool:
263+
def inference_config_str(self, config) -> str:
264264
dic = {}
265265
enable_mkldnn = config.mkldnn_enabled()
266266
dic['use_mkldnn'] = enable_mkldnn
@@ -372,7 +372,7 @@ def run_test(self, quant=False, *args, **kwargs):
372372
status = self.check_op_version() and status
373373
self.assertTrue(status)
374374

375-
def inference_config_str(self, config) -> bool:
375+
def inference_config_str(self, config) -> str:
376376
dic = {}
377377
enable_mkldnn = config.mkldnn_enabled()
378378
dic['use_mkldnn'] = enable_mkldnn
@@ -491,7 +491,7 @@ def assert_op_size(self, trt_engine_num, paddle_op_num):
491491
'paddle_op_num is {}, but got {}!'.format(
492492
paddle_op_size, paddle_op_num))
493493

494-
def inference_config_str(self, config: paddle_infer.Config):
494+
def inference_config_str(self, config: paddle_infer.Config) -> str:
495495
dic = {}
496496
enable_trt = config.tensorrt_engine_enabled()
497497
trt_precison = config.tensorrt_precision_mode()

python/paddle/fluid/tests/unittests/ir/inference/test_emb_eltwise_layernorm_fuse_pass.py

Lines changed: 50 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from auto_scan_test import PassAutoScanTest, SkipReasons
16-
from program_config import TensorConfig, ProgramConfig
16+
from program_config import TensorConfig, ProgramConfig, OpConfig
1717
import numpy as np
1818
import paddle.inference as paddle_infer
1919
from functools import partial
@@ -116,94 +116,71 @@ def generate_weight2(attrs):
116116
'weight_size': kwargs['weight_size']
117117
}]
118118

119-
ops_config = [{
120-
"op_type": attrs[0]['op_type'],
121-
"op_inputs": {
122-
"Ids": ["input_data1"],
123-
"W": ["embedding_weight1"]
124-
},
125-
"op_outputs": {
126-
"Out": ["embedding_output1"]
127-
},
128-
"op_attrs": {
119+
emb_op1 = OpConfig(
120+
type=attrs[0]['op_type'],
121+
inputs={"Ids": ["input_data1"],
122+
"W": ["embedding_weight1"]},
123+
outputs={"Out": ["embedding_output1"]},
124+
attrs={
129125
'is_sparse': attrs[0]['is_sparse'],
130126
'is_distributed': attrs[0]['is_distributed'],
131-
'padding_idx': attrs[0]['padding_idx'],
132-
}
133-
}, {
134-
"op_type": attrs[0]['op_type'],
135-
"op_inputs": {
136-
"Ids": ["input_data2"],
137-
"W": ["embedding_weight2"]
138-
},
139-
"op_outputs": {
140-
"Out": ["embedding_output2"]
141-
},
142-
"op_attrs": {
127+
'padding_idx': attrs[0]['padding_idx']
128+
})
129+
emb_op2 = OpConfig(
130+
type=attrs[0]['op_type'],
131+
inputs={"Ids": ["input_data2"],
132+
"W": ["embedding_weight2"]},
133+
outputs={"Out": ["embedding_output2"]},
134+
attrs={
143135
'is_sparse': attrs[0]['is_sparse'],
144136
'is_distributed': attrs[0]['is_distributed'],
145-
'padding_idx': attrs[0]['padding_idx'],
146-
},
147-
}, {
148-
"op_type": attrs[0]['op_type'],
149-
"op_inputs": {
150-
"Ids": ["input_data3"],
151-
"W": ["embedding_weight3"]
152-
},
153-
"op_outputs": {
154-
"Out": ["embedding_output3"]
155-
},
156-
"op_attrs": {
137+
'padding_idx': attrs[0]['padding_idx']
138+
})
139+
emb_op3 = OpConfig(
140+
type=attrs[0]['op_type'],
141+
inputs={"Ids": ["input_data3"],
142+
"W": ["embedding_weight3"]},
143+
outputs={"Out": ["embedding_output3"]},
144+
attrs={
157145
'is_sparse': attrs[0]['is_sparse'],
158146
'is_distributed': attrs[0]['is_distributed'],
159-
'padding_idx': attrs[0]['padding_idx'],
160-
},
161-
}, {
162-
"op_type": "elementwise_add",
163-
"op_inputs": {
164-
"X": ["embedding_output2"],
165-
"Y": ["embedding_output3"]
166-
},
167-
"op_outputs": {
168-
"Out": ["elementwise_add_output1"]
169-
},
170-
"op_attrs": {
171-
"axis": attrs[1]['axis'],
172-
}
173-
}, {
174-
"op_type": "elementwise_add",
175-
"op_inputs": {
176-
"X": ["elementwise_add_output1"],
177-
"Y": ["embedding_output1"]
147+
'padding_idx': attrs[0]['padding_idx']
148+
})
149+
add_op1 = OpConfig(
150+
type='elementwise_add',
151+
inputs={
152+
"X": [emb_op2.outputs["Out"][0]],
153+
"Y": [emb_op3.outputs["Out"][0]],
178154
},
179-
"op_outputs": {
180-
"Out": ["elementwise_add_output2"]
155+
outputs={"Out": ["elementwise_add_output1"]},
156+
attrs={"axis": attrs[1]['axis']})
157+
add_op2 = OpConfig(
158+
type='elementwise_add',
159+
inputs={
160+
"X": [add_op1.outputs["Out"][0]],
161+
"Y": [emb_op1.outputs["Out"][0]],
181162
},
182-
"op_attrs": {
183-
"axis": attrs[1]['axis'],
184-
}
185-
}, {
186-
"op_type": "layer_norm",
187-
"op_inputs": {
188-
"X": ["elementwise_add_output2"],
163+
outputs={"Out": ["elementwise_add_output2"]},
164+
attrs={"axis": attrs[1]['axis']})
165+
layer_norm_op = OpConfig(
166+
type='layer_norm',
167+
inputs={
168+
"X": [add_op2.outputs["Out"][0]],
189169
"Bias": ["layer_norm_bias"],
190170
"Scale": ["layer_norm_scale"]
191171
},
192-
"op_outputs": {
172+
outputs={
193173
"Y": ["layer_norm_output1"],
194174
"Mean": ["layer_norm_output2"],
195175
"Variance": ["layer_norm_output3"]
196176
},
197-
"op_attrs": {
177+
attrs={
198178
'begin_norm_axis': attrs[2]['begin_norm_axis'],
199-
'epsilon': attrs[2]['epsilon'],
200-
}
201-
}]
202-
203-
ops = self.generate_op_config(ops_config)
179+
'epsilon': attrs[2]['epsilon']
180+
})
204181

205182
program_config = ProgramConfig(
206-
ops=ops,
183+
ops=[emb_op1, emb_op2, emb_op3, add_op1, add_op2, layer_norm_op],
207184
weights={
208185
"embedding_weight1":
209186
TensorConfig(data_gen=partial(generate_weight1, attrs[3])),
@@ -242,7 +219,7 @@ def sample_predictor_configs(self, program_config):
242219
precision_mode=paddle_infer.PrecisionType.Float32,
243220
use_static=False,
244221
use_calib_mode=False)
245-
yield config, (10, 3), (1e-5, 1e-5)
222+
yield config, (10, 5), (1e-5, 1e-5)
246223
# trt dynamic_shape
247224
config = self.create_trt_inference_config()
248225
config.enable_tensorrt_engine(
@@ -280,7 +257,7 @@ def sample_predictor_configs(self, program_config):
280257
"input_data2": [2, 128],
281258
"input_data3": [2, 128]
282259
})
283-
yield config, (10, 3), (1e-5, 1e-5)
260+
yield config, (10, 5), (1e-5, 1e-5)
284261

285262
def add_skip_pass_case(self):
286263
def teller1(program_config, predictor_config):

python/paddle/fluid/tests/unittests/ir/inference/test_mkldnn_prelu_op.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from auto_scan_test import MkldnnAutoScanTest, SkipReasons
16-
from program_config import TensorConfig, ProgramConfig
16+
from program_config import TensorConfig, ProgramConfig, OpConfig
1717
import numpy as np
1818
import paddle.inference as paddle_infer
1919
from functools import partial
@@ -52,24 +52,15 @@ def generate_alpha(*args, **kwargs):
5252
return np.zeros((1)).astype(np.float32)
5353
return np.random.random(kwargs['in_shape']).astype(np.float32)
5454

55-
ops_config = [{
56-
"op_type": "prelu",
57-
"op_inputs": {
58-
"X": ["input_data"],
59-
"Alpha": ["alpha_weight"]
60-
},
61-
"op_outputs": {
62-
"Out": ["output_data"]
63-
},
64-
"op_attrs": {
65-
"mode": kwargs['mode']
66-
}
67-
}]
68-
69-
ops = self.generate_op_config(ops_config)
55+
prelu_op = OpConfig(
56+
type="prelu",
57+
inputs={"X": ["input_data"],
58+
"Alpha": ["alpha_weight"]},
59+
outputs={"Out": ["output_data"]},
60+
attrs={"mode": kwargs['mode']})
7061

7162
program_config = ProgramConfig(
72-
ops=ops,
63+
ops=[prelu_op],
7364
weights={
7465
"alpha_weight":
7566
TensorConfig(data_gen=partial(generate_alpha, *args, **kwargs))

0 commit comments

Comments
 (0)