Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5cd6a707
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5cd6a707
编写于
10月 09, 2022
作者:
Z
zhangkaihuo
提交者:
GitHub
10月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sync_batch_norm_kernel (#46430)
上级
912be4f8
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
292 addition
and
6 deletion
+292
-6
paddle/fluid/operators/sparse_manual_op.cc
paddle/fluid/operators/sparse_manual_op.cc
+1
-1
paddle/phi/api/yaml/sparse_backward.yaml
paddle/phi/api/yaml/sparse_backward.yaml
+12
-0
paddle/phi/api/yaml/sparse_ops.yaml
paddle/phi/api/yaml/sparse_ops.yaml
+10
-0
paddle/phi/kernels/sparse/gpu/sync_batch_norm_grad_kernel.cu
paddle/phi/kernels/sparse/gpu/sync_batch_norm_grad_kernel.cu
+85
-0
paddle/phi/kernels/sparse/gpu/sync_batch_norm_kernel.cu
paddle/phi/kernels/sparse/gpu/sync_batch_norm_kernel.cu
+84
-0
paddle/phi/kernels/sparse/sync_batch_norm_grad_kernel.h
paddle/phi/kernels/sparse/sync_batch_norm_grad_kernel.h
+47
-0
paddle/phi/kernels/sparse/sync_batch_norm_kernel.h
paddle/phi/kernels/sparse/sync_batch_norm_kernel.h
+47
-0
python/paddle/incubate/sparse/nn/layer/norm.py
python/paddle/incubate/sparse/nn/layer/norm.py
+6
-5
未找到文件。
paddle/fluid/operators/sparse_manual_op.cc
浏览文件 @
5cd6a707
...
...
@@ -213,7 +213,7 @@ class SparseBatchNormOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr
<
bool
>
(
"fuse_with_relu"
,
"(bool), attribute 4 for sparse_batch_norm op."
);
AddComment
(
R"DOC(
TODO: Documentation of sparse_
conv3d
op.
TODO: Documentation of sparse_
batch_norm
op.
)DOC"
);
}
};
...
...
paddle/phi/api/yaml/sparse_backward.yaml
浏览文件 @
5cd6a707
...
...
@@ -356,6 +356,18 @@
func
:
subtract_coo_coo_grad{sparse_coo, sparse_coo, sparse_coo -> sparse_coo, sparse_coo},
subtract_csr_csr_grad{sparse_csr, sparse_csr, sparse_csr -> sparse_csr, sparse_csr}
-
backward_op
:
sync_batch_norm_grad
forward
:
sync_batch_norm(Tensor x, Tensor scale, Tensor bias, Tensor mean, Tensor variance, float momentum, float epsilon, str data_layout, bool is_test, bool use_global_stats, bool trainable_statistics, bool fuse_with_relu) -> Tensor(out), Tensor(mean_out), Tensor(variance_out), Tensor(saved_mean), Tensor(saved_variance), Tensor(reserve_space)
args
:
(Tensor x, Tensor scale, Tensor bias, Tensor saved_mean, Tensor saved_variance, Tensor reserve_space, Tensor out_grad, float momentum, float epsilon, str data_layout, bool is_test, bool use_global_stats, bool trainable_statistics, bool fuse_with_relu)
output
:
Tensor(x_grad), Tensor(scale_grad), Tensor(bias_grad)
infer_meta
:
func
:
GeneralTernaryGradInferMeta
param
:
[
x
,
scale
,
bias
]
kernel
:
func
:
sync_batch_norm_coo_grad{sparse_coo, dense, dense, dense, dense, dense, sparse_coo -> sparse_coo, dense, dense}
data_type
:
out_grad
optional
:
reserve_space
-
backward_op
:
tan_grad
forward
:
tan(Tensor x) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad)
...
...
paddle/phi/api/yaml/sparse_ops.yaml
浏览文件 @
5cd6a707
...
...
@@ -479,3 +479,13 @@
transpose_csr{sparse_csr -> sparse_csr}
layout
:
x
backward
:
transpose_grad
-
op
:
sync_batch_norm
args
:
(Tensor x, Tensor scale, Tensor bias, Tensor mean, Tensor variance, float momentum, float epsilon, str data_layout, bool is_test, bool use_global_stats, bool trainable_statistics, bool fuse_with_relu)
output
:
Tensor(out), Tensor(mean_out), Tensor(variance_out), Tensor(saved_mean), Tensor(saved_variance), Tensor(reserve_space)
infer_meta
:
func
:
BatchNormInferMeta
kernel
:
func
:
sync_batch_norm_coo{sparse_coo, dense, dense, dense, dense -> sparse_coo, dense, dense, dense, dense, dense}
data_type
:
x
backward
:
sync_batch_norm_grad
paddle/phi/kernels/sparse/gpu/sync_batch_norm_grad_kernel.cu
0 → 100644
浏览文件 @
5cd6a707
/* 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/kernels/sparse/sync_batch_norm_grad_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/sparse/empty_kernel.h"
#include "paddle/phi/kernels/sync_batch_norm_grad_kernel.h"
namespace
phi
{
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
SyncBatchNormCooGradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
scale
,
const
DenseTensor
&
bias
,
const
DenseTensor
&
saved_mean
,
const
DenseTensor
&
saved_variance
,
const
paddle
::
optional
<
DenseTensor
>&
reserve_space
,
const
SparseCooTensor
&
y_grad
,
float
momentum
,
float
epsilon
,
const
std
::
string
&
data_layout
,
bool
is_test
,
bool
use_global_stats
,
bool
trainable_statistics
,
bool
fuse_with_relu
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
scale_grad
,
DenseTensor
*
bias_grad
)
{
EmptyLikeCooKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
x_grad
);
*
scale_grad
=
phi
::
EmptyLike
<
T
,
Context
>
(
dev_ctx
,
scale
);
*
bias_grad
=
phi
::
EmptyLike
<
T
,
Context
>
(
dev_ctx
,
bias
);
phi
::
SyncBatchNormGradKernel
<
T
,
Context
>
(
dev_ctx
,
x
.
values
(),
scale
,
bias
,
saved_mean
,
saved_variance
,
reserve_space
,
y_grad
.
values
(),
momentum
,
epsilon
,
data_layout
,
is_test
,
use_global_stats
,
trainable_statistics
,
fuse_with_relu
,
x_grad
->
mutable_values
(),
scale_grad
,
bias_grad
);
}
}
// namespace sparse
}
// namespace phi
#ifdef PADDLE_WITH_HIP
PD_REGISTER_KERNEL
(
sync_batch_norm_coo_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
SyncBatchNormCooGradKernel
,
float
,
phi
::
dtype
::
float16
)
{}
#else
PD_REGISTER_KERNEL
(
sync_batch_norm_coo_grad
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
SyncBatchNormCooGradKernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{}
#endif
paddle/phi/kernels/sparse/gpu/sync_batch_norm_kernel.cu
0 → 100644
浏览文件 @
5cd6a707
/* 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/kernels/sparse/sync_batch_norm_kernel.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/sparse/empty_kernel.h"
#include "paddle/phi/kernels/sync_batch_norm_kernel.h"
namespace
phi
{
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
SyncBatchNormCooKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
scale
,
const
DenseTensor
&
bias
,
const
DenseTensor
&
mean
,
const
DenseTensor
&
variance
,
float
momentum
,
float
epsilon
,
const
std
::
string
&
data_layout
,
bool
is_test
,
bool
use_global_stats
,
bool
trainable_statistics
,
bool
fuse_with_relu
,
SparseCooTensor
*
y
,
DenseTensor
*
mean_out
,
DenseTensor
*
variance_out
,
DenseTensor
*
saved_mean
,
DenseTensor
*
saved_variance
,
DenseTensor
*
reserve_space
)
{
EmptyLikeCooKernel
<
T
,
Context
>
(
dev_ctx
,
x
,
y
);
phi
::
SyncBatchNormKernel
<
T
,
Context
>
(
dev_ctx
,
x
.
values
(),
scale
,
bias
,
mean
,
variance
,
momentum
,
epsilon
,
data_layout
,
is_test
,
use_global_stats
,
trainable_statistics
,
fuse_with_relu
,
y
->
mutable_values
(),
mean_out
,
variance_out
,
saved_mean
,
saved_variance
,
reserve_space
);
y
->
SetIndicesDict
(
x
.
GetIndicesDict
());
}
}
// namespace sparse
}
// namespace phi
#ifdef PADDLE_WITH_HIP
PD_REGISTER_KERNEL
(
sync_batch_norm_coo
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
SyncBatchNormCooKernel
,
float
,
phi
::
dtype
::
float16
)
{}
#else
PD_REGISTER_KERNEL
(
sync_batch_norm_coo
,
GPU
,
ALL_LAYOUT
,
phi
::
sparse
::
SyncBatchNormCooKernel
,
float
,
double
,
phi
::
dtype
::
float16
)
{}
#endif
paddle/phi/kernels/sparse/sync_batch_norm_grad_kernel.h
0 → 100644
浏览文件 @
5cd6a707
/* 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. */
#pragma once
#include <string>
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
namespace
phi
{
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
SyncBatchNormCooGradKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
scale
,
const
DenseTensor
&
bias
,
const
DenseTensor
&
saved_mean
,
const
DenseTensor
&
saved_variance
,
const
paddle
::
optional
<
DenseTensor
>&
reserve_space
,
const
SparseCooTensor
&
y_grad
,
float
momentum
,
float
epsilon
,
const
std
::
string
&
data_layout
,
bool
is_test
,
bool
use_global_stats
,
bool
trainable_statistics
,
bool
fuse_with_relu
,
SparseCooTensor
*
x_grad
,
DenseTensor
*
scale_grad
,
DenseTensor
*
bias_grad
);
}
// namespace sparse
}
// namespace phi
paddle/phi/kernels/sparse/sync_batch_norm_kernel.h
0 → 100644
浏览文件 @
5cd6a707
/* 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. */
#pragma once
#include <string>
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
namespace
phi
{
namespace
sparse
{
template
<
typename
T
,
typename
Context
>
void
SyncBatchNormCooKernel
(
const
Context
&
dev_ctx
,
const
SparseCooTensor
&
x
,
const
DenseTensor
&
scale
,
const
DenseTensor
&
bias
,
const
DenseTensor
&
mean
,
const
DenseTensor
&
variance
,
float
momentum
,
float
epsilon
,
const
std
::
string
&
data_layout
,
bool
is_test
,
bool
use_global_stats
,
bool
trainable_statistics
,
bool
fuse_with_relu
,
SparseCooTensor
*
y
,
DenseTensor
*
mean_out
,
DenseTensor
*
variance_out
,
DenseTensor
*
saved_mean
,
DenseTensor
*
saved_variance
,
DenseTensor
*
reserve_space
);
}
// namespace sparse
}
// namespace phi
python/paddle/incubate/sparse/nn/layer/norm.py
浏览文件 @
5cd6a707
...
...
@@ -296,11 +296,12 @@ class SyncBatchNorm(paddle.nn.SyncBatchNorm):
bias_attr
,
data_format
,
name
)
def
forward
(
self
,
x
):
assert
x
.
is_sparse_coo
(
),
"SyncBatchNorm only support SparseTensor in COO format."
out
=
super
(
SyncBatchNorm
,
self
).
forward
(
x
.
values
())
return
paddle
.
incubate
.
sparse
.
sparse_coo_tensor
(
x
.
indices
(),
out
,
shape
=
x
.
shape
,
stop_gradient
=
x
.
stop_gradient
)
self
.
_check_data_format
()
sync_batch_norm_out
,
_
,
_
,
_
,
_
,
_
=
_C_ops
.
sparse_sync_batch_norm
(
x
,
self
.
weight
,
self
.
bias
,
self
.
_mean
,
self
.
_variance
,
self
.
_momentum
,
self
.
_epsilon
,
self
.
_data_format
,
not
self
.
training
,
False
,
False
,
False
)
return
sync_batch_norm_out
@
classmethod
def
convert_sync_batchnorm
(
cls
,
layer
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录