Cherry-pick benchmark related changes from release/1.4 (#17156)
* cherry-pick commit fromrevert-17304-fix_default_paddle_version8877054
* cherry-pick commit from3f0b97d
* cherry-pick from 16691:Anakin subgraph support yolo_v3 and faster-rcnn (cherry picked from commit8643dbc233
) * Cherry-Pick from 16662 : Anakin subgraph cpu support (cherry picked from commit7ad182e16c
) * Cherry-pick from 1662, 16797.. : add anakin int8 support (cherry picked from commite14ab180fe
) * Cherry-pick from 16813 : change singleton to graph RegistBlock test=release/1.4 (cherry picked from commit4b9fa42307
) * Cherry Pick : 16837 Support ShuffleNet and MobileNet-v2 Support ShuffleNet and MobileNet-v2, test=release/1.4 (cherry picked from commita6fb066f90
) * Cherry-pick : anakin subgraph add opt config layout argument #16846 test=release/1.4 (cherry picked from commit8121b3eccb
) * 1. add shuffle_channel_detect (cherry picked from commit6efdea8997
) * update shuffle_channel op convert, test=release/1.4 (cherry picked from commite4726a066f
) * Modify symbol export rules test=develop
parent
16922e0093
commit
a72dbe9abf
@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2018 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 <string>
|
||||
|
||||
#include "paddle/fluid/framework/ir/graph_viz_pass.h"
|
||||
#include "paddle/fluid/framework/ir/shuffle_channel_detect_pass.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
namespace ir {
|
||||
|
||||
#define GET_IR_NODE(node__) GET_IR_NODE_FROM_SUBGRAPH(node__, node__, pattern);
|
||||
#define GET_NODES \
|
||||
GET_IR_NODE(reshape1_op); \
|
||||
GET_IR_NODE(reshape1_out); \
|
||||
GET_IR_NODE(transpose_op); \
|
||||
GET_IR_NODE(transpose_out); \
|
||||
GET_IR_NODE(reshape2_op); \
|
||||
GET_IR_NODE(reshape2_out);
|
||||
|
||||
void ShuffleChannelDetectPass::ApplyImpl(ir::Graph* graph) const {
|
||||
const std::string pattern_name = "shufflechannel_pattern";
|
||||
FusePassBase::Init(pattern_name, graph);
|
||||
|
||||
GraphPatternDetector gpd;
|
||||
auto* x = gpd.mutable_pattern()
|
||||
->NewNode("x")
|
||||
->assert_is_op_input("reshape2", "X")
|
||||
->AsInput();
|
||||
|
||||
patterns::ShuffleChannelPattern pattern(gpd.mutable_pattern(), pattern_name);
|
||||
pattern(x);
|
||||
|
||||
auto handler = [&](const GraphPatternDetector::subgraph_t& subgraph,
|
||||
Graph* g) {
|
||||
GET_NODES;
|
||||
|
||||
PADDLE_ENFORCE(subgraph.count(x));
|
||||
auto* input_node = subgraph.at(x);
|
||||
auto reshape1_desc = reshape1_op->Op();
|
||||
auto reshape2_desc = reshape2_op->Op();
|
||||
std::string input_name = input_node->Name();
|
||||
std::string output_name = reshape2_out->Name();
|
||||
|
||||
auto reshape1_shape =
|
||||
boost::get<std::vector<int>>(reshape1_desc->GetAttr("shape"));
|
||||
auto reshape2_shape =
|
||||
boost::get<std::vector<int>>(reshape2_desc->GetAttr("shape"));
|
||||
|
||||
int i_c = reshape1_shape[2];
|
||||
int o_c = reshape2_shape[1];
|
||||
int group = o_c / i_c;
|
||||
|
||||
framework::OpDesc new_op_desc;
|
||||
new_op_desc.SetType("shuffle_channel");
|
||||
new_op_desc.SetInput("X", {input_name});
|
||||
new_op_desc.SetOutput("Out", {output_name});
|
||||
|
||||
new_op_desc.SetAttr("group", group);
|
||||
new_op_desc.Flush();
|
||||
|
||||
// Create a new node for the fused op.
|
||||
auto* new_op = graph->CreateOpNode(&new_op_desc);
|
||||
|
||||
IR_NODE_LINK_TO(input_node, new_op);
|
||||
IR_NODE_LINK_TO(new_op, reshape2_out);
|
||||
|
||||
// Delete the unneeded nodes.
|
||||
GraphSafeRemoveNodes(graph, {reshape1_op, reshape1_out, transpose_op,
|
||||
transpose_out, reshape2_op});
|
||||
};
|
||||
|
||||
gpd(graph, handler);
|
||||
}
|
||||
|
||||
} // namespace ir
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
||||
|
||||
REGISTER_PASS(shuffle_channel_detect_pass,
|
||||
paddle::framework::ir::ShuffleChannelDetectPass);
|
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2018 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 <vector>
|
||||
#include "paddle/fluid/framework/ir/fuse_pass_base.h"
|
||||
#include "paddle/fluid/framework/ir/graph_pattern_detector.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
namespace ir {
|
||||
|
||||
class ShuffleChannelDetectPass : public FusePassBase {
|
||||
public:
|
||||
virtual ~ShuffleChannelDetectPass() {}
|
||||
|
||||
protected:
|
||||
void ApplyImpl(ir::Graph* graph) const override;
|
||||
};
|
||||
|
||||
} // namespace ir
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2018 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 "paddle/fluid/inference/anakin/convert/affine_channel.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "paddle/fluid/inference/anakin/convert/helper.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace inference {
|
||||
namespace anakin {
|
||||
|
||||
template <typename TargetT, ::anakin::Precision PrecisionT>
|
||||
void AffineChannelOpConverter<TargetT, PrecisionT>::operator()(
|
||||
const framework::proto::OpDesc &op, const framework::BlockDesc &block_desc,
|
||||
const framework::Scope &scope, bool test_mode) {
|
||||
framework::OpDesc op_desc(op, nullptr);
|
||||
PADDLE_ENFORCE_EQ(op_desc.Input("X").size(), 1);
|
||||
PADDLE_ENFORCE_EQ(op_desc.Output("Out").size(), 1);
|
||||
|
||||
auto op_name = op_desc.Type() + ":" + op_desc.Output("Out").front();
|
||||
auto input_name = op_desc.Input("X").front();
|
||||
auto output_name = op_desc.Output("Out").front();
|
||||
this->engine_->AddOp(op_name, "AffineChannel", {input_name}, {output_name});
|
||||
|
||||
// Copy the Scale to CPUPlace and get the pointer.
|
||||
auto *scale_v = scope.FindVar(op_desc.Input("Scale").front());
|
||||
PADDLE_ENFORCE_NOT_NULL(scale_v);
|
||||
auto weight1 = pblock_from_var<TargetT, PrecisionT>(*scale_v, this->engine_);
|
||||
this->engine_->AddOpAttr(op_name, "weight_1", *weight1);
|
||||
|
||||
// Copy the Bias to CPUPlace and get the pointer.
|
||||
auto *bias_v = scope.FindVar(op_desc.Input("Bias").front());
|
||||
PADDLE_ENFORCE_NOT_NULL(bias_v);
|
||||
auto weight2 = pblock_from_var<TargetT, PrecisionT>(*bias_v, this->engine_);
|
||||
this->engine_->AddOpAttr(op_name, "weight_2", *weight2);
|
||||
}
|
||||
|
||||
} // namespace anakin
|
||||
} // namespace inference
|
||||
} // namespace paddle
|
||||
|
||||
REGISTER_ANAKIN_OP_CONVERTER(affine_channel, AffineChannelOpConverter);
|
@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2018 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 <memory>
|
||||
#include "paddle/fluid/inference/anakin/convert/op_converter.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace inference {
|
||||
namespace anakin {
|
||||
|
||||
template <typename TargetT, ::anakin::Precision PrecisionT>
|
||||
class AffineChannelOpConverter : public AnakinOpConverter<TargetT, PrecisionT> {
|
||||
public:
|
||||
AffineChannelOpConverter() = default;
|
||||
|
||||
virtual void operator()(const framework::proto::OpDesc &op,
|
||||
const framework::BlockDesc &block_desc,
|
||||
const framework::Scope &scope,
|
||||
bool test_mode) override;
|
||||
virtual ~AffineChannelOpConverter() {}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace anakin
|
||||
} // namespace inference
|
||||
} // namespace paddle
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue