-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1516 from zhanghonggeng/ignore_test_1
support conv3d_transpose uniform & fix some tests
- Loading branch information
Showing
16 changed files
with
468 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// 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. | ||
|
||
#include "paddle2onnx/mapper/nn/conv3d_transpose.h" | ||
|
||
namespace paddle2onnx { | ||
REGISTER_PIR_MAPPER(conv3d_transpose, Conv3dTransposeMapper) | ||
|
||
int32_t Conv3dTransposeMapper::GetMinOpsetVersion(bool verbose) { | ||
if (data_format_ != "NCHW" && data_format_ != "NHWC") { | ||
Error() << "[ERROR] only support NCDHW or NDHWC format for " | ||
"conv3d_transpose " | ||
<< std::endl; | ||
return -1; | ||
} | ||
return 7; | ||
} | ||
|
||
void Conv3dTransposeMapper::Opset7() { | ||
auto kernel_info = GetInput("filter"); | ||
auto input_info = GetInput("x"); | ||
auto output_info = GetOutput("out"); | ||
|
||
auto input = helper_->AutoCast( | ||
input_info[0].name, input_info[0].dtype, P2ODataType::FP32); | ||
if (data_format_ == "NHWC") { | ||
input = helper_->Transpose(input, {0, 4, 1, 2, 3}); // NDHWC -> NCDHW | ||
} | ||
|
||
auto kernel = helper_->AutoCast( | ||
kernel_info[0].name, kernel_info[0].dtype, P2ODataType::FP32); | ||
|
||
auto node = helper_->MakeNode("ConvTranspose", {input, kernel}); | ||
|
||
std::vector<int64_t> kernel_shape = {kernel_info[0].shape[2], | ||
kernel_info[0].shape[3], | ||
kernel_info[0].shape[4]}; | ||
AddAttribute(node, "kernel_shape", kernel_shape); | ||
|
||
AddAttribute(node, "dilations", dilations_); | ||
AddAttribute(node, "strides", strides_); | ||
AddAttribute(node, "group", groups_); | ||
|
||
if (padding_algorithm_ == "SAME") { | ||
AddAttribute(node, "auto_pad", "SAME_UPPER"); | ||
} else if (padding_algorithm_ == "VALID") { | ||
AddAttribute(node, "auto_pad", "VALID"); | ||
} else { | ||
std::vector<int64_t> paddings; | ||
if (paddings_.size() == 3) { | ||
paddings.insert(paddings.begin(), paddings_.begin(), paddings_.end()); | ||
paddings.insert(paddings.begin(), paddings_.begin(), paddings_.end()); | ||
} else { | ||
std::vector<int64_t> index = {0, 2, 4, 1, 3, 5}; | ||
for (auto& i : index) { | ||
paddings.push_back(paddings_[i]); | ||
} | ||
} | ||
AddAttribute(node, "pads", paddings); | ||
} | ||
|
||
if (!output_padding_.empty()) { | ||
AddAttribute(node, "output_padding", output_padding_); | ||
} | ||
|
||
auto output = node->output(0); | ||
if (data_format_ == "NHWC") { | ||
output = helper_->Transpose(output, {0, 2, 3, 4, 1}); // NCDHW -> NDHWC | ||
} | ||
helper_->AutoCast( | ||
output, output_info[0].name, P2ODataType::FP32, output_info[0].dtype); | ||
} | ||
} // namespace paddle2onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// 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. | ||
|
||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "paddle2onnx/mapper/mapper.h" | ||
|
||
namespace paddle2onnx { | ||
|
||
class Conv3dTransposeMapper : public Mapper { | ||
public: | ||
Conv3dTransposeMapper(const PaddlePirParser& p, | ||
OnnxHelper* helper, | ||
int64_t i, | ||
bool c) | ||
: Mapper(p, helper, i, c) { | ||
GetAttr("groups", &groups_); | ||
GetAttr("dilations", &dilations_); | ||
GetAttr("strides", &strides_); | ||
GetAttr("paddings", &paddings_); | ||
GetAttr("padding_algorithm", &padding_algorithm_); | ||
GetAttr("data_format", &data_format_); | ||
|
||
if (HasAttr("output_padding")) { | ||
GetAttr("output_padding", &output_padding_); | ||
} | ||
if (HasAttr("output_size")) { | ||
GetAttr("output_size", &output_size_); | ||
} | ||
} | ||
|
||
int32_t GetMinOpsetVersion(bool verbose) override; | ||
void Opset7() override; | ||
|
||
private: | ||
std::vector<int64_t> dilations_; | ||
std::vector<int64_t> strides_; | ||
std::vector<int64_t> paddings_; | ||
std::vector<int64_t> output_padding_; | ||
std::vector<int64_t> output_size_; | ||
std::string padding_algorithm_; | ||
std::string data_format_; | ||
int64_t groups_; | ||
}; | ||
|
||
} // namespace paddle2onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// 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. | ||
|
||
#include "paddle2onnx/mapper/tensor/uniform.h" | ||
|
||
namespace paddle2onnx { | ||
REGISTER_PIR_MAPPER(uniform, UniformMapper) | ||
|
||
int32_t UniformMapper::GetMinOpsetVersion(bool verbose) { return 7; } | ||
|
||
void UniformMapper::Opset7() { | ||
auto output_info = GetOutput("out"); | ||
auto shape_info = GetInput("shape"); | ||
auto min_info = GetInput("min"); | ||
auto max_info = GetInput("max"); | ||
|
||
if (min_info[0].Rank() != 0 || max_info[0].Rank() != 0) { | ||
Error() << "[ERROR] min/max must be scalar tensors for op " | ||
"uniform " | ||
<< std::endl; | ||
} | ||
std::vector<float> min_val{0.0f}, max_val{1.0f}; | ||
bool is_min_const = | ||
helper_->TryGetTensorValue<float>(min_info[0].name, &min_val); | ||
bool is_max_const = | ||
helper_->TryGetTensorValue<float>(max_info[0].name, &max_val); | ||
|
||
std::vector<int64_t> shape_values; | ||
helper_->TryGetTensorValue<int64_t>(shape_info[0].name, &shape_values); | ||
|
||
auto onnx_dtype = GetOnnxDtype(dtype_); | ||
|
||
auto random_node = | ||
helper_->MakeNode("RandomUniform", {}, {output_info[0].name}); | ||
|
||
AddAttribute(random_node, "shape", shape_values); | ||
AddAttribute(random_node, "low", min_val[0]); | ||
AddAttribute(random_node, "high", max_val[0]); | ||
AddAttribute(random_node, "dtype", static_cast<int64_t>(onnx_dtype)); | ||
if (seed_ != 0) { | ||
AddAttribute(random_node, "seed", static_cast<float>(seed_)); | ||
} | ||
} | ||
} // namespace paddle2onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// 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. | ||
|
||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "paddle2onnx/mapper/mapper.h" | ||
|
||
namespace paddle2onnx { | ||
|
||
class UniformMapper : public Mapper { | ||
public: | ||
UniformMapper(const PaddlePirParser& p, OnnxHelper* helper, int64_t i, bool c) | ||
: Mapper(p, helper, i, c) { | ||
GetAttr("dtype", &dtype_); | ||
GetAttr("seed", &seed_); | ||
} | ||
|
||
int32_t GetMinOpsetVersion(bool verbose) override; | ||
void Opset7() override; | ||
|
||
private: | ||
int64_t dtype_; | ||
int64_t seed_; | ||
}; | ||
|
||
} // namespace paddle2onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.