未验证 提交 ceb3382b 编写于 作者: A Aurelius84 提交者: GitHub

[Eager] Fix empty tensor Initializer bug with shape=[] (#41374)

* [Eager] Fix empty tensor Initializer bug with shape=[]

* [Eager] Fix empty tensor Initializer bug with shape=[]

* ignore two unittest

* fix unittest
上级 93ea1297
......@@ -72,11 +72,20 @@ void EmptyTensorInitializer(TensorObject* self, const std::string& name,
}
if (var_type == paddle::framework::proto::VarType::LOD_TENSOR) {
// TODO(jiabin): Maybe support LOD later
std::shared_ptr<phi::DenseTensor> dense_tensor =
std::make_shared<phi::DenseTensor>(
phi::make_intrusive<paddle::experimental::SharedStorage>(place),
phi::DenseTensorMeta(paddle::framework::TransToPhiDataType(dtype),
ddims));
std::shared_ptr<phi::DenseTensor> dense_tensor = nullptr;
if (dims.empty()) {
std::shared_ptr<phi::Allocation> allocation_ptr = nullptr;
dense_tensor = std::make_shared<phi::DenseTensor>(
allocation_ptr,
phi::DenseTensorMeta(paddle::framework::TransToPhiDataType(dtype),
ddims));
} else {
// TODO(dev): we need enhance check for ddims.
dense_tensor = std::make_shared<phi::DenseTensor>(
phi::make_intrusive<paddle::experimental::SharedStorage>(place),
phi::DenseTensorMeta(paddle::framework::TransToPhiDataType(dtype),
ddims));
}
self->tensor.set_impl(dense_tensor);
} else if (var_type == paddle::framework::proto::VarType::SELECTED_ROWS) {
std::shared_ptr<phi::SelectedRows> tensor =
......
......@@ -125,6 +125,7 @@ class PyTensorVoidHook : public egr::TensorVoidHook {
extern void InitTensorWithNumpyValue(TensorObject* self,
const pybind11::object& array,
const paddle::platform::Place& place,
bool zero_copy);
extern PyTypeObject* p_tensor_type;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册