Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a32c1391
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看板
未验证
提交
a32c1391
编写于
4月 23, 2023
作者:
Z
zhangyuqin1998
提交者:
GitHub
4月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete overwrite from gather_grad (#52707)
* delete overwrite from gather_grad * fix * Update gather_grad_kernel.cc
上级
7634a18a
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
13 addition
and
34 deletion
+13
-34
paddle/fluid/operators/gather_op.cc
paddle/fluid/operators/gather_op.cc
+1
-1
paddle/fluid/prim/api/composite_backward/composite_backward_api.h
...luid/prim/api/composite_backward/composite_backward_api.h
+0
-1
paddle/phi/api/yaml/legacy_backward.yaml
paddle/phi/api/yaml/legacy_backward.yaml
+2
-2
paddle/phi/api/yaml/op_compat.yaml
paddle/phi/api/yaml/op_compat.yaml
+0
-2
paddle/phi/kernels/cpu/gather_grad_kernel.cc
paddle/phi/kernels/cpu/gather_grad_kernel.cc
+2
-13
paddle/phi/kernels/gather_grad_kernel.h
paddle/phi/kernels/gather_grad_kernel.h
+0
-1
paddle/phi/kernels/gpu/gather_grad_kernel.cu
paddle/phi/kernels/gpu/gather_grad_kernel.cu
+2
-3
paddle/phi/kernels/xpu/gather_grad_kernel.cc
paddle/phi/kernels/xpu/gather_grad_kernel.cc
+2
-3
paddle/phi/ops/compat/gather_sig.cc
paddle/phi/ops/compat/gather_sig.cc
+4
-8
未找到文件。
paddle/fluid/operators/gather_op.cc
浏览文件 @
a32c1391
...
@@ -155,7 +155,7 @@ class GatherCompositeGradOpMaker : public prim::CompositeGradOpMakerBase {
...
@@ -155,7 +155,7 @@ class GatherCompositeGradOpMaker : public prim::CompositeGradOpMakerBase {
"We don't support dynamic index from tensor for gather composite "
"We don't support dynamic index from tensor for gather composite "
"grad for now. "
));
"grad for now. "
));
}
else
{
}
else
{
prim
::
gather_grad
<
prim
::
DescTensor
>
(
x
,
index
,
dout
,
axis
,
false
,
dx_ptr
);
prim
::
gather_grad
<
prim
::
DescTensor
>
(
x
,
index
,
dout
,
axis
,
dx_ptr
);
}
}
this
->
RecoverOutputName
(
dx
,
dx_name
);
this
->
RecoverOutputName
(
dx
,
dx_name
);
}
}
...
...
paddle/fluid/prim/api/composite_backward/composite_backward_api.h
浏览文件 @
a32c1391
...
@@ -121,7 +121,6 @@ void gather_grad(const Tensor& x,
...
@@ -121,7 +121,6 @@ void gather_grad(const Tensor& x,
const
Tensor
&
index
,
const
Tensor
&
index
,
const
Tensor
&
out_grad
,
const
Tensor
&
out_grad
,
const
Scalar
&
axis
,
const
Scalar
&
axis
,
bool
overwrite
,
Tensor
*
grad_x
)
{
Tensor
*
grad_x
)
{
auto
zero_tensor
=
full
<
T
>
(
phi
::
vectorize
(
x
.
dims
()),
0.0
,
x
.
dtype
());
auto
zero_tensor
=
full
<
T
>
(
phi
::
vectorize
(
x
.
dims
()),
0.0
,
x
.
dtype
());
std
::
vector
<
int
>
tmp_perm
;
std
::
vector
<
int
>
tmp_perm
;
...
...
paddle/phi/api/yaml/legacy_backward.yaml
浏览文件 @
a32c1391
...
@@ -418,7 +418,7 @@
...
@@ -418,7 +418,7 @@
-
backward_op
:
gather_grad
-
backward_op
:
gather_grad
forward
:
gather(Tensor x, Tensor index, Scalar axis=0) -> Tensor(out)
forward
:
gather(Tensor x, Tensor index, Scalar axis=0) -> Tensor(out)
args
:
(Tensor x, Tensor index, Tensor out_grad, Scalar axis=0
, bool overwrite=false
)
args
:
(Tensor x, Tensor index, Tensor out_grad, Scalar axis=0)
output
:
Tensor(x_grad)
output
:
Tensor(x_grad)
infer_meta
:
infer_meta
:
func
:
UnchangedInferMeta
func
:
UnchangedInferMeta
...
@@ -426,7 +426,7 @@
...
@@ -426,7 +426,7 @@
kernel
:
kernel
:
data_type
:
x
data_type
:
x
func
:
gather_grad
func
:
gather_grad
composite
:
gather_grad(x, index, out_grad, axis,
overwrite,
x_grad)
composite
:
gather_grad(x, index, out_grad, axis, x_grad)
no_need_buffer
:
x
no_need_buffer
:
x
-
backward_op
:
group_norm_grad
-
backward_op
:
group_norm_grad
...
...
paddle/phi/api/yaml/op_compat.yaml
浏览文件 @
a32c1391
...
@@ -955,8 +955,6 @@
...
@@ -955,8 +955,6 @@
-
op
:
gather
-
op
:
gather
backward
:
gather_grad
backward
:
gather_grad
extra
:
attrs
:
[
bool overwrite = true
]
-
op
:
gather_nd
-
op
:
gather_nd
backward
:
gather_nd_grad
backward
:
gather_nd_grad
...
...
paddle/phi/kernels/cpu/gather_grad_kernel.cc
浏览文件 @
a32c1391
...
@@ -28,7 +28,6 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -28,7 +28,6 @@ void GatherGradKernel(const Context& dev_ctx,
const
DenseTensor
&
index
,
const
DenseTensor
&
index
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
out_grad
,
const
Scalar
&
axis
,
const
Scalar
&
axis
,
bool
overwrite
,
DenseTensor
*
x_grad
)
{
DenseTensor
*
x_grad
)
{
const
auto
&
index_type
=
index
.
dtype
();
const
auto
&
index_type
=
index
.
dtype
();
auto
axis_v
=
axis
.
to
<
int
>
();
auto
axis_v
=
axis
.
to
<
int
>
();
...
@@ -52,19 +51,9 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -52,19 +51,9 @@ void GatherGradKernel(const Context& dev_ctx,
if
(
x_grad
->
numel
()
==
0
)
return
;
if
(
x_grad
->
numel
()
==
0
)
return
;
if
(
index_type
==
phi
::
DataType
::
INT32
)
{
if
(
index_type
==
phi
::
DataType
::
INT32
)
{
if
(
overwrite
)
{
phi
::
funcs
::
ScatterAssignAdd
<
T
,
int32_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
);
phi
::
funcs
::
ScatterAssign
<
T
,
int32_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
);
}
else
{
phi
::
funcs
::
ScatterAssignAdd
<
T
,
int32_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
);
}
}
else
if
(
index_type
==
phi
::
DataType
::
INT64
)
{
}
else
if
(
index_type
==
phi
::
DataType
::
INT64
)
{
if
(
overwrite
)
{
phi
::
funcs
::
ScatterAssignAdd
<
T
,
int64_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
);
phi
::
funcs
::
ScatterAssign
<
T
,
int64_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
);
}
else
{
phi
::
funcs
::
ScatterAssignAdd
<
T
,
int64_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
);
}
}
else
{
}
else
{
PADDLE_THROW
(
phi
::
errors
::
InvalidArgument
(
PADDLE_THROW
(
phi
::
errors
::
InvalidArgument
(
"The data type of Input(Index) of gather_grad must be int32 or int64 "
"The data type of Input(Index) of gather_grad must be int32 or int64 "
...
...
paddle/phi/kernels/gather_grad_kernel.h
浏览文件 @
a32c1391
...
@@ -25,7 +25,6 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -25,7 +25,6 @@ void GatherGradKernel(const Context& dev_ctx,
const
DenseTensor
&
index
,
const
DenseTensor
&
index
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
out_grad
,
const
Scalar
&
axis
,
const
Scalar
&
axis
,
bool
overwrite
,
DenseTensor
*
x_grad
);
DenseTensor
*
x_grad
);
}
// namespace phi
}
// namespace phi
paddle/phi/kernels/gpu/gather_grad_kernel.cu
浏览文件 @
a32c1391
...
@@ -28,7 +28,6 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -28,7 +28,6 @@ void GatherGradKernel(const Context& dev_ctx,
const
DenseTensor
&
index
,
const
DenseTensor
&
index
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
out_grad
,
const
Scalar
&
axis
,
const
Scalar
&
axis
,
bool
overwrite
,
DenseTensor
*
x_grad
)
{
DenseTensor
*
x_grad
)
{
const
auto
&
index_type
=
index
.
dtype
();
const
auto
&
index_type
=
index
.
dtype
();
auto
axis_v
=
axis
.
to
<
int
>
();
auto
axis_v
=
axis
.
to
<
int
>
();
...
@@ -51,10 +50,10 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -51,10 +50,10 @@ void GatherGradKernel(const Context& dev_ctx,
if
(
out_grad
.
numel
()
==
0
)
return
;
if
(
out_grad
.
numel
()
==
0
)
return
;
if
(
index_type
==
DataType
::
INT32
)
{
if
(
index_type
==
DataType
::
INT32
)
{
phi
::
funcs
::
GPUScatterAssign
<
T
,
int
>
(
phi
::
funcs
::
GPUScatterAssign
<
T
,
int
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
,
overwrit
e
);
dev_ctx
,
out_grad
,
index
,
x_grad
,
fals
e
);
}
else
if
(
index_type
==
DataType
::
INT64
)
{
}
else
if
(
index_type
==
DataType
::
INT64
)
{
phi
::
funcs
::
GPUScatterAssign
<
T
,
int64_t
>
(
phi
::
funcs
::
GPUScatterAssign
<
T
,
int64_t
>
(
dev_ctx
,
out_grad
,
index
,
x_grad
,
overwrit
e
);
dev_ctx
,
out_grad
,
index
,
x_grad
,
fals
e
);
}
else
{
}
else
{
PADDLE_THROW
(
phi
::
errors
::
InvalidArgument
(
PADDLE_THROW
(
phi
::
errors
::
InvalidArgument
(
"The data type of Input(Index) of gather_grad must be int32 or int64 "
"The data type of Input(Index) of gather_grad must be int32 or int64 "
...
...
paddle/phi/kernels/xpu/gather_grad_kernel.cc
浏览文件 @
a32c1391
...
@@ -25,7 +25,6 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -25,7 +25,6 @@ void GatherGradKernel(const Context& dev_ctx,
const
DenseTensor
&
index
,
const
DenseTensor
&
index
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
out_grad
,
const
Scalar
&
axis
,
const
Scalar
&
axis
,
bool
overwrite
,
DenseTensor
*
x_grad
)
{
DenseTensor
*
x_grad
)
{
auto
axis_v
=
axis
.
to
<
int
>
();
auto
axis_v
=
axis
.
to
<
int
>
();
const
auto
&
index_type
=
index
.
dtype
();
const
auto
&
index_type
=
index
.
dtype
();
...
@@ -68,7 +67,7 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -68,7 +67,7 @@ void GatherGradKernel(const Context& dev_ctx,
xshape
,
xshape
,
index
.
dims
().
size
()
==
0
?
1
:
index
.
dims
()[
0
],
index
.
dims
().
size
()
==
0
?
1
:
index
.
dims
()[
0
],
axis_v
,
axis_v
,
overwrit
e
);
fals
e
);
}
else
{
}
else
{
xpu
::
ctx_guard
RAII_GUARD
(
dev_ctx
.
x_context
());
xpu
::
ctx_guard
RAII_GUARD
(
dev_ctx
.
x_context
());
int
*
index_int_ptr_l3
=
RAII_GUARD
.
alloc_l3_or_gm
<
int32_t
>
(
index
.
numel
());
int
*
index_int_ptr_l3
=
RAII_GUARD
.
alloc_l3_or_gm
<
int32_t
>
(
index
.
numel
());
...
@@ -86,7 +85,7 @@ void GatherGradKernel(const Context& dev_ctx,
...
@@ -86,7 +85,7 @@ void GatherGradKernel(const Context& dev_ctx,
xshape
,
xshape
,
index
.
dims
().
size
()
==
0
?
1
:
index
.
dims
()[
0
],
index
.
dims
().
size
()
==
0
?
1
:
index
.
dims
()[
0
],
axis_v
,
axis_v
,
overwrit
e
);
fals
e
);
}
}
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"gather_grad"
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"gather_grad"
);
}
}
...
...
paddle/phi/ops/compat/gather_sig.cc
浏览文件 @
a32c1391
...
@@ -26,15 +26,11 @@ KernelSignature GatherOpArgumentMapping(const ArgumentMappingContext& ctx) {
...
@@ -26,15 +26,11 @@ KernelSignature GatherOpArgumentMapping(const ArgumentMappingContext& ctx) {
KernelSignature
GatherGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
KernelSignature
GatherGradOpArgumentMapping
(
const
ArgumentMappingContext
&
ctx
)
{
if
(
ctx
.
HasInput
(
"Axis"
))
{
if
(
ctx
.
HasInput
(
"Axis"
))
{
return
KernelSignature
(
"gather_grad"
,
return
KernelSignature
(
{
"X"
,
"Index"
,
"Out@GRAD"
},
"gather_grad"
,
{
"X"
,
"Index"
,
"Out@GRAD"
},
{
"Axis"
},
{
"X@GRAD"
});
{
"Axis"
,
"overwrite"
},
{
"X@GRAD"
});
}
else
{
}
else
{
return
KernelSignature
(
"gather_grad"
,
return
KernelSignature
(
{
"X"
,
"Index"
,
"Out@GRAD"
},
"gather_grad"
,
{
"X"
,
"Index"
,
"Out@GRAD"
},
{
"axis"
},
{
"X@GRAD"
});
{
"axis"
,
"overwrite"
},
{
"X@GRAD"
});
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录