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

[AutoParallel] Disttensor print #59068

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 9 additions & 4 deletions paddle/fluid/pybind/eager_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,15 @@ static PyObject* tensor_method__is_initialized(TensorObject* self,
static PyObject* tensor_method__is_dense_tensor_hold_allocation(
TensorObject* self, PyObject* args, PyObject* kwargs) {
EAGER_TRY
auto dense_tensor =
std::dynamic_pointer_cast<phi::DenseTensor>(self->tensor.impl());
if (dense_tensor) {
return ToPyObject(dense_tensor->IsInitialized());
if (self->tensor.is_dense_tensor()) {
return ToPyObject(
std::dynamic_pointer_cast<phi::DenseTensor>(self->tensor.impl())
->IsInitialized());
} else if (self->tensor.is_dist_tensor()) {
return ToPyObject(
static_cast<phi::distributed::DistTensor*>(self->tensor.impl().get())
->value()
.IsInitialized());
} else {
return ToPyObject(false);
}
Expand Down
35 changes: 24 additions & 11 deletions python/paddle/tensor/to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,30 @@ def dist_tensor_to_string(tensor, prefix='Tensor'):
if tensor.dtype == core.VarDesc.VarType.BF16:
dtype = 'bfloat16'

_template = "{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient}, dist_attr={dist_attr},\n{indent}{data})"
return _template.format(
prefix=prefix,
shape=tensor.shape,
dtype=dtype,
place=tensor._place_str,
stop_gradient=tensor.stop_gradient,
dist_attr=tensor.dist_attr,
indent=' ' * indent,
data=None,
)
if not tensor._is_dense_tensor_hold_allocation():
_template = "{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient}, dist_attr={dist_attr}, GlobalDenseTensor Not initialized)"
return _template.format(
prefix=prefix,
shape=tensor.shape,
dtype=dtype,
place=tensor._place_str,
stop_gradient=tensor.stop_gradient,
dist_attr=tensor.dist_attr,
)
else:
indent = len(prefix) + 1
data = _format_dense_tensor(tensor, indent)
_template = "{prefix}(shape={shape}, dtype={dtype}, place={place}, stop_gradient={stop_gradient}, dist_attr={dist_attr}, GlobalDenseTensor=\n{indent}{data})"
return _template.format(
prefix=prefix,
shape=tensor.shape,
dtype=dtype,
place=tensor._place_str,
stop_gradient=tensor.stop_gradient,
dist_attr=tensor.dist_attr,
indent=' ' * indent,
data=data,
)


def tensor_to_string(tensor, prefix='Tensor'):
Expand Down