From f9a0605dfce3c30d1eb6f456b78916e46430ad9d Mon Sep 17 00:00:00 2001 From: zhangkaihuo Date: Thu, 3 Nov 2022 11:56:00 +0800 Subject: [PATCH] [Sparse] Unified api args name (#47529) --- 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 b0a4a97ca5..54dec292ef 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 6e6fd07a24..ea35737a70 100644 --- a/paddle/phi/api/yaml/sparse_ops.yaml +++ b/paddle/phi/api/yaml/sparse_ops.yaml @@ -280,7 +280,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 1b86f00ac2..650ab64663 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 39d58bb539..a2c3e6fe57 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 fa16114e0f..8639f91469 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 6f0c9cb42e..7b23d73260 100644 --- a/python/paddle/sparse/creation.py +++ b/python/paddle/sparse/creation.py @@ -169,7 +169,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