Skip to content

Commit

Permalink
Merge branch 'yi3/rebase_1' into yi3/update_to_latest
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangYiIntel committed Apr 23, 2021
2 parents 4fb44e6 + f078fb8 commit 03d93cb
Show file tree
Hide file tree
Showing 60 changed files with 4,442 additions and 34 deletions.
18 changes: 18 additions & 0 deletions ngraph/frontend/paddlepaddle/src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,23 @@ std::vector<int64_t> DecoderPDPDProto::get_longs(const std::string& name, const
}
}

int64_t DecoderPDPDProto::get_long(const std::string& name, const int64_t& def) const
{
std::cout << "Running get_longs" << std::endl;
std::vector<proto::OpDesc_Attr> attrs;
for (const auto &attr : op.attrs()) {
if (attr.name() == name)
attrs.push_back(attr);
}
if (attrs.empty()) {
return def;
} else if (attrs.size() > 1) {
// TODO: raise exception here
return def;
} else {
return attrs[0].l();
}
}

}
}
1 change: 1 addition & 0 deletions ngraph/frontend/paddlepaddle/src/decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class DecoderPDPDProto
std::string get_str(const std::string& name, const std::string& def = "") const;
bool get_bool (const std::string& name, bool def = false) const;
std::vector<int64_t> get_longs(const std::string& name, const std::vector<int64_t>& def = {}) const;
int64_t get_long(const std::string& name, const int64_t& def = {}) const;

// TODO: Further populate get_XXX methods on demand
ngraph::element::Type get_dtype(const std::string& name, ngraph::element::Type def) const;
Expand Down
14 changes: 9 additions & 5 deletions ngraph/frontend/paddlepaddle/src/node_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ template <>
inline ngraph::element::Type NodeContext::get_attribute (const std::string& name, const ngraph::element::Type& def) const
{ return node.get_dtype(name, def); }

template <>
inline std::vector<int64_t> NodeContext::get_attribute (const std::string& name, const std::vector<int64_t>& def) const
{ return node.get_longs(name, def); }


inline NamedOutputs NodeContext::default_single_output_mapping(const std::shared_ptr<Node>& ngraph_node,
const std::vector<OutPortName>& required_pdpd_out_names) const
{
Expand All @@ -126,6 +121,15 @@ inline NamedOutputs NodeContext::default_single_output_mapping(const std::shared
}
return named_outputs;
}
template <>
inline std::vector<int64_t> NodeContext::get_attribute (const std::string& name, const std::vector<int64_t>& def) const
{ return node.get_longs(name, def); }

template <>
inline int64_t NodeContext::get_attribute (const std::string& name, const int64_t& def) const
{ return node.get_long(name, def); }


}
}
}
35 changes: 35 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/hard_sigmoid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// 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 <ngraph/opsets/opset6.hpp>
#include "hard_sigmoid.hpp"
#include <paddlepaddle_frontend/utility.hpp>

namespace ngraph {
namespace frontend {
namespace pdpd {
namespace op {

NamedOutputs hard_sigmoid (const NodeContext& node) {
auto data = node.get_ng_input("X");
auto slope = node.get_attribute<float>("slope");
PDPD_ASSERT(slope >= 0, "hard_sigmoid: slope must greater than 0!");
auto alpha = ngraph::opset6::Constant::create(ngraph::element::f32, {}, {slope});
auto beta = ngraph::opset6::Constant::create(ngraph::element::f32, {}, {node.get_attribute<float>("offset")});
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::HardSigmoid>(data, alpha, beta)}, {"Out"});
}

}}}}
27 changes: 27 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/hard_sigmoid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// 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 "node_context.hpp"

namespace ngraph {
namespace frontend {
namespace pdpd {
namespace op {

NamedOutputs hard_sigmoid (const NodeContext& node);

}}}}
43 changes: 43 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/hard_swish.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// 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 <ngraph/opsets/opset6.hpp>
#include "hard_swish.hpp"
#include <paddlepaddle_frontend/utility.hpp>

namespace ngraph {
namespace frontend {
namespace pdpd {
namespace op {

NamedOutputs hard_swish (const NodeContext& node) {
auto data = node.get_ng_input("X");
if (node.has_attribute<float>("threshold")) {
auto threshold = node.get_attribute<float>("threshold");
PDPD_ASSERT(std::abs(threshold - 6.0) < 0.001, "hard_swish: threshold must = 6.0.");
}
if (node.has_attribute<float>("scale")) {
auto scale = node.get_attribute<float>("scale");
PDPD_ASSERT(std::abs(scale - 6.0) < 0.001, "hard_swish: scale must = 6.0.");
}
if (node.has_attribute<float>("offset")) {
auto offset = node.get_attribute<float>("offset");
PDPD_ASSERT(std::abs(offset - 3.0) < 0.001, "hard_swish: offset must = 3.0.");
}
return node.default_single_output_mapping({std::make_shared<ngraph::opset6::HSwish>(data)}, {"Out"});
}

}}}}
27 changes: 27 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/hard_swish.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// 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 "node_context.hpp"

namespace ngraph {
namespace frontend {
namespace pdpd {
namespace op {

NamedOutputs hard_swish (const NodeContext& node);

}}}}
Loading

0 comments on commit 03d93cb

Please sign in to comment.