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

[FrontEnd]enable PDPD 16 ops conversion Part2 #6632

Merged
merged 13 commits into from
Jul 30, 2021
26 changes: 26 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/conv2d_transpose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "conv2d_transpose.hpp"
#include <ngraph/opsets/opset6.hpp>
#include "conv2d_utils.hpp"

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs conv2d_transpose(const NodeContext& node)
{
return conv2d_base<opset6::GroupConvolutionBackpropData,
opset6::ConvolutionBackpropData>(node);
}

} // namespace op
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
20 changes: 20 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/conv2d_transpose.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once
#include "node_context.hpp"

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs conv2d_transpose(const NodeContext& node_context);
}
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
41 changes: 41 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/dropout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "dropout.hpp"
#include <ngraph/opsets/opset6.hpp>

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs dropout(const NodeContext& node)
{
auto data = node.get_ng_input("X");
auto dropout_implementation =
node.get_attribute<std::string>("dropout_implementation");
if (dropout_implementation == "downgrade_in_infer")
mangguo321 marked this conversation as resolved.
Show resolved Hide resolved
{
auto dropout_prob = ngraph::opset6::Constant::create(
ngraph::element::f32,
{1},
{1 - node.get_attribute<float>("dropout_prob")});
return node.default_single_output_mapping(
{std::make_shared<ngraph::opset6::Multiply>(data, dropout_prob)},
{"Out"});
}
else
{
return node.default_single_output_mapping(data.get_node_shared_ptr(),
{"Out"});
}
}

} // namespace op
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
20 changes: 20 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/dropout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once
#include "node_context.hpp"

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs dropout(const NodeContext& node);
}
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
27 changes: 27 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "equal.hpp"
#include <ngraph/opsets/opset6.hpp>

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs equal(const NodeContext& node)
{
auto data_x = node.get_ng_input("X");
auto data_y = node.get_ng_input("Y");
return node.default_single_output_mapping(
{std::make_shared<ngraph::opset6::Equal>(data_x, data_y)}, {"Out"});
zhangYiIntel marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace op
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
20 changes: 20 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/equal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once
#include "node_context.hpp"

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs equal(const NodeContext& node);
}
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
69 changes: 69 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/expand_v2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "expand_v2.hpp"
#include <ngraph/opsets/opset6.hpp>
#include <paddlepaddle_frontend/utility.hpp>

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs expand_v2(const NodeContext& node)
zhangYiIntel marked this conversation as resolved.
Show resolved Hide resolved
{
auto x = node.get_ng_input("X");
Output<Node> shape_expected_node;
if (node.has_ng_input("Shape"))
{
shape_expected_node = node.get_ng_input("Shape");
}
else if (node.has_ng_input("expand_shapes_tensor"))
{
auto inputs = node.get_ng_inputs("expand_shapes_tensor");
ngraph::NodeVector node_vec;
for (auto& input : inputs)
{
auto cast =
std::make_shared<ngraph::opset6::Convert>(input, element::i32);
node_vec.push_back(cast);
}
shape_expected_node = std::make_shared<ngraph::opset6::Concat>(node_vec, 0);
}
else
{
std::vector<int32_t> shape_expected;
if (node.has_attribute<std::vector<int32_t>>("shape"))
{
shape_expected = node.get_attribute<std::vector<int32_t>>("shape");
}
else
{
throw std::runtime_error("expand: has no shape attribute");
}
shape_expected_node = ngraph::opset6::Constant::create(
ngraph::element::i32, {shape_expected.size()}, shape_expected);
}
// if -1 in shape we will copy the orginal value from input
auto zero_node =
ngraph::opset6::Constant::create(ngraph::element::i32, {1}, {0});
auto mask_node =
std::make_shared<ngraph::opset6::Greater>(shape_expected_node, zero_node);
auto input_shape_node =
std::make_shared<ngraph::opset6::ShapeOf>(x, element::i32);
auto fixed_shape_node = std::make_shared<ngraph::opset6::Select>(
mask_node, shape_expected_node, input_shape_node);

return node.default_single_output_mapping(
{std::make_shared<ngraph::opset6::Broadcast>(x, fixed_shape_node)},
{"Out"});
}

} // namespace op
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
20 changes: 20 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/expand_v2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once
#include "node_context.hpp"

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs expand_v2(const NodeContext& node);
}
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
73 changes: 73 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/fill_constant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "fill_constant.hpp"
#include <ngraph/opsets/opset6.hpp>

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs fill_constant(const NodeContext& node)
{
auto shape = node.get_attribute<std::vector<int64_t>>("shape");
auto dtype = node.get_attribute<ngraph::element::Type>("dtype");
Output<Node> value_node;
Output<Node> shape_node;
if (node.has_ng_input("ValueTensor"))
{
value_node = node.get_ng_input("ValueTensor");
}
else if (dtype == element::i32)
{
int32_t value = static_cast<int32_t>(node.get_attribute<float>("value"));
value_node = opset6::Constant::create(dtype, {1}, {value});
}
else if (dtype == element::f32)
{
float value = node.get_attribute<float>("value");
value_node = opset6::Constant::create(dtype, {1}, {value});
}
else if (dtype == element::i64)
{
int64_t value = static_cast<int64_t>(node.get_attribute<float>("value"));
value_node = opset6::Constant::create(dtype, {1}, {value});
}
else
{
PDPD_ASSERT(false, "fill_constant only supports i32, f32, i64");
}

PDPD_ASSERT(shape.size() > 0 || node.has_ng_input("ShapeTensor") ||
node.has_ng_input("ShapeTensorList"),
"fill_constant shape not set");

if (node.has_ng_input("ShapeTensor"))
{
shape_node = node.get_ng_input("ShapeTensor");
}
else if (node.has_ng_input("ShapeTensorList"))
{
auto shape_tensor_list = node.get_ng_inputs("ShapeTensorList");
shape_node =
Output<Node>{std::make_shared<opset6::Concat>(shape_tensor_list, 0)};
}
else
{
shape_node = opset6::Constant::create(element::i64, {shape.size()}, shape);
}

return node.default_single_output_mapping(
{std::make_shared<ngraph::opset6::Broadcast>(value_node, shape_node)},
{"Out"});
}

} // namespace op
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
21 changes: 21 additions & 0 deletions ngraph/frontend/paddlepaddle/src/op/fill_constant.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "node_context.hpp"

namespace ngraph
{
namespace frontend
{
namespace pdpd
{
namespace op
{
NamedOutputs fill_constant(const NodeContext& node);
}
} // namespace pdpd
} // namespace frontend
} // namespace ngraph
Loading