Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
3065fa2c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
3065fa2c
编写于
3月 22, 2023
作者:
W
Wang Xin
提交者:
GitHub
3月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add autogen code support for index_add op (#51887)
* add autogen code for index_add op * bug fixed
上级
8ef020c1
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
28 addition
and
175 deletion
+28
-175
paddle/fluid/operators/index_add_op.cc
paddle/fluid/operators/index_add_op.cc
+0
-118
paddle/phi/api/yaml/backward.yaml
paddle/phi/api/yaml/backward.yaml
+11
-0
paddle/phi/api/yaml/legacy_backward.yaml
paddle/phi/api/yaml/legacy_backward.yaml
+0
-11
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+0
-11
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+6
-0
paddle/phi/api/yaml/ops.yaml
paddle/phi/api/yaml/ops.yaml
+11
-0
paddle/phi/ops/compat/index_add_sig.cc
paddle/phi/ops/compat/index_add_sig.cc
+0
-35
未找到文件。
paddle/fluid/operators/index_add_op.cc
已删除
100644 → 0
浏览文件 @
8ef020c1
// 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 <memory>
#include "paddle/fluid/framework/infershape_utils.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/phi/infermeta/backward.h"
#include "paddle/phi/infermeta/binary.h"
namespace
paddle
{
namespace
operators
{
class
IndexAddOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"X"
),
ctx
.
GetPlace
());
}
};
class
IndexAddOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"X"
,
"(Tensor), "
"the input feature data of IndexAddOp, dtype should be"
"bool, int32, int64, float16, float32, float64."
);
AddInput
(
"Index"
,
"(Tensor), the 1-D tensor containing the indices to index."
);
AddInput
(
"AddValue"
,
"(Tensor), the tensor containing values to add."
);
AddOutput
(
"Out"
,
"(Tensor),"
" the output of IndexAddOp, whose dtype and shape are the same as X."
);
AddAttr
<
int
>
(
"axis"
,
"the dimension in which we index."
).
SetDefault
(
0
);
AddComment
(
R"DOC(
IndexAdd operator
Add the elements of the input tensor with value
by selecting the indices in the order given in index.
This operator also supports inplace modification.
)DOC"
);
}
};
template
<
typename
T
>
class
IndexAddGradMaker
:
public
framework
::
SingleGradOpMaker
<
T
>
{
public:
using
framework
::
SingleGradOpMaker
<
T
>::
SingleGradOpMaker
;
void
Apply
(
GradOpPtr
<
T
>
op
)
const
override
{
op
->
SetType
(
"index_add_grad"
);
op
->
SetInput
(
"Index"
,
this
->
Input
(
"Index"
));
op
->
SetInput
(
"AddValue"
,
this
->
Input
(
"AddValue"
));
op
->
SetInput
(
framework
::
GradVarName
(
"Out"
),
this
->
OutputGrad
(
"Out"
));
op
->
SetAttrMap
(
this
->
Attrs
());
op
->
SetOutput
(
framework
::
GradVarName
(
"X"
),
this
->
InputGrad
(
"X"
));
op
->
SetOutput
(
framework
::
GradVarName
(
"AddValue"
),
this
->
InputGrad
(
"AddValue"
));
}
};
class
IndexAddGradOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
phi
::
KernelKey
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
phi
::
KernelKey
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
framework
::
GradVarName
(
"Out"
)),
ctx
.
GetPlace
());
}
};
DECLARE_INPLACE_OP_INFERER
(
IndexAddInplaceInferer
,
{
"X"
,
"Out"
});
DECLARE_INPLACE_OP_INFERER
(
IndexAddGradInplaceInferer
,
{
framework
::
GradVarName
(
"Out"
),
framework
::
GradVarName
(
"X"
)});
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
DECLARE_INFER_SHAPE_FUNCTOR
(
index_add
,
IndexAddInferShapeFunctor
,
PD_INFER_META
(
phi
::
IndexAddInferMeta
));
REGISTER_OPERATOR
(
index_add
,
ops
::
IndexAddOp
,
ops
::
IndexAddOpMaker
,
ops
::
IndexAddGradMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
IndexAddGradMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
IndexAddInplaceInferer
,
IndexAddInferShapeFunctor
);
DECLARE_INFER_SHAPE_FUNCTOR
(
index_add_grad
,
IndexAddGradInferShapeFunctor
,
PD_INFER_META
(
phi
::
IndexAddGradInferMeta
));
REGISTER_OPERATOR
(
index_add_grad
,
ops
::
IndexAddGradOp
,
ops
::
IndexAddGradInplaceInferer
,
IndexAddGradInferShapeFunctor
);
paddle/phi/api/yaml/backward.yaml
浏览文件 @
3065fa2c
...
@@ -689,6 +689,17 @@
...
@@ -689,6 +689,17 @@
func
:
imag_grad
func
:
imag_grad
data_type
:
complex(out_grad)
data_type
:
complex(out_grad)
-
backward_op
:
index_add_grad
forward
:
index_add(Tensor x, Tensor index, Tensor add_value, int axis=0) -> Tensor(out)
args
:
(Tensor index, Tensor add_value, Tensor out_grad, int axis)
output
:
Tensor(x_grad), Tensor(add_value_grad)
infer_meta
:
func
:
IndexAddGradInferMeta
kernel
:
func
:
index_add_grad
data_type
:
out_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
index_sample_grad
-
backward_op
:
index_sample_grad
forward
:
index_sample (Tensor x, Tensor index) -> Tensor(out)
forward
:
index_sample (Tensor x, Tensor index) -> Tensor(out)
args
:
(Tensor x, Tensor index, Tensor out_grad)
args
:
(Tensor x, Tensor index, Tensor out_grad)
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
3065fa2c
...
@@ -574,17 +574,6 @@
...
@@ -574,17 +574,6 @@
kernel
:
kernel
:
func
:
huber_loss_grad
func
:
huber_loss_grad
-
backward_op
:
index_add_grad
forward
:
index_add(Tensor x, Tensor index, Tensor add_value, int axis) -> Tensor(out)
args
:
(Tensor index, Tensor add_value, Tensor out_grad, int axis)
output
:
Tensor(x_grad), Tensor(add_value_grad)
infer_meta
:
func
:
IndexAddGradInferMeta
kernel
:
func
:
index_add_grad
data_type
:
out_grad
inplace
:
(out_grad -> x_grad)
-
backward_op
:
instance_norm_double_grad
-
backward_op
:
instance_norm_double_grad
forward
:
instance_norm_grad(Tensor x, Tensor fwd_scale, Tensor saved_mean, Tensor saved_variance, Tensor grad_y, float epsilon) -> Tensor(grad_x), Tensor(grad_scale), Tensor(grad_bias)
forward
:
instance_norm_grad(Tensor x, Tensor fwd_scale, Tensor saved_mean, Tensor saved_variance, Tensor grad_y, float epsilon) -> Tensor(grad_x), Tensor(grad_scale), Tensor(grad_bias)
args
:
(Tensor x, Tensor fwd_scale, Tensor saved_mean, Tensor saved_variance, Tensor grad_y, Tensor grad_x_grad, Tensor grad_scale_grad, Tensor grad_bias_grad, float epsilon)
args
:
(Tensor x, Tensor fwd_scale, Tensor saved_mean, Tensor saved_variance, Tensor grad_y, Tensor grad_x_grad, Tensor grad_scale_grad, Tensor grad_bias_grad, float epsilon)
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
3065fa2c
...
@@ -831,17 +831,6 @@
...
@@ -831,17 +831,6 @@
func
:
increment
func
:
increment
inplace
:
(x -> out)
inplace
:
(x -> out)
-
op
:
index_add
args
:
(Tensor x, Tensor index, Tensor add_value, int axis)
output
:
Tensor(out)
infer_meta
:
func
:
IndexAddInferMeta
kernel
:
func
:
index_add
data_type
:
x
inplace
:
(x -> out)
backward
:
index_add_grad
-
op
:
instance_norm
-
op
:
instance_norm
args
:
(Tensor x, Tensor scale, Tensor bias, float epsilon)
args
:
(Tensor x, Tensor scale, Tensor bias, float epsilon)
output
:
Tensor(y), Tensor(saved_mean), Tensor(saved_variance)
output
:
Tensor(y), Tensor(saved_mean), Tensor(saved_variance)
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
3065fa2c
...
@@ -882,6 +882,12 @@
...
@@ -882,6 +882,12 @@
outputs
:
outputs
:
out
:
Out
out
:
Out
-
op
:
index_add
inputs
:
{
x
:
X
,
index
:
Index
,
add_value
:
AddValue
}
outputs
:
out
:
Out
-
op
:
index_sample
-
op
:
index_sample
inputs
:
inputs
:
{
x
:
X
,
index
:
Index
}
{
x
:
X
,
index
:
Index
}
...
...
paddle/phi/api/yaml/ops.yaml
浏览文件 @
3065fa2c
...
@@ -710,6 +710,17 @@
...
@@ -710,6 +710,17 @@
func
:
imag
func
:
imag
backward
:
imag_grad
backward
:
imag_grad
-
op
:
index_add
args
:
(Tensor x, Tensor index, Tensor add_value, int axis = 0)
output
:
Tensor(out)
infer_meta
:
func
:
IndexAddInferMeta
kernel
:
func
:
index_add
data_type
:
x
inplace
:
(x -> out)
backward
:
index_add_grad
-
op
:
index_sample
-
op
:
index_sample
args
:
(Tensor x, Tensor index)
args
:
(Tensor x, Tensor index)
output
:
Tensor
output
:
Tensor
...
...
paddle/phi/ops/compat/index_add_sig.cc
已删除
100644 → 0
浏览文件 @
8ef020c1
// 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
IndexAddOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"index_add"
,
{
"X"
,
"Index"
,
"AddValue"
},
{
"axis"
},
{
"Out"
});
}
KernelSignature
IndexAddGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"index_add_grad"
,
{
"Index"
,
"AddValue"
,
"Out@GRAD"
},
{
"axis"
},
{
"X@GRAD"
,
"AddValue@GRAD"
});
}
}
// namespace phi
PD_REGISTER_ARG_MAPPING_FN
(
index_add
,
phi
::
IndexAddOpArgumentMapping
);
PD_REGISTER_ARG_MAPPING_FN
(
index_add_grad
,
phi
::
IndexAddGradOpArgumentMapping
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录