Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the mechanism #1487

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions paddle2onnx/mapper/mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,13 @@ class Mapper {
bool TryGetValue(const TensorInfo& info, std::vector<T>* data) {
return parser_->TryGetTensorValue(block_idx_, info.name, data);
}

void SetTensorArrayName(const std::string &arr_name) {
pir_parser_->SetTensorArrayName(pir_op_idx_, if_in_cf_block, arr_name);
}

std::string GetTensorArrayName() {
return pir_parser_->GetTensorArrayName(pir_op_idx_, if_in_cf_block);
}
};
} // namespace paddle2onnx
12 changes: 9 additions & 3 deletions paddle2onnx/mapper/onnx_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void AddAttribute(std::shared_ptr<ONNX_NAMESPACE::NodeProto> node,
}

ONNX_NAMESPACE::TensorProto_DataType GetOnnxDtype(int32_t paddle_dtype) {
Assert((paddle_dtype >= 0 && paddle_dtype <= 7) || paddle_dtype == 20 ||
paddle_dtype == 21,
Assert((paddle_dtype >= 0 && paddle_dtype <= 7) ||
(paddle_dtype >= 20 && paddle_dtype <= 24),
"Unknow paddle data type: " + std::to_string(paddle_dtype) +
" While call GetOnnxDtype.");
auto onnx_dtype = ONNX_NAMESPACE::TensorProto::FLOAT;
Expand All @@ -123,8 +123,14 @@ ONNX_NAMESPACE::TensorProto_DataType GetOnnxDtype(int32_t paddle_dtype) {
onnx_dtype = ONNX_NAMESPACE::TensorProto::FLOAT;
} else if (paddle_dtype == P2ODataType::FP64) {
onnx_dtype = ONNX_NAMESPACE::TensorProto::DOUBLE;
} else {
} else if (paddle_dtype == P2ODataType::UINT8) {
onnx_dtype = ONNX_NAMESPACE::TensorProto::UINT8;
} else if (paddle_dtype == P2ODataType::BF16) {
onnx_dtype = ONNX_NAMESPACE::TensorProto::BFLOAT16;
} else if (paddle_dtype == P2ODataType::COMPLEX64) {
onnx_dtype = ONNX_NAMESPACE::TensorProto::COMPLEX64;
} else if (paddle_dtype == P2ODataType::COMPLEX128) {
onnx_dtype = ONNX_NAMESPACE::TensorProto::COMPLEX128;
}
return onnx_dtype;
}
Expand Down
13 changes: 8 additions & 5 deletions paddle2onnx/mapper/register_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,26 @@ class MapperHelper {
}

bool IsRegisteredInPir(const std::string& op_name) {
static std::set<std::string> log_infos;
auto iter_pir = pir_mappers.find(op_name);
if (pir_mappers.end() != iter_pir) {
return true;
}
auto iter = mappers.find(op_name);
if (mappers.end() != iter) {
P2OLogger()
<< op_name
<< " is not registered in PIR mappers, but found in old ir mappers."
<< std::endl;
std::string log_info =
op_name +
" is not registered in new ir mappers, but found in old ir mappers.";
if (!log_infos.count(log_info)) {
log_infos.insert(log_info);
P2OLogger() << log_info << std::endl;
}
return false;
}
return false;
}

std::string GenName(const std::string& op_name) {
// std::string key = "p2o." + op_name + ".";
std::string key = op_name + ".";
if (name_counter.find(key) == name_counter.end()) {
name_counter[key] = 0;
Expand Down
15 changes: 5 additions & 10 deletions paddle2onnx/mapper/tensor/tensor_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ void CreateArrayMapper::Opset11() {
auto output_info = GetOutput(0);
auto node = helper_->MakeNode("SequenceEmpty", {}, {output_info[0].name});
AddAttribute(node, "dtype", GetOnnxDtype(dtype_));
pir_parser_->SetTensorArrayName(
pir_op_idx_, if_in_cf_block, output_info[0].name);
SetTensorArrayName(output_info[0].name);
}
int32_t ArrayLengthMapper::GetMinOpsetVersion(bool verbose) {
Logger(verbose, 11) << "ArrayLengthMapper " << RequireOpset(11) << std::endl;
return 11;
}
void ArrayLengthMapper::Opset11() {
auto output_info = GetOutput(0);
std::string arr_name =
pir_parser_->GetTensorArrayName(pir_op_idx_, if_in_cf_block);
std::string arr_name = GetTensorArrayName();
helper_->MakeNode("SequenceLength", {arr_name}, {output_info[0].name});
}
int32_t ArrayWriteMapper::GetMinOpsetVersion(bool verbose) {
Expand All @@ -55,13 +53,11 @@ void ArrayWriteMapper::Opset11() {
auto index_info = GetInput(2);
auto output_info = GetOutput(0);
auto squeeze_node = helper_->MakeNode("Squeeze", {index_info[0].name});
std::string arr_name =
pir_parser_->GetTensorArrayName(pir_op_idx_, if_in_cf_block);
std::string arr_name = GetTensorArrayName();
helper_->MakeNode("SequenceInsert",
{arr_name, tensor_info[0].name, squeeze_node->output(0)},
{output_info[0].name});
pir_parser_->SetTensorArrayName(
pir_op_idx_, if_in_cf_block, output_info[0].name);
SetTensorArrayName(output_info[0].name);
}
int32_t ArrayReadMapper::GetMinOpsetVersion(bool verbose) {
Logger(verbose, 11) << "ArrayReadMapper " << RequireOpset(11) << std::endl;
Expand All @@ -71,8 +67,7 @@ void ArrayReadMapper::Opset11() {
auto index_info = GetInput(1);
auto output_info = GetOutput(0);
auto squeeze_node = helper_->MakeNode("Squeeze", {index_info[0].name});
std::string arr_name =
pir_parser_->GetTensorArrayName(pir_op_idx_, if_in_cf_block);
std::string arr_name = GetTensorArrayName();
helper_->MakeNode(
"SequenceAt", {arr_name, squeeze_node->output(0)}, {output_info[0].name});
}
Expand Down
9 changes: 6 additions & 3 deletions paddle2onnx/parser/pir_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,14 @@ P2ODataType PaddlePirParser::TransPirDataType2OldIrDataType(
return P2ODataType::FP32;
} else if (dtype == phi::DataType::FLOAT64) {
return P2ODataType::FP64;
// } else if (dtype == phi::DataType::COMPLEX64) {
// } else if (dtype == phi::DataType::COMPLEX128) {
} else if (dtype == phi::DataType::COMPLEX64) {
return P2ODataType::COMPLEX64;
} else if (dtype == phi::DataType::COMPLEX128) {
return P2ODataType::COMPLEX128;
} else if (dtype == phi::DataType::FLOAT16) {
return P2ODataType::FP16;
// } else if (dtype == phi::DataType::BFLOAT16) {
} else if (dtype == phi::DataType::BFLOAT16) {
return P2ODataType::BF16;
} else {
Assert(false,
"Unsupported data type exists in "
Expand Down
9 changes: 9 additions & 0 deletions paddle2onnx/parser/tensor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ int32_t PaddleDataTypeSize(int32_t paddle_dtype) {
} else if (paddle_dtype ==
paddle2onnx::framework::proto::VarType_Type_UINT8) {
return sizeof(uint8_t);
} else if (paddle_dtype ==
paddle2onnx::framework::proto::VarType_Type_BF16) {
return sizeof(int16_t);
} else if (paddle_dtype ==
paddle2onnx::framework::proto::VarType_Type_COMPLEX64) {
return sizeof(float) * 2;
} else if (paddle_dtype ==
paddle2onnx::framework::proto::VarType_Type_COMPLEX128) {
return sizeof(double) * 2;
} else {
Assert(false, "Unexpected data type: " + std::to_string(paddle_dtype));
}
Expand Down
3 changes: 3 additions & 0 deletions paddle2onnx/parser/tensor_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ enum P2ODataType {
X19,
UINT8,
INT8,
BF16,
COMPLEX64,
COMPLEX128
};
int32_t PaddleDataTypeSize(int32_t paddle_dtype);

Expand Down
1 change: 1 addition & 0 deletions tests/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ set ignore=!ignore! test_auto_scan_conv2d.py
set ignore=!ignore! test_auto_scan_conv2d_transpose.py
set ignore=!ignore! test_auto_scan_conv3d.py
set ignore=!ignore! test_auto_scan_grid_sampler.py
set ignore=!ignore! test_auto_scan_set_value.py

REM Initialize bug count
set bug=0
Expand Down
3 changes: 2 additions & 1 deletion tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ ignore="test_auto_scan_multiclass_nms.py
test_resnet_fp16.py \
test_empty.py \
test_auto_scan_pool_max_ops.py \
test_auto_scan_fill_constant.py"
test_auto_scan_fill_constant.py \
test_auto_scan_set_value.py"
bug=0

# Install Python Packet
Expand Down
Loading