From 75088bbfd5d15b08a6a7d193f9bfc869682e8b4d Mon Sep 17 00:00:00 2001 From: zhangkaihuo Date: Thu, 3 Nov 2022 17:23:26 +0800 Subject: [PATCH] [Sparse] Unified api args name (#47529) (#47627) Unified api args name --- paddle/phi/api/yaml/sparse_backward.yaml | 2 +- paddle/phi/api/yaml/sparse_ops.yaml | 2 +- paddle/phi/infermeta/sparse/binary.cc | 4 ++-- paddle/phi/infermeta/sparse/binary.h | 2 +- paddle/phi/kernels/sparse/sparse_utils_kernel.h | 5 ++--- python/paddle/sparse/creation.py | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/paddle/phi/api/yaml/sparse_backward.yaml b/paddle/phi/api/yaml/sparse_backward.yaml index ffb5406436f..6503dbb46e8 100644 --- a/paddle/phi/api/yaml/sparse_backward.yaml +++ b/paddle/phi/api/yaml/sparse_backward.yaml @@ -325,7 +325,7 @@ func : softmax_csr_grad{sparse_csr, sparse_csr -> sparse_csr} - backward_op : sparse_coo_tensor_grad - forward : sparse_coo_tensor(Tensor values, Tensor indices, IntArray dense_shape) -> Tensor(out) + forward : sparse_coo_tensor(Tensor values, Tensor indices, int64_t[] shape) -> Tensor(out) args : (Tensor indices, Tensor out_grad) output : Tensor(values_grad) infer_meta : diff --git a/paddle/phi/api/yaml/sparse_ops.yaml b/paddle/phi/api/yaml/sparse_ops.yaml index fb1562520f9..015e7aef0ff 100644 --- a/paddle/phi/api/yaml/sparse_ops.yaml +++ b/paddle/phi/api/yaml/sparse_ops.yaml @@ -269,7 +269,7 @@ backward : softmax_grad - op : sparse_coo_tensor - args : (Tensor values, Tensor indices, IntArray dense_shape) + args : (Tensor values, Tensor indices, int64_t[] shape={}) output : Tensor(out) infer_meta : func : sparse::SparseCooTensorInferMeta diff --git a/paddle/phi/infermeta/sparse/binary.cc b/paddle/phi/infermeta/sparse/binary.cc index 1b86f00ac2e..650ab646639 100644 --- a/paddle/phi/infermeta/sparse/binary.cc +++ b/paddle/phi/infermeta/sparse/binary.cc @@ -136,9 +136,9 @@ void Pool3dInferMeta(const MetaTensor& x, void SparseCooTensorInferMeta(const MetaTensor& values, const MetaTensor& indices, - const IntArray& dense_shape, + const std::vector& shape, MetaTensor* out) { - out->set_dims(phi::make_ddim(dense_shape.GetData())); + out->set_dims(phi::make_ddim(shape)); out->set_dtype(values.dtype()); out->set_layout(values.layout()); } diff --git a/paddle/phi/infermeta/sparse/binary.h b/paddle/phi/infermeta/sparse/binary.h index 39d58bb539e..a2c3e6fe570 100644 --- a/paddle/phi/infermeta/sparse/binary.h +++ b/paddle/phi/infermeta/sparse/binary.h @@ -45,7 +45,7 @@ void Pool3dInferMeta(const MetaTensor& x, void SparseCooTensorInferMeta(const MetaTensor& values, const MetaTensor& indices, - const IntArray& dense_shape, + const std::vector& shape, MetaTensor* out); } // namespace sparse diff --git a/paddle/phi/kernels/sparse/sparse_utils_kernel.h b/paddle/phi/kernels/sparse/sparse_utils_kernel.h index fa16114e0f9..8639f914694 100644 --- a/paddle/phi/kernels/sparse/sparse_utils_kernel.h +++ b/paddle/phi/kernels/sparse/sparse_utils_kernel.h @@ -168,10 +168,9 @@ template void SparseCooTensorKernel(const Context& dev_ctx, const DenseTensor& values, const DenseTensor& indices, - const IntArray& dense_shape, + const std::vector& shape, SparseCooTensor* out) { - *out = - SparseCooTensor(indices, values, phi::make_ddim(dense_shape.GetData())); + *out = SparseCooTensor(indices, values, phi::make_ddim(shape)); } } // namespace sparse diff --git a/python/paddle/sparse/creation.py b/python/paddle/sparse/creation.py index 1237dff3522..a960e895ff2 100644 --- a/python/paddle/sparse/creation.py +++ b/python/paddle/sparse/creation.py @@ -180,7 +180,7 @@ def sparse_coo_tensor( inputs = {'values': values, 'indices': indices} if shape[0] is None: shape[0] = -1 - attrs = {'dense_shape': shape} + attrs = {'shape': shape} helper = LayerHelper(op_type) out = helper.create_sparse_variable_for_type_inference(dtype) helper.append_op( -- GitLab