未验证 提交 23d1b3e8 编写于 作者: J Jiabin Yang 提交者: GitHub

[Eager] fix memory issue for eager (#42086)

* fix memory issue for eager

* fix bug
上级 1b8fd85d
...@@ -55,6 +55,20 @@ class TensorWrapper { ...@@ -55,6 +55,20 @@ class TensorWrapper {
if (full_reserved_) { if (full_reserved_) {
VLOG(6) << "Fully reserved tensor: " << tensor.name(); VLOG(6) << "Fully reserved tensor: " << tensor.name();
intermidiate_tensor_ = tensor; intermidiate_tensor_ = tensor;
if (no_need_buffer_) {
if (phi::DenseTensor::classof(tensor.impl().get())) {
// Only Copy Meta
phi::DenseTensor* dense_tensor =
static_cast<phi::DenseTensor*>(tensor.impl().get());
auto tw_dense_tensor =
std::make_shared<phi::DenseTensor>(*dense_tensor);
tw_dense_tensor->clear();
intermidiate_tensor_.set_impl(tw_dense_tensor);
} else {
PADDLE_THROW(paddle::platform::errors::Fatal(
"Unrecognized tensor type for no_need_buffer feature"));
}
}
return; return;
} }
......
...@@ -341,7 +341,11 @@ bool Tensor::is_initialized() const { ...@@ -341,7 +341,11 @@ bool Tensor::is_initialized() const {
return defined() && impl_->initialized(); return defined() && impl_->initialized();
} }
void Tensor::reset() { impl_.reset(); } void Tensor::reset() {
impl_.reset();
autograd_meta_.reset();
name_ = "";
}
/* Part 6: Operator overloading */ /* Part 6: Operator overloading */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册