Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG FIX]Fix MetaTensor's bug when run infermeta #46265

Merged
merged 4 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions paddle/phi/core/meta_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ int64_t MetaTensor::numel() const {

DDim MetaTensor::dims() const {
ValidCheck(*this);
return tensor_->dims();
if (phi::SelectedRows::classof(tensor_)) {
return static_cast<SelectedRows*>(tensor_)->GetCompleteDims();
} else {
return tensor_->dims();
}
}

DataType MetaTensor::dtype() const {
Expand All @@ -61,9 +65,7 @@ void MetaTensor::set_dims(const DDim& dims) {
StringTensorUtils::GetMutableMeta(static_cast<StringTensor*>(tensor_))
->dims = dims;
} else if (phi::SelectedRows::classof(tensor_)) {
DenseTensorUtils::GetMutableMeta(
static_cast<SelectedRows*>(tensor_)->mutable_value())
->dims = dims;
static_cast<SelectedRows*>(tensor_)->set_height(dims[0]);
} else if (phi::SparseCooTensor::classof(tensor_)) {
DenseTensorUtils::GetMutableMeta(static_cast<SparseCooTensor*>(tensor_))
->dims = dims;
Expand Down Expand Up @@ -179,7 +181,6 @@ void MetaTensor::share_dims(const MetaTensor& meta_tensor) {
bool is_sparse_coo = phi::SparseCooTensor::classof(tensor_);
bool is_sparse_csr = phi::SparseCsrTensor::classof(tensor_);
if (is_dense_tensor || is_selected_rows || is_sparse_coo || is_sparse_csr) {
set_dims(meta_tensor.dims());
if (is_selected_rows) {
const auto in_tensor_base = meta_tensor.tensor();
PADDLE_ENFORCE_EQ(
Expand All @@ -191,6 +192,11 @@ void MetaTensor::share_dims(const MetaTensor& meta_tensor) {
auto* selected_rows_in = static_cast<SelectedRows*>(in_tensor_base);
selected_rows_out->set_rows(selected_rows_in->rows());
selected_rows_out->set_height(selected_rows_in->height());
DenseTensorUtils::GetMutableMeta(
static_cast<SelectedRows*>(tensor_)->mutable_value())
->dims = selected_rows_in->mutable_value()->dims();
} else {
set_dims(meta_tensor.dims());
}
} else {
PADDLE_THROW(phi::errors::Unimplemented(
Expand Down
5 changes: 1 addition & 4 deletions paddle/phi/core/selected_rows.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ class SelectedRows : public TensorBase,

/// \brief Returns the dims of the tensor.
/// \return The dims of the tensor.
const DDim& dims() const noexcept override {
return impl_->dims();
// return phi::make_ddim(dims);
}
const DDim& dims() const noexcept override { return impl_->dims(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里语义不正确的问题暂时没办法解决?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后期解决


/// \brief Returns the data type of the tensor.
/// \return The data type of the tensor.
Expand Down