未验证 提交 0e6ff923 编写于 作者: Z zhupengyang 提交者: GitHub

[NPU] enhance dropout (#3669)

上级 73d16a07
...@@ -34,8 +34,6 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) { ...@@ -34,8 +34,6 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto x_name = op_info->Input("X").front(); auto x_name = op_info->Input("X").front();
auto x = scope->FindMutableTensor(x_name); auto x = scope->FindMutableTensor(x_name);
auto x_dims = x->dims(); auto x_dims = x->dims();
auto x_rank = x_dims.size();
CHECK_GE(x_rank, 2);
auto out_name = op_info->Output("Out").front(); auto out_name = op_info->Output("Out").front();
...@@ -45,9 +43,6 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) { ...@@ -45,9 +43,6 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
if (dropout_implementation == "upscale_in_train") { if (dropout_implementation == "upscale_in_train") {
scale = 1.f; scale = 1.f;
} }
// HiAI only support [n, c, 1, 1] for the shape of scale
std::vector<int64_t> scale_shape = {
1, x_rank < 3 ? 1 : x_dims[x_rank - 3], 1, 1};
// X node // X node
std::shared_ptr<Node> x_node = nullptr; std::shared_ptr<Node> x_node = nullptr;
...@@ -61,11 +56,7 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) { ...@@ -61,11 +56,7 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto scale_node = graph->Add<ge::op::Scale>(out_name); auto scale_node = graph->Add<ge::op::Scale>(out_name);
auto scale_op = scale_node->data<ge::op::Scale>(); auto scale_op = scale_node->data<ge::op::Scale>();
scale_op->set_input_x(*x_node->data()); scale_op->set_input_x(*x_node->data());
scale_op->set_attr_axis(1); scale_op->set_attr_filler_value(scale);
// Add filter node(fill with scale)
auto filter_node = graph->Add(out_name + "/filter", scale, scale_shape);
scale_op->set_input_filter(*filter_node->data());
return REBUILD_WHEN_SHAPE_CHANGED; return REBUILD_WHEN_SHAPE_CHANGED;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册