未验证 提交 6c183a8e 编写于 作者: W Wilber 提交者: GitHub

update ut (#37089)

上级 32c3e61b
...@@ -260,7 +260,7 @@ class MkldnnAutoScanTest(AutoScanTest): ...@@ -260,7 +260,7 @@ class MkldnnAutoScanTest(AutoScanTest):
self.assertTrue(status) self.assertTrue(status)
def inference_config_str(self, config) -> bool: def inference_config_str(self, config) -> str:
dic = {} dic = {}
enable_mkldnn = config.mkldnn_enabled() enable_mkldnn = config.mkldnn_enabled()
dic['use_mkldnn'] = enable_mkldnn dic['use_mkldnn'] = enable_mkldnn
...@@ -372,7 +372,7 @@ class PassAutoScanTest(AutoScanTest): ...@@ -372,7 +372,7 @@ class PassAutoScanTest(AutoScanTest):
status = self.check_op_version() and status status = self.check_op_version() and status
self.assertTrue(status) self.assertTrue(status)
def inference_config_str(self, config) -> bool: def inference_config_str(self, config) -> str:
dic = {} dic = {}
enable_mkldnn = config.mkldnn_enabled() enable_mkldnn = config.mkldnn_enabled()
dic['use_mkldnn'] = enable_mkldnn dic['use_mkldnn'] = enable_mkldnn
...@@ -491,7 +491,7 @@ class TrtLayerAutoScanTest(AutoScanTest): ...@@ -491,7 +491,7 @@ class TrtLayerAutoScanTest(AutoScanTest):
'paddle_op_num is {}, but got {}!'.format( 'paddle_op_num is {}, but got {}!'.format(
paddle_op_size, paddle_op_num)) paddle_op_size, paddle_op_num))
def inference_config_str(self, config: paddle_infer.Config): def inference_config_str(self, config: paddle_infer.Config) -> str:
dic = {} dic = {}
enable_trt = config.tensorrt_engine_enabled() enable_trt = config.tensorrt_engine_enabled()
trt_precison = config.tensorrt_precision_mode() trt_precison = config.tensorrt_precision_mode()
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
from auto_scan_test import PassAutoScanTest, SkipReasons from auto_scan_test import PassAutoScanTest, SkipReasons
from program_config import TensorConfig, ProgramConfig from program_config import TensorConfig, ProgramConfig, OpConfig
import numpy as np import numpy as np
import paddle.inference as paddle_infer import paddle.inference as paddle_infer
from functools import partial from functools import partial
...@@ -116,94 +116,71 @@ class TestEmbeddingEltwiseLayerNormFusePass(PassAutoScanTest): ...@@ -116,94 +116,71 @@ class TestEmbeddingEltwiseLayerNormFusePass(PassAutoScanTest):
'weight_size': kwargs['weight_size'] 'weight_size': kwargs['weight_size']
}] }]
ops_config = [{ emb_op1 = OpConfig(
"op_type": attrs[0]['op_type'], type=attrs[0]['op_type'],
"op_inputs": { inputs={"Ids": ["input_data1"],
"Ids": ["input_data1"], "W": ["embedding_weight1"]},
"W": ["embedding_weight1"] outputs={"Out": ["embedding_output1"]},
}, attrs={
"op_outputs": {
"Out": ["embedding_output1"]
},
"op_attrs": {
'is_sparse': attrs[0]['is_sparse'], 'is_sparse': attrs[0]['is_sparse'],
'is_distributed': attrs[0]['is_distributed'], 'is_distributed': attrs[0]['is_distributed'],
'padding_idx': attrs[0]['padding_idx'], 'padding_idx': attrs[0]['padding_idx']
} })
}, { emb_op2 = OpConfig(
"op_type": attrs[0]['op_type'], type=attrs[0]['op_type'],
"op_inputs": { inputs={"Ids": ["input_data2"],
"Ids": ["input_data2"], "W": ["embedding_weight2"]},
"W": ["embedding_weight2"] outputs={"Out": ["embedding_output2"]},
}, attrs={
"op_outputs": {
"Out": ["embedding_output2"]
},
"op_attrs": {
'is_sparse': attrs[0]['is_sparse'], 'is_sparse': attrs[0]['is_sparse'],
'is_distributed': attrs[0]['is_distributed'], 'is_distributed': attrs[0]['is_distributed'],
'padding_idx': attrs[0]['padding_idx'], 'padding_idx': attrs[0]['padding_idx']
}, })
}, { emb_op3 = OpConfig(
"op_type": attrs[0]['op_type'], type=attrs[0]['op_type'],
"op_inputs": { inputs={"Ids": ["input_data3"],
"Ids": ["input_data3"], "W": ["embedding_weight3"]},
"W": ["embedding_weight3"] outputs={"Out": ["embedding_output3"]},
}, attrs={
"op_outputs": {
"Out": ["embedding_output3"]
},
"op_attrs": {
'is_sparse': attrs[0]['is_sparse'], 'is_sparse': attrs[0]['is_sparse'],
'is_distributed': attrs[0]['is_distributed'], 'is_distributed': attrs[0]['is_distributed'],
'padding_idx': attrs[0]['padding_idx'], 'padding_idx': attrs[0]['padding_idx']
}, })
}, { add_op1 = OpConfig(
"op_type": "elementwise_add", type='elementwise_add',
"op_inputs": { inputs={
"X": ["embedding_output2"], "X": [emb_op2.outputs["Out"][0]],
"Y": ["embedding_output3"] "Y": [emb_op3.outputs["Out"][0]],
},
"op_outputs": {
"Out": ["elementwise_add_output1"]
},
"op_attrs": {
"axis": attrs[1]['axis'],
}
}, {
"op_type": "elementwise_add",
"op_inputs": {
"X": ["elementwise_add_output1"],
"Y": ["embedding_output1"]
}, },
"op_outputs": { outputs={"Out": ["elementwise_add_output1"]},
"Out": ["elementwise_add_output2"] attrs={"axis": attrs[1]['axis']})
add_op2 = OpConfig(
type='elementwise_add',
inputs={
"X": [add_op1.outputs["Out"][0]],
"Y": [emb_op1.outputs["Out"][0]],
}, },
"op_attrs": { outputs={"Out": ["elementwise_add_output2"]},
"axis": attrs[1]['axis'], attrs={"axis": attrs[1]['axis']})
} layer_norm_op = OpConfig(
}, { type='layer_norm',
"op_type": "layer_norm", inputs={
"op_inputs": { "X": [add_op2.outputs["Out"][0]],
"X": ["elementwise_add_output2"],
"Bias": ["layer_norm_bias"], "Bias": ["layer_norm_bias"],
"Scale": ["layer_norm_scale"] "Scale": ["layer_norm_scale"]
}, },
"op_outputs": { outputs={
"Y": ["layer_norm_output1"], "Y": ["layer_norm_output1"],
"Mean": ["layer_norm_output2"], "Mean": ["layer_norm_output2"],
"Variance": ["layer_norm_output3"] "Variance": ["layer_norm_output3"]
}, },
"op_attrs": { attrs={
'begin_norm_axis': attrs[2]['begin_norm_axis'], 'begin_norm_axis': attrs[2]['begin_norm_axis'],
'epsilon': attrs[2]['epsilon'], 'epsilon': attrs[2]['epsilon']
} })
}]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig( program_config = ProgramConfig(
ops=ops, ops=[emb_op1, emb_op2, emb_op3, add_op1, add_op2, layer_norm_op],
weights={ weights={
"embedding_weight1": "embedding_weight1":
TensorConfig(data_gen=partial(generate_weight1, attrs[3])), TensorConfig(data_gen=partial(generate_weight1, attrs[3])),
...@@ -242,7 +219,7 @@ class TestEmbeddingEltwiseLayerNormFusePass(PassAutoScanTest): ...@@ -242,7 +219,7 @@ class TestEmbeddingEltwiseLayerNormFusePass(PassAutoScanTest):
precision_mode=paddle_infer.PrecisionType.Float32, precision_mode=paddle_infer.PrecisionType.Float32,
use_static=False, use_static=False,
use_calib_mode=False) use_calib_mode=False)
yield config, (10, 3), (1e-5, 1e-5) yield config, (10, 5), (1e-5, 1e-5)
# trt dynamic_shape # trt dynamic_shape
config = self.create_trt_inference_config() config = self.create_trt_inference_config()
config.enable_tensorrt_engine( config.enable_tensorrt_engine(
...@@ -280,7 +257,7 @@ class TestEmbeddingEltwiseLayerNormFusePass(PassAutoScanTest): ...@@ -280,7 +257,7 @@ class TestEmbeddingEltwiseLayerNormFusePass(PassAutoScanTest):
"input_data2": [2, 128], "input_data2": [2, 128],
"input_data3": [2, 128] "input_data3": [2, 128]
}) })
yield config, (10, 3), (1e-5, 1e-5) yield config, (10, 5), (1e-5, 1e-5)
def add_skip_pass_case(self): def add_skip_pass_case(self):
def teller1(program_config, predictor_config): def teller1(program_config, predictor_config):
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
from auto_scan_test import MkldnnAutoScanTest, SkipReasons from auto_scan_test import MkldnnAutoScanTest, SkipReasons
from program_config import TensorConfig, ProgramConfig from program_config import TensorConfig, ProgramConfig, OpConfig
import numpy as np import numpy as np
import paddle.inference as paddle_infer import paddle.inference as paddle_infer
from functools import partial from functools import partial
...@@ -52,24 +52,15 @@ class TestMkldnnPreluOp(MkldnnAutoScanTest): ...@@ -52,24 +52,15 @@ class TestMkldnnPreluOp(MkldnnAutoScanTest):
return np.zeros((1)).astype(np.float32) return np.zeros((1)).astype(np.float32)
return np.random.random(kwargs['in_shape']).astype(np.float32) return np.random.random(kwargs['in_shape']).astype(np.float32)
ops_config = [{ prelu_op = OpConfig(
"op_type": "prelu", type="prelu",
"op_inputs": { inputs={"X": ["input_data"],
"X": ["input_data"], "Alpha": ["alpha_weight"]},
"Alpha": ["alpha_weight"] outputs={"Out": ["output_data"]},
}, attrs={"mode": kwargs['mode']})
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": {
"mode": kwargs['mode']
}
}]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig( program_config = ProgramConfig(
ops=ops, ops=[prelu_op],
weights={ weights={
"alpha_weight": "alpha_weight":
TensorConfig(data_gen=partial(generate_alpha, *args, **kwargs)) TensorConfig(data_gen=partial(generate_alpha, *args, **kwargs))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册