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

[Eager]Fix tensor.name is empty behavior (#42587)

* [Eager]Fix tensor.name is empty behavior

* fix unittest
上级 c22c2c58
...@@ -37,6 +37,13 @@ extern PyTypeObject* p_tensor_type; ...@@ -37,6 +37,13 @@ extern PyTypeObject* p_tensor_type;
PyObject* tensor_properties_get_name(TensorObject* self, void* closure) { PyObject* tensor_properties_get_name(TensorObject* self, void* closure) {
EAGER_TRY EAGER_TRY
// NOTE(dev): [why not use egr::Controller::Instance::GernerateUniqueName()?]
// Beacause Controller must holder a tracer, but 'tensor.name' maybe called
// everywhere such as static mode in @to_static, which means tracer is None.
static egr::UniqueNameGenerator name_generator;
if (self->tensor.name().empty()) {
self->tensor.set_name(name_generator.Generate());
}
return ToPyObject(self->tensor.name()); return ToPyObject(self->tensor.name());
EAGER_CATCH_AND_THROW_RETURN_NULL EAGER_CATCH_AND_THROW_RETURN_NULL
} }
......
...@@ -16,8 +16,6 @@ import paddle ...@@ -16,8 +16,6 @@ import paddle
from paddle.nn import Layer from paddle.nn import Layer
import numpy as np import numpy as np
import unittest import unittest
from paddle.fluid.framework import _enable_legacy_dygraph
_enable_legacy_dygraph()
class Net(Layer): class Net(Layer):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册