未验证 提交 dddc5d9d 编写于 作者: Z zhangkaihuo 提交者: GitHub

[cherry-pick]BatchNorm use inplace (#49529)

att, cherry-pick#48254, and resolve conflict
上级 34fafb11
...@@ -84,6 +84,8 @@ def main( ...@@ -84,6 +84,8 @@ def main(
backward_api_dict = to_named_dict(backward_apis) backward_api_dict = to_named_dict(backward_apis)
for api in apis: for api in apis:
if api['name'][-1] == '_':
api['name'] = api['name'][:-1]
api['op_name'] = SPARSE_OP_PREFIX + api['name'] api['op_name'] = SPARSE_OP_PREFIX + api['name']
api['name'] = api['op_name'] api['name'] = api['op_name']
if api["backward"] is not None: if api["backward"] is not None:
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
atanh_csr_grad {sparse_csr, sparse_csr -> sparse_csr} atanh_csr_grad {sparse_csr, sparse_csr -> sparse_csr}
- backward_op : batch_norm_grad - backward_op : batch_norm_grad
forward : 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) forward : 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 mean_out, Tensor variance_out, 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) args : (Tensor x, Tensor scale, Tensor bias, Tensor mean_out, Tensor variance_out, 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) output : Tensor(x_grad), Tensor(scale_grad), Tensor(bias_grad)
infer_meta : infer_meta :
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
layout : x layout : x
backward : atanh_grad backward : atanh_grad
- op : batch_norm - op : 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) 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) output : Tensor(out), Tensor(mean_out), Tensor(variance_out), Tensor(saved_mean), Tensor(saved_variance), Tensor(reserve_space)
infer_meta : infer_meta :
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
kernel : kernel :
func : batch_norm_coo {sparse_coo, dense, dense, dense, dense -> sparse_coo, dense, dense, dense, dense, dense} func : batch_norm_coo {sparse_coo, dense, dense, dense, dense -> sparse_coo, dense, dense, dense, dense, dense}
data_type : x data_type : x
view : (mean -> mean_out), (variance -> variance_out) inplace : (mean -> mean_out), (variance -> variance_out)
backward : batch_norm_grad backward : batch_norm_grad
- op : cast - op : cast
......
...@@ -23,7 +23,7 @@ namespace phi { ...@@ -23,7 +23,7 @@ namespace phi {
namespace sparse { namespace sparse {
template <typename T, typename Context> template <typename T, typename Context>
void BatchNormKernel(const Context& dev_ctx, void BatchNormCooKernel(const Context& dev_ctx,
const SparseCooTensor& x, const SparseCooTensor& x,
const DenseTensor& scale, const DenseTensor& scale,
const DenseTensor& bias, const DenseTensor& bias,
......
...@@ -138,7 +138,7 @@ class BatchNorm(paddle.nn.BatchNorm1D): ...@@ -138,7 +138,7 @@ class BatchNorm(paddle.nn.BatchNorm1D):
data_format = 'NCHW' if self._data_format[1] == 'C' else 'NHWC' data_format = 'NCHW' if self._data_format[1] == 'C' else 'NHWC'
if in_dynamic_mode(): if in_dynamic_mode():
batch_norm_out, _, _, _, _, _ = _C_ops.sparse_batch_norm( batch_norm_out, _, _, _, _, _ = _C_ops.sparse_batch_norm_(
input, input,
self.weight, self.weight,
self.bias, self.bias,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册