Meiyang/paddle 2.3 (#13272)
* Migrate to PDPD 2.3 * update supported paddle version to 2.3.2 * update paddle test with paddle new static API on 2.3.2 * fix issue of different output shape with paddle's * fix clang format issue * fix compiling issue * integrate paddle static save model api to original save model api Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com> Co-authored-by: Alina Kladieva <alina.kladieva@intel.com>
This commit is contained in:
11 files changed
+117
-72
No files matched your search
@@ -247,7 +247,7 @@ jobs:
|
||||
|
||||
- script: call $(SETUPVARS) && $(INSTALL_TEST_DIR)\paddle_tests --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)\TEST-Paddle.xml
|
||||
displayName: 'Paddle Frontend UT'
|
||||
continueOnError: true
|
||||
continueOnError: false
|
||||
|
||||
- script: call $(SETUPVARS) && $(INSTALL_TEST_DIR)\ov_tensorflow_frontend_tests --gtest_print_time=1 --gtest_output=xml:$(INSTALL_TEST_DIR)\TEST-Tensorflow.xml
|
||||
displayName: 'TensorFlow Frontend Unit Tests'
|
||||
|
||||
@@ -45,12 +45,12 @@ std::vector<std::string> tensor_names = {
|
||||
"relu_1.tmp_0",
|
||||
"relu_2.tmp_0",
|
||||
"relu_3.tmp_0",
|
||||
"save_infer_model/scale_0.tmp_1",
|
||||
"save_infer_model/scale_1.tmp_1",
|
||||
"save_infer_model/scale_2.tmp_1",
|
||||
"save_infer_model/scale_3.tmp_1",
|
||||
"save_infer_model/scale_4.tmp_1",
|
||||
"save_infer_model/scale_5.tmp_1",
|
||||
"save_infer_model/scale_0.tmp_0",
|
||||
"save_infer_model/scale_1.tmp_0",
|
||||
"save_infer_model/scale_2.tmp_0",
|
||||
"save_infer_model/scale_3.tmp_0",
|
||||
"save_infer_model/scale_4.tmp_0",
|
||||
"save_infer_model/scale_5.tmp_0",
|
||||
};
|
||||
|
||||
TEST(Paddle_Places, check_tensor_names) {
|
||||
@@ -82,12 +82,12 @@ TEST(Paddle_Places, check_input_outputs) {
|
||||
auto tensor_place = input_model->get_place_by_tensor_name("x");
|
||||
tensor_place->is_equal(inputs[0]);
|
||||
|
||||
std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_1",
|
||||
"save_infer_model/scale_1.tmp_1",
|
||||
"save_infer_model/scale_2.tmp_1",
|
||||
"save_infer_model/scale_3.tmp_1",
|
||||
"save_infer_model/scale_4.tmp_1",
|
||||
"save_infer_model/scale_5.tmp_1"};
|
||||
std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_0",
|
||||
"save_infer_model/scale_1.tmp_0",
|
||||
"save_infer_model/scale_2.tmp_0",
|
||||
"save_infer_model/scale_3.tmp_0",
|
||||
"save_infer_model/scale_4.tmp_0",
|
||||
"save_infer_model/scale_5.tmp_0"};
|
||||
|
||||
for (const auto& name : output_names) {
|
||||
const auto output_place = input_model->get_place_by_tensor_name(name);
|
||||
@@ -398,12 +398,12 @@ TEST(Paddle_Places, check_input_output_ports_dy_idx) {
|
||||
InputModel::Ptr input_model;
|
||||
ASSERT_NO_THROW(input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file)));
|
||||
|
||||
std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_1",
|
||||
"save_infer_model/scale_1.tmp_1",
|
||||
"save_infer_model/scale_2.tmp_1",
|
||||
"save_infer_model/scale_3.tmp_1",
|
||||
"save_infer_model/scale_4.tmp_1",
|
||||
"save_infer_model/scale_5.tmp_1"};
|
||||
std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_0",
|
||||
"save_infer_model/scale_1.tmp_0",
|
||||
"save_infer_model/scale_2.tmp_0",
|
||||
"save_infer_model/scale_3.tmp_0",
|
||||
"save_infer_model/scale_4.tmp_0",
|
||||
"save_infer_model/scale_5.tmp_0"};
|
||||
|
||||
for (const auto& tensor_name : output_names) {
|
||||
auto tensor_place = input_model->get_place_by_tensor_name(tensor_name);
|
||||
@@ -424,12 +424,12 @@ TEST(Paddle_Places, check_ops_tensors_by_idx) {
|
||||
InputModel::Ptr input_model;
|
||||
ASSERT_NO_THROW(input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file)));
|
||||
|
||||
std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_1",
|
||||
"save_infer_model/scale_1.tmp_1",
|
||||
"save_infer_model/scale_2.tmp_1",
|
||||
"save_infer_model/scale_3.tmp_1",
|
||||
"save_infer_model/scale_4.tmp_1",
|
||||
"save_infer_model/scale_5.tmp_1"};
|
||||
std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_0",
|
||||
"save_infer_model/scale_1.tmp_0",
|
||||
"save_infer_model/scale_2.tmp_0",
|
||||
"save_infer_model/scale_3.tmp_0",
|
||||
"save_infer_model/scale_4.tmp_0",
|
||||
"save_infer_model/scale_5.tmp_0"};
|
||||
|
||||
for (const auto& tensor_name : output_names) {
|
||||
auto tensor_place = input_model->get_place_by_tensor_name(tensor_name);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# PaddlePaddle - generate test models
|
||||
paddlepaddle==2.1.0
|
||||
paddlepaddle==2.3.2
|
||||
gast==0.3.3
|
||||
numpy~=1.19.2
|
||||
six~=1.15.0
|
||||
protobuf>=3.18.1,<4.0.0
|
||||
protobuf>=3.18.1,<4.0.0
|
||||
@@ -17,8 +17,7 @@ static TelemetryFEParam getTestData() {
|
||||
res.m_modelName = "relu/relu.pdmodel";
|
||||
res.m_expected_events = {{std::make_tuple("mo", "op_count", "paddle_feed", 1),
|
||||
std::make_tuple("mo", "op_count", "paddle_fetch", 1),
|
||||
std::make_tuple("mo", "op_count", "paddle_relu", 1),
|
||||
std::make_tuple("mo", "op_count", "paddle_scale", 1)}};
|
||||
std::make_tuple("mo", "op_count", "paddle_relu", 1)}};
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from paddle import fluid
|
||||
import numpy as np
|
||||
import os
|
||||
import sys
|
||||
from save_model import saveModel
|
||||
|
||||
|
||||
paddle.enable_static()
|
||||
@@ -38,5 +39,8 @@ inp_dict = {'inputX1': inp_blob1, 'inputX2': inp_blob2}
|
||||
var = [relu3a, relu3b]
|
||||
res_paddle = exe.run(fluid.default_main_program(), fetch_list=var, feed=inp_dict)
|
||||
|
||||
fluid.io.save_inference_model(os.path.join(sys.argv[1], "2in_2out"), list(inp_dict.keys()), var, exe,
|
||||
model_filename="2in_2out.pdmodel", params_filename="2in_2out.pdiparams")
|
||||
saveModel("2in_2out", exe, feedkeys=[x1, x2],
|
||||
fetchlist=var,
|
||||
inputs=[inp_blob1, inp_blob2],
|
||||
outputs=[res_paddle[0], res_paddle[1]], target_dir=sys.argv[1],
|
||||
use_static_api=True)
|
||||
@@ -34,10 +34,11 @@ def paddle_rnn_lstm(input_size, hidden_size, layers, direction):
|
||||
feed={'x': np.ones([4, 3, input_size]).astype(np.float32)},
|
||||
fetch_list=[y, h, c],
|
||||
program=main_program)
|
||||
saveModel("place_test_model", exe, feedkeys=['x'],
|
||||
saveModel("place_test_model", exe, feedkeys=[data],
|
||||
fetchlist=[y, h, c, relu_1, relu_2, relu_3],
|
||||
inputs=[np.ones([4, 3, input_size]).astype(np.float32)],
|
||||
outputs=[outs[0], outs[1], outs[2]], target_dir=sys.argv[1])
|
||||
outputs=[outs[0], outs[1], outs[2]], target_dir=sys.argv[1],
|
||||
use_static_api=True)
|
||||
return outs[0]
|
||||
|
||||
|
||||
@@ -53,4 +54,4 @@ if __name__ == "__main__":
|
||||
]
|
||||
|
||||
for test in testCases:
|
||||
paddle_rnn_lstm(test['input_size'], test['hidden_size'], test['layers'], test['direction'])
|
||||
paddle_rnn_lstm(test['input_size'], test['hidden_size'], test['layers'], test['direction'])
|
||||
+2
-25
@@ -11,6 +11,7 @@ import sys
|
||||
import os
|
||||
import numpy as np
|
||||
import paddle
|
||||
from save_model import saveModel
|
||||
|
||||
|
||||
# print numpy array like C structure
|
||||
@@ -44,30 +45,6 @@ def print_alike(arr):
|
||||
print(print_array(arr, "}"))
|
||||
|
||||
|
||||
def saveModel(name, exe, feedkeys: list, fetchlist: list, inputs: list, outputs: list, target_dir: str):
|
||||
model_dir = os.path.join(target_dir, name)
|
||||
if not os.path.exists(model_dir):
|
||||
os.makedirs(model_dir)
|
||||
|
||||
print("\n\n------------- %s -----------\n" % (name))
|
||||
for i, input in enumerate(inputs):
|
||||
print("INPUT %s :" % (feedkeys[i]), input.shape, input.dtype, "\n")
|
||||
print_alike(input)
|
||||
np.save(os.path.join(model_dir, "input{}".format(i)), input)
|
||||
np.save(os.path.join(model_dir, "input{}.{}.{}".format(i, feedkeys[i], input.dtype)), input)
|
||||
print("\n")
|
||||
|
||||
for i, output in enumerate(outputs):
|
||||
print("OUTPUT %s :" % (fetchlist[i]), output.shape, output.dtype, "\n")
|
||||
print_alike(output)
|
||||
np.save(os.path.join(model_dir, "output{}".format(i)), output)
|
||||
|
||||
# composited model + scattered model
|
||||
paddle.fluid.io.save_inference_model(model_dir, feedkeys, fetchlist, exe)
|
||||
paddle.fluid.io.save_inference_model(model_dir, feedkeys, fetchlist, exe, model_filename=name + ".pdmodel",
|
||||
params_filename=name + ".pdiparams")
|
||||
|
||||
|
||||
def relu(name: str, x):
|
||||
import paddle
|
||||
paddle.enable_static()
|
||||
@@ -105,4 +82,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
@@ -41,28 +41,35 @@ def print_alike(arr, seperator_begin='{', seperator_end='}', verbose=False):
|
||||
if verbose:
|
||||
print(print_array(arr, seperator_end))
|
||||
|
||||
|
||||
def saveModel(name, exe, feedkeys:list, fetchlist:list, inputs:list, outputs:list, target_dir:str):
|
||||
def saveModel(name, exe, feedkeys:list, fetchlist:list, inputs:list, outputs:list, target_dir:str, use_static_api=False):
|
||||
model_dir = os.path.join(target_dir, name)
|
||||
if not os.path.exists(model_dir):
|
||||
os.makedirs(model_dir)
|
||||
os.makedirs(model_dir)
|
||||
|
||||
# print("\n\n------------- %s -----------\n" % (name))
|
||||
for i, input in enumerate(inputs):
|
||||
# print("INPUT %s :" % (feedkeys[i]), input.shape, input.dtype, "\n")
|
||||
if use_static_api == True:
|
||||
feedkey = feedkeys[i].name
|
||||
else:
|
||||
feedkey = feedkeys[i]
|
||||
# print("INPUT %s :" % (feedkey), input.shape, input.dtype, "\n")
|
||||
# print_alike(input)
|
||||
np.save(os.path.join(model_dir, "input{}".format(i)), input)
|
||||
np.save(os.path.join(model_dir, "input{}.{}.{}".format(i, feedkeys[i], input.dtype)), input)
|
||||
np.save(os.path.join(model_dir, "input{}.{}.{}".format(i, feedkey, input.dtype)), input)
|
||||
# print("\n")
|
||||
|
||||
for i, output in enumerate(outputs):
|
||||
# print("OUTPUT %s :" % (fetchlist[i]),output.shape, output.dtype, "\n")
|
||||
# print_alike(output)
|
||||
np.save(os.path.join(model_dir, "output{}".format(i)), output)
|
||||
np.save(os.path.join(model_dir, "output{}".format(i)), output)
|
||||
|
||||
# composited model + scattered model
|
||||
paddle.fluid.io.save_inference_model(model_dir, feedkeys, fetchlist, exe)
|
||||
paddle.fluid.io.save_inference_model(model_dir, feedkeys, fetchlist, exe, model_filename=name+".pdmodel", params_filename=name+".pdiparams")
|
||||
if use_static_api == True:
|
||||
model_name = os.path.join(model_dir, name)
|
||||
paddle.static.io.save_inference_model(model_name, feedkeys, fetchlist, exe)
|
||||
else:
|
||||
paddle.fluid.io.save_inference_model(model_dir, feedkeys, fetchlist, exe)
|
||||
paddle.fluid.io.save_inference_model(model_dir, feedkeys, fetchlist, exe, model_filename=name+".pdmodel", params_filename=name+".pdiparams")
|
||||
|
||||
|
||||
'''
|
||||
|
||||
@@ -14,7 +14,13 @@ NamedOutputs matmul_v2(const NodeContext& node) {
|
||||
const auto transpose_a = node.get_attribute<bool>("trans_x", false);
|
||||
const auto transpose_b = node.get_attribute<bool>("trans_y", false);
|
||||
const auto mm = std::make_shared<default_opset::MatMul>(x, y, transpose_a, transpose_b);
|
||||
return node.default_single_output_mapping({mm}, {"Out"});
|
||||
|
||||
std::shared_ptr<Node> result = mm;
|
||||
if (is_scalar(mm->get_output_partial_shape(0))) {
|
||||
auto unsqueeze_scalar = default_opset::Constant::create(ov::element::i64, {}, {0});
|
||||
result = std::make_shared<default_opset::Unsqueeze>(mm, unsqueeze_scalar);
|
||||
}
|
||||
return node.default_single_output_mapping({result}, {"Out"});
|
||||
}
|
||||
|
||||
} // namespace op
|
||||
|
||||
@@ -24,10 +24,26 @@ NamedOutputs reduce_ops(const NodeContext& node) {
|
||||
dims = node.get_attribute<std::vector<int32_t>>("dim");
|
||||
}
|
||||
auto axesNode = default_opset::Constant::create(ngraph::element::i32, {dims.size()}, dims);
|
||||
return node.default_single_output_mapping({std::make_shared<T>(x, axesNode, keep_dim)}, {"Out"});
|
||||
bool scalar_output = !keep_dim;
|
||||
if (scalar_output) {
|
||||
for (int32_t i = 0; i < input_rank; i++) {
|
||||
if (std::find(dims.begin(), dims.end(), i) == dims.end()) {
|
||||
scalar_output = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto reduceNode = std::make_shared<T>(x, axesNode, keep_dim);
|
||||
std::shared_ptr<Node> result = reduceNode;
|
||||
if (scalar_output) {
|
||||
auto unsqueeze_scalar = default_opset::Constant::create(ov::element::i64, {}, {0});
|
||||
result = std::make_shared<default_opset::Unsqueeze>(reduceNode, unsqueeze_scalar);
|
||||
}
|
||||
return node.default_single_output_mapping({result}, {"Out"});
|
||||
}
|
||||
|
||||
} // namespace op
|
||||
} // namespace paddle
|
||||
} // namespace frontend
|
||||
} // namespace ov
|
||||
} // namespace ov
|
||||
@@ -11,12 +11,11 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. */
|
||||
// Modification Copyright (C) 2018-2022 Intel Corporation
|
||||
|
||||
syntax = "proto2";
|
||||
package paddle.framework.proto;
|
||||
|
||||
option optimize_for = LITE_RUNTIME; // Added by Intel Corporation 2021
|
||||
option optimize_for = LITE_RUNTIME; // Added by Intel Corporation 2021-2022
|
||||
|
||||
// Any incompatible changes to ProgramDesc and its dependencies should
|
||||
// raise the version defined version.h.
|
||||
@@ -38,6 +37,10 @@ enum AttrType {
|
||||
LONG = 9;
|
||||
BLOCKS = 10;
|
||||
LONGS = 11;
|
||||
FLOAT64S = 12;
|
||||
VAR = 13;
|
||||
VARS = 14;
|
||||
FLOAT64 = 15;
|
||||
}
|
||||
|
||||
// OpDesc describes an instance of a C++ framework::OperatorBase
|
||||
@@ -59,6 +62,10 @@ message OpDesc {
|
||||
optional int64 l = 13;
|
||||
repeated int32 blocks_idx = 14;
|
||||
repeated int64 longs = 15;
|
||||
repeated double float64s = 16;
|
||||
optional string var_name = 17;
|
||||
repeated string vars_name = 18;
|
||||
optional double float64 = 19;
|
||||
};
|
||||
|
||||
message Var {
|
||||
@@ -84,6 +91,8 @@ message OpProto {
|
||||
optional bool duplicable = 3 [ default = false ];
|
||||
optional bool intermediate = 4 [ default = false ];
|
||||
optional bool dispensable = 5 [ default = false ];
|
||||
optional bool extra = 6 [ default = false ];
|
||||
optional bool quant = 7 [ default = false ];
|
||||
}
|
||||
|
||||
// AttrProto describes the C++ type Attribute.
|
||||
@@ -95,6 +104,9 @@ message OpProto {
|
||||
// language binding has responsibility to fill that
|
||||
// attribute. End-User should not set that attribute.
|
||||
optional bool generated = 4 [ default = false ];
|
||||
optional bool extra = 5 [ default = false ];
|
||||
optional bool quant = 6 [ default = false ];
|
||||
optional bool support_tensor = 7 [ default = false];
|
||||
}
|
||||
|
||||
required string type = 1;
|
||||
@@ -137,6 +149,13 @@ message VarType {
|
||||
// in operators like nccl_op
|
||||
RAW = 17;
|
||||
TUPLE = 18;
|
||||
|
||||
STRING = 25;
|
||||
STRINGS = 26;
|
||||
VOCAB = 27;
|
||||
FEED_LIST = 28;
|
||||
// The data type of phi::StringTensor
|
||||
PSTRING = 29;
|
||||
}
|
||||
|
||||
required Type type = 1;
|
||||
@@ -165,15 +184,31 @@ message VarType {
|
||||
|
||||
message Tuple { repeated Type element_type = 1; }
|
||||
optional Tuple tuple = 7;
|
||||
|
||||
optional TensorDesc string = 8;
|
||||
optional TensorDesc strings = 9;
|
||||
optional TensorDesc vocab = 10;
|
||||
}
|
||||
|
||||
message VarDesc {
|
||||
|
||||
message Attr {
|
||||
required string name = 1;
|
||||
required AttrType type = 2;
|
||||
optional int32 i = 3;
|
||||
optional string s = 4;
|
||||
repeated int32 ints = 5;
|
||||
};
|
||||
|
||||
required string name = 1;
|
||||
required VarType type = 2;
|
||||
optional bool persistable = 3 [ default = false ];
|
||||
// True if the variable is an input data and
|
||||
// have to check the feed data shape and dtype
|
||||
optional bool need_check_feed = 4 [ default = false ];
|
||||
optional bool is_parameter = 5 [ default = false ];
|
||||
optional bool stop_gradient = 6 [ default = false ];
|
||||
repeated Attr attrs = 7;
|
||||
}
|
||||
|
||||
message BlockDesc {
|
||||
|
||||
Reference in new issue
Block a user