Skip to content

Commit

Permalink
Delete the code related to SetOpInputOutputIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
0x3878f committed Sep 29, 2024
2 parents 2711221 + 2ec91f3 commit ed1c9f2
Show file tree
Hide file tree
Showing 28 changed files with 30 additions and 170 deletions.
9 changes: 0 additions & 9 deletions paddle2onnx/mapper/activation/activation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,8 @@ int32_t ActivationMapper::GetMinOpsetVersion(bool verbose) {
return 7;
}

void ActivationMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
};
output_idx_ = {
{"Out", 0},
};
}

void ActivationMapper::Opset7() {
SetOpInputOutputIndex();
auto input_info = GetInput("X");
auto output_info = GetOutput("Out");
auto iter = op_mapper_.find(convert_pir_op_name(OpType()));
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/activation/activation.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class ActivationMapper : public Mapper {

int32_t GetMinOpsetVersion(bool verbose) override;
void Opset7() override;
void SetOpInputOutputIndex() override;

private:
std::map<std::string, std::string> op_mapper_;
Expand Down
10 changes: 0 additions & 10 deletions paddle2onnx/mapper/activation/relu6.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ namespace paddle2onnx {
REGISTER_MAPPER(relu6, Relu6Mapper)
REGISTER_PIR_MAPPER(relu6, Relu6Mapper)

void Relu6Mapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
};
output_idx_ = {
{"Out", 0},
};
}

void Relu6Mapper::Opset7() {
SetOpInputOutputIndex();
auto input_info = GetInput("X");
auto output_info = GetOutput("Out");
float min = 0.0;
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/activation/relu6.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ class Relu6Mapper : public Mapper {
: Mapper(p, helper, op_id) { in_pir_mode = true; }

void Opset7() override;
void SetOpInputOutputIndex() override;
};
}
25 changes: 10 additions & 15 deletions paddle2onnx/mapper/mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Mapper {
helper_ = helper;
name_ = name;
pir_op_idx_ = op_id;
// TODO(by wangmingkai02) call SetOpInputOutputIndex()
}

// [exported_op_name, domain]
Expand Down Expand Up @@ -165,15 +164,6 @@ class Mapper {
int32_t op_idx_;
int32_t pir_op_idx_;
std::string name_; // op transform name
std::unordered_map<std::string, int64_t> input_idx_;
std::unordered_map<std::string, int64_t> output_idx_;
virtual void SetOpInputOutputIndex() {
Assert(false,
"The error occurred because the " + name_ +
" Mapper class did not override the "
"SetOpInputOutputIndex function. Please double-check if the SetOpInputOutputIndex function is "
"implemented correctly.");
}

std::string OpType() const {
if (in_pir_mode) {
Expand All @@ -192,25 +182,29 @@ class Mapper {
std::string Name() const { return name_; }

bool HasInput(const std::string &name) const {
if (in_pir_mode) return pir_parser_->OpHasInput(pir_op_idx_, input_idx_.at(name));
if (in_pir_mode) {
int32_t value_idx = pir_parser_->GetOpInputOutputName2Idx(pir_op_idx_, name, true);
return pir_parser_->OpHasInput(pir_op_idx_, value_idx);
}
return parser_->OpHasInput(block_idx_, op_idx_, name);
}
bool HasOutput(const std::string &name) const {
if (in_pir_mode) return pir_parser_->OpHasOutput(pir_op_idx_, output_idx_.at(name));
if (in_pir_mode) {
int32_t value_idx = pir_parser_->GetOpInputOutputName2Idx(pir_op_idx_, name, false);
return pir_parser_->OpHasOutput(pir_op_idx_, value_idx);
}
return parser_->OpHasOutput(block_idx_, op_idx_, name);
}
std::vector<TensorInfo> GetInput(const std::string &name) const {
if (in_pir_mode) {
int32_t value_idx = pir_parser_->GetOpInputOutputName2Idx(pir_op_idx_, name, true);
// Assert(value_idx == input_idx_.at(name), "Input index not match\n");
return pir_parser_->GetOpInput(pir_op_idx_, value_idx);
}
return parser_->GetOpInput(block_idx_, op_idx_, name);
}
std::vector<TensorInfo> GetOutput(const std::string &name) const {
if (in_pir_mode) {
int32_t value_idx = pir_parser_->GetOpInputOutputName2Idx(pir_op_idx_, name, false);
// Assert(value_idx == output_idx_.at(name), "Output index not match\n");
return pir_parser_->GetOpOutput(pir_op_idx_, value_idx);
}
return parser_->GetOpOutput(block_idx_, op_idx_, name);
Expand All @@ -227,7 +221,8 @@ class Mapper {
}

std::vector<int64_t> GetInputAttrVar(const std::string &input_name, const std::string &attr_name) const {
return pir_parser_->GetOpAttrVar(pir_op_idx_, input_idx_.at(input_name), attr_name);
int32_t value_idx = pir_parser_->GetOpInputOutputName2Idx(pir_op_idx_, input_name, true);
return pir_parser_->GetOpAttrVar(pir_op_idx_, value_idx, attr_name);
}


Expand Down
13 changes: 0 additions & 13 deletions paddle2onnx/mapper/nn/batch_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,7 @@ namespace paddle2onnx {
REGISTER_MAPPER(batch_norm, BatchNormMapper)
REGISTER_PIR_MAPPER(batch_norm, BatchNormMapper)

void BatchNormMapper::SetOpInputOutputIndex()
{
input_idx_ = {
{"X", 0},
{"Mean", 1},
{"Variance", 2},
{"Scale", 3},
{"Bias", 4},
};
output_idx_ = {{"Y", 0}};
}

void BatchNormMapper::Opset7() {
SetOpInputOutputIndex();
auto input_info = GetInput("X");
auto scale_info = GetInput("Scale");
auto bias_info = GetInput("Bias");
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/nn/batch_norm.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class BatchNormMapper : public Mapper {
}

void Opset7() override;
void SetOpInputOutputIndex() override;

private:
bool is_test_;
Expand Down
10 changes: 0 additions & 10 deletions paddle2onnx/mapper/nn/conv2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,8 @@ int32_t Conv2dMapper::GetMinOpsetVersion(bool verbose) {
return 7;
}

void Conv2dMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"Input", 0},
{"Filter", 1},
};
output_idx_ = {
{"Output", 0},
};
}

void Conv2dMapper::Opset7() {
SetOpInputOutputIndex();
auto input_info = GetInput("Input");
auto kernel_info = GetInput("Filter");
auto output_info = GetOutput("Output");
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/nn/conv2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Conv2dMapper : public Mapper {

int32_t GetMinOpsetVersion(bool verbose) override;
void Opset7() override;
void SetOpInputOutputIndex() override;

private:
std::vector<int64_t> dilations_;
Expand Down
14 changes: 11 additions & 3 deletions paddle2onnx/mapper/nn/dropout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace paddle2onnx {

REGISTER_MAPPER(dropout, DropoutMapper)
REGISTER_PIR_MAPPER(dropout, DropoutMapper)

int32_t DropoutMapper::GetMinOpsetVersion(bool verbose) {
if (dropout_implementation_ != "downgrade_in_infer" &&
Expand Down Expand Up @@ -47,13 +48,20 @@ void DropoutMapper::Opset7() {
if (dropout_implementation_ == "upscale_in_train") {
helper_->MakeNode("Identity", {input_info[0].name}, {output_info[0].name});
} else {
if (IsAttrVar("dropout_prob")) {
auto prob_info = GetAttrVar("dropout_prob");
if (in_pir_mode) {
std::vector<float> temp;
auto prob_info = GetInput("Prob");
TryGetValue(prob_info[0], &temp);
dropout_prob_ = temp[0];
} else {
GetAttr("dropout_prob", &dropout_prob_);
if (IsAttrVar("dropout_prob")) {
auto prob_info = GetAttrVar("dropout_prob");
std::vector<float> temp;
TryGetValue(prob_info[0], &temp);
dropout_prob_ = temp[0];
} else {
GetAttr("dropout_prob", &dropout_prob_);
}
}
std::string scale_node = helper_->Constant(
{}, GetOnnxDtype(input_info[0].dtype), 1 - dropout_prob_);
Expand Down
7 changes: 7 additions & 0 deletions paddle2onnx/mapper/nn/dropout.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class DropoutMapper : public Mapper {
GetAttr("dropout_implementation", &dropout_implementation_);
}

DropoutMapper(const PaddlePirParser& p, OnnxHelper* helper,
int64_t op_id)
: Mapper(p, helper, op_id) {
in_pir_mode = true;
GetAttr("mode", &dropout_implementation_);
}

int32_t GetMinOpsetVersion(bool verbose) override;
void Opset7() override;

Expand Down
11 changes: 0 additions & 11 deletions paddle2onnx/mapper/nn/pool2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ void Pool2dMapper::NoAdaptivePool(const std::vector<TensorInfo>& input_info,
}

int32_t Pool2dMapper::GetMinOpsetVersion(bool verbose) {
SetOpInputOutputIndex();
// NHWC is not supported : todo support NHWC
if (data_format_ == "NHWC") {
Error() << "NHWC format is not supported." << std::endl;
Expand Down Expand Up @@ -270,17 +269,7 @@ int32_t Pool2dMapper::GetMinOpsetVersion(bool verbose) {
return 7;
}

void Pool2dMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
{"ksize", 1},
};
output_idx_ = {
{"Out", 0},
};
}
void Pool2dMapper::Opset7() {
SetOpInputOutputIndex();
auto input_info = GetInput("X");
auto output_info = GetOutput("Out");
if (in_pir_mode) {
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/nn/pool2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Pool2dMapper : public Mapper {
}
int32_t GetMinOpsetVersion(bool verbose) override;
void Opset7() override;
void SetOpInputOutputIndex() override;

private:
bool IsSameSpan(const int64_t& in_size, const int64_t& out_size);
Expand Down
30 changes: 0 additions & 30 deletions paddle2onnx/mapper/tensor/elementwise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,8 @@ int32_t ElementwiseMapper::GetMinOpsetVersion(bool verbose) {
return 7;
}

void ElementwiseMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
{"Y", 1},
};
output_idx_ = {
{"Out", 0},
};
}

void ElementwiseMapper::Opset7() {
SetOpInputOutputIndex();
auto input_x_info = GetInput("X");
auto input_y_info = GetInput("Y");
auto output_info = GetOutput("Out");
Expand Down Expand Up @@ -96,18 +86,8 @@ void ElementwiseMapper::Opset7() {
helper_->MakeNode("Identity", {output_name}, {output_info[0].name});
}
}
void ElementWiseModMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
{"Y", 1},
};
output_idx_ = {
{"Out", 0},
};
}

void ElementWiseModMapper::Opset10() {
SetOpInputOutputIndex();
auto input_x_info = GetInput("X");
auto input_y_info = GetInput("Y");
auto output_info = GetOutput("Out");
Expand Down Expand Up @@ -174,18 +154,8 @@ void ElementWiseModMapper::Opset10() {
{output_info[0].name});
}

void ElementWiseFloordivMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
{"Y", 1},
};
output_idx_ = {
{"Out", 0},
};
}

void ElementWiseFloordivMapper::Opset7() {
SetOpInputOutputIndex();
auto input_x_info = GetInput("X");
auto input_y_info = GetInput("Y");
auto output_info = GetOutput("Out");
Expand Down
3 changes: 0 additions & 3 deletions paddle2onnx/mapper/tensor/elementwise.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ElementwiseMapper : public Mapper {

int32_t GetMinOpsetVersion(bool verbose) override;
void Opset7() override;
void SetOpInputOutputIndex() override;

private:
std::map<std::string, std::string> op_mapper_;
Expand All @@ -77,7 +76,6 @@ class ElementWiseModMapper : public Mapper {
}

void Opset10() override;
void SetOpInputOutputIndex() override;
};

class ElementWiseFloordivMapper : public Mapper {
Expand All @@ -96,7 +94,6 @@ class ElementWiseFloordivMapper : public Mapper {
}

void Opset7() override;
void SetOpInputOutputIndex() override;

private:
int64_t axis_;
Expand Down
9 changes: 0 additions & 9 deletions paddle2onnx/mapper/tensor/flatten.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ namespace paddle2onnx {
REGISTER_MAPPER(flatten_contiguous_range, FlattenMapper)
REGISTER_PIR_MAPPER(flatten_contiguous_range, FlattenMapper)

void FlattenMapper::SetOpInputOutputIndex() {
input_idx_ = {
{"X", 0},
};
output_idx_ = {
{"Out", 0},
};
}
void FlattenMapper::Opset7() {
SetOpInputOutputIndex();
auto input_info = GetInput("X");
if (start_axis_ < 0) {
start_axis_ += input_info[0].Rank();
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/tensor/flatten.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class FlattenMapper : public Mapper {
}

void Opset7() override;
void SetOpInputOutputIndex() override;

private:
int64_t start_axis_;
Expand Down
7 changes: 0 additions & 7 deletions paddle2onnx/mapper/tensor/full.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@
namespace paddle2onnx {
REGISTER_PIR_MAPPER(full, FullMapper)

void FullMapper::SetOpInputOutputIndex() {
input_idx_ = {};
output_idx_ = {
{"Out", 0},
};
}
void FullMapper::Opset7() {
SetOpInputOutputIndex();
auto output_info = GetOutput("Out");
helper_->Constant(output_info[0].name, shape_,
GetOnnxDtype(output_info[0].dtype), value_);
Expand Down
1 change: 0 additions & 1 deletion paddle2onnx/mapper/tensor/full.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class FullMapper : public Mapper {
}

void Opset7() override;
void SetOpInputOutputIndex() override;

private:
std::string dtype_;
Expand Down
7 changes: 0 additions & 7 deletions paddle2onnx/mapper/tensor/full_int_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@
namespace paddle2onnx {
REGISTER_PIR_MAPPER(full_int_array, FullIntArrayMapper)

void FullIntArrayMapper::SetOpInputOutputIndex() {
input_idx_ = {};
output_idx_ = {
{"Out", 0},
};
}
void FullIntArrayMapper::Opset7() {
SetOpInputOutputIndex();
auto output_info = GetOutput("Out");
int64_t shape_dim = shape_values_.size();
std::vector<int64_t> shape_ = {shape_dim};
Expand Down
Loading

0 comments on commit ed1c9f2

Please sign in to comment.