Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b6af72eb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2322
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b6af72eb
编写于
3月 28, 2023
作者:
R
RedContritio
提交者:
GitHub
3月 28, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support auto generate static for one_hot_v2 (#52134)
* support auto generate static for one_hot_v2 * format
上级
8c8c6d9d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
25 addition
and
157 deletion
+25
-157
paddle/fluid/eager/auto_code_generator/generator/python_c_gen.py
...fluid/eager/auto_code_generator/generator/python_c_gen.py
+2
-0
paddle/fluid/operators/generator/templates/operator_utils.c.j2
...e/fluid/operators/generator/templates/operator_utils.c.j2
+4
-4
paddle/fluid/operators/one_hot_v2_op.cc
paddle/fluid/operators/one_hot_v2_op.cc
+0
-116
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+10
-0
paddle/phi/api/yaml/static_ops.yaml
paddle/phi/api/yaml/static_ops.yaml
+9
-0
paddle/phi/ops/compat/one_hot_sig.cc
paddle/phi/ops/compat/one_hot_sig.cc
+0
-37
未找到文件。
paddle/fluid/eager/auto_code_generator/generator/python_c_gen.py
浏览文件 @
b6af72eb
...
@@ -92,6 +92,8 @@ static PyObject * eager_api_{}(PyObject *self, PyObject *args, PyObject *kwargs)
...
@@ -92,6 +92,8 @@ static PyObject * eager_api_{}(PyObject *self, PyObject *args, PyObject *kwargs)
PyThreadState *tstate = nullptr;
PyThreadState *tstate = nullptr;
try {{
try {{
VLOG(6) << "Running Eager Final State API: {}";
VLOG(6) << "Running Eager Final State API: {}";
VLOG(8) << "args count: " << (PyTuple_Size(args) / 2);
// Get EagerTensors from args
// Get EagerTensors from args
{}
{}
// Parse Attributes if needed
// Parse Attributes if needed
...
...
paddle/fluid/operators/generator/templates/operator_utils.c.j2
浏览文件 @
b6af72eb
...
@@ -107,10 +107,10 @@ AddAttr<{{typename | to_op_attr_type}}>("{{name}}", "({{typename | to_op_attr_ty
...
@@ -107,10 +107,10 @@ AddAttr<{{typename | to_op_attr_type}}>("{{name}}", "({{typename | to_op_attr_ty
{% if default_value == "DataType::UNDEFINED" %}
{% if default_value == "DataType::UNDEFINED" %}
-1
-1
{%- else %}
{%- else %}
static_cast<int>(framework::TransToProtoVarType(
experimental
::{{default_value}}))
static_cast<int>(framework::TransToProtoVarType(
phi
::{{default_value}}))
{%- endif %}
{%- endif %}
{%- elif typename == "DataLayout" %} {# does DataLayout need any processing?#}
{%- elif typename == "DataLayout" %} {# does DataLayout need any processing?#}
static_cast<int>(
experimental
::{{default_value}})
static_cast<int>(
phi
::{{default_value}})
{%- elif typename == "Place" %}{# construct a Place to get the type #}
{%- elif typename == "Place" %}{# construct a Place to get the type #}
static_cast<int>(phi::Place({{"phi::" if not default_value is initializer_list}}{{default_value}}).GetType())
static_cast<int>(phi::Place({{"phi::" if not default_value is initializer_list}}{{default_value}}).GetType())
{%- else %}{# pass through as-is #}
{%- else %}{# pass through as-is #}
...
@@ -385,7 +385,7 @@ phi::KernelKey GetKernelTypeForVar(
...
@@ -385,7 +385,7 @@ phi::KernelKey GetKernelTypeForVar(
var_name == "{{ skip_arg }}"
var_name == "{{ skip_arg }}"
{%- if skip_args_len != 1 and loop.index != skip_args_len %} || {% endif -%}
{%- if skip_args_len != 1 and loop.index != skip_args_len %} || {% endif -%}
{%- endfor -%}
{%- endfor -%}
){
)
{
{% if "skip_transform" in op["data_transform"] %}
{% if "skip_transform" in op["data_transform"] %}
return phi::KernelKey(phi::Backend::ALL_BACKEND,
return phi::KernelKey(phi::Backend::ALL_BACKEND,
expected_kernel_type.layout(),
expected_kernel_type.layout(),
...
@@ -400,7 +400,7 @@ phi::KernelKey GetKernelTypeForVar(
...
@@ -400,7 +400,7 @@ phi::KernelKey GetKernelTypeForVar(
return phi::KernelKey(tensor.place(), tensor.layout(), tensor.dtype());
return phi::KernelKey(tensor.place(), tensor.layout(), tensor.dtype());
}
}
{% endif %}
{% endif %}
else{
else
{
return phi::KernelKey(
return phi::KernelKey(
tensor.place(), tensor.layout(), expected_kernel_type.dtype());
tensor.place(), tensor.layout(), expected_kernel_type.dtype());
}
}
...
...
paddle/fluid/operators/one_hot_v2_op.cc
已删除
100644 → 0
浏览文件 @
8c8c6d9d
// Copyright (c) 2019 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 <vector>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/core/infermeta_utils.h"
#include "paddle/phi/infermeta/backward.h"
#include "paddle/phi/infermeta/unary.h"
namespace
paddle
{
namespace
operators
{
class
OneHotV2Op
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"X"
),
ctx
.
GetPlace
());
}
phi
::
KernelKey
GetKernelTypeForVar
(
const
std
::
string
&
var_name
,
const
phi
::
DenseTensor
&
tensor
,
const
phi
::
KernelKey
&
expected_kernel_type
)
const
override
{
if
(
var_name
==
"depth_tensor"
)
{
return
phi
::
KernelKey
(
phi
::
Backend
::
ALL_BACKEND
,
expected_kernel_type
.
layout
(),
expected_kernel_type
.
dtype
());
}
return
phi
::
KernelKey
(
tensor
.
place
(),
tensor
.
layout
(),
expected_kernel_type
.
dtype
());
}
};
class
OneHotV2OpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(phi::DenseTensor, phi::DenseTensor<int>) Input variable with "
"rank at least 2. "
"The last dimension of X should be 1. Each value of X is an index "
"to indicate the position."
);
AddInput
(
"depth_tensor"
,
"(Tensor, Tensor<int>), Length of one-hot vector"
)
.
AsDispensable
();
AddOutput
(
"Out"
,
"(Tensor, Tensor<float>) Output tensor with same rank as X. "
"The tensor consists of one-hot representations of values in X."
);
AddAttr
<
int
>
(
"depth"
,
"A positive integer to specify the length of one-hot vector."
)
.
SetDefault
(
-
1
);
AddAttr
<
int
>
(
"dtype"
,
"An integer to specify the data type of one-hot "
"vector. The default value is FP32."
)
.
SetDefault
(
paddle
::
framework
::
proto
::
VarType
::
FP32
);
AddAttr
<
bool
>
(
"allow_out_of_range"
,
"If it is set true and the input data is out of range, "
"the output tensor will be filled zeros. The default value "
"is false."
)
.
SetDefault
(
false
);
AddComment
(
R"DOC(
One Hot Operator. This operator creates the one-hot representations for input
index values. The following example will help to explain the function of this
operator:
X is a LoDTensor:
X.lod = [[0, 1, 4]]
X.shape = [4]
X.data = [1, 1, 3, 0]
set depth = 4
Out is a LoDTensor:
Out.lod = [[0, 1, 4]]
Out.shape = [4, 4]
Out.data = [[0., 1., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 0., 1.],
[1., 0., 0., 0.]]
)DOC"
);
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
one_hot_v2
,
OneHotInferShapeFunctor
,
PD_INFER_META
(
phi
::
OneHotRawInferMeta
));
REGISTER_OPERATOR
(
one_hot_v2
,
ops
::
OneHotV2Op
,
ops
::
OneHotV2OpMaker
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
paddle
::
framework
::
EmptyGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
OneHotInferShapeFunctor
);
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
b6af72eb
...
@@ -1328,6 +1328,16 @@
...
@@ -1328,6 +1328,16 @@
outputs
:
outputs
:
size
:
Out
size
:
Out
-
op
:
one_hot (one_hot_v2)
inputs
:
x
:
X
outputs
:
out
:
Out
scalar
:
depth
:
data_type
:
int
tensor_name
:
depth_tensor
-
op
:
overlap_add
-
op
:
overlap_add
backward
:
overlap_add_grad
backward
:
overlap_add_grad
inputs
:
inputs
:
...
...
paddle/phi/api/yaml/static_ops.yaml
浏览文件 @
b6af72eb
...
@@ -129,6 +129,15 @@
...
@@ -129,6 +129,15 @@
backend
:
x
backend
:
x
force_backend
:
force_cpu
force_backend
:
force_cpu
-
op
:
one_hot
args
:
(Tensor x, Scalar(int) depth = -1, DataType dtype = DataType::FLOAT32, bool allow_out_of_range =
false
)
output
:
Tensor(out)
infer_meta
:
func
:
OneHotRawInferMeta
kernel
:
func
:
one_hot_raw
data_type
:
x
-
op
:
reduce
-
op
:
reduce
args
:
(Tensor x, int ring_id = 0, int root_id = 0, int reduce_type = 0)
args
:
(Tensor x, int ring_id = 0, int root_id = 0, int reduce_type = 0)
output
:
Tensor(out)
output
:
Tensor(out)
...
...
paddle/phi/ops/compat/one_hot_sig.cc
已删除
100644 → 0
浏览文件 @
8c8c6d9d
// Copyright (c) 2022 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/phi/core/compat/op_utils.h"
namespace
phi
{
KernelSignature
OneHotOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
if
(
ctx
.
HasInput
(
"depth_tensor"
))
{
return
KernelSignature
(
"one_hot_raw"
,
{
"X"
},
{
"depth_tensor"
,
"dtype"
,
"allow_out_of_range"
},
{
"Out"
});
}
else
{
return
KernelSignature
(
"one_hot_raw"
,
{
"X"
},
{
"depth"
,
"dtype"
,
"allow_out_of_range"
},
{
"Out"
});
}
}
}
// namespace phi
PD_REGISTER_BASE_KERNEL_NAME
(
one_hot_v2
,
one_hot
);
PD_REGISTER_ARG_MAPPING_FN
(
one_hot_v2
,
phi
::
OneHotOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录