未验证 提交 d0b71349 编写于 作者: Q Qiao Longfei 提交者: GitHub

enhance DebugStringEx (#12949)

上级 eca4563e
...@@ -74,6 +74,12 @@ static DDim GetDims(const Scope& scope, const std::string& name, ...@@ -74,6 +74,12 @@ static DDim GetDims(const Scope& scope, const std::string& name,
} }
} }
static bool VarInited(const Scope& scope, const std::string& name) {
Variable* var = scope.FindVar(name);
if (var == nullptr) return false;
return var->IsInitialized();
}
static std::string GetDtype(const Scope& scope, const std::string& name) { static std::string GetDtype(const Scope& scope, const std::string& name) {
Variable* var = scope.FindVar(name); Variable* var = scope.FindVar(name);
if (var == nullptr) { if (var == nullptr) {
...@@ -87,8 +93,12 @@ static std::string GetDtype(const Scope& scope, const std::string& name) { ...@@ -87,8 +93,12 @@ static std::string GetDtype(const Scope& scope, const std::string& name) {
} }
return DataTypeToString(ToDataType(tensor.type())); return DataTypeToString(ToDataType(tensor.type()));
} else if (var->IsType<SelectedRows>()) { } else if (var->IsType<SelectedRows>()) {
return DataTypeToString( auto tensor = var->Get<SelectedRows>().value();
ToDataType(var->Get<SelectedRows>().value().type())); if (UNLIKELY(!tensor.IsInitialized())) {
return "uninited";
} else {
return DataTypeToString(ToDataType(tensor.type()));
}
} else { } else {
return ""; return "";
} }
...@@ -197,16 +207,21 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const { ...@@ -197,16 +207,21 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const {
auto& input = *it; auto& input = *it;
ss << input.first << "["; ss << input.first << "[";
for (size_t i = 0; i < input.second.size(); ++i) { for (size_t i = 0; i < input.second.size(); ++i) {
ss << input.second[i]; auto var_name = input.second[i];
ss << var_name;
if (scope) { if (scope) {
int row_size = GetRowSize(*scope, input.second[i]); if (!VarInited(*scope, var_name)) {
ss << "[uninited]";
} else {
int row_size = GetRowSize(*scope, var_name);
if (row_size >= 0) { if (row_size >= 0) {
ss << "[row_size=" << row_size << "]"; ss << "[row_size=" << row_size << "]";
} }
std::string dtype = GetDtype(*scope, input.second[i]); std::string dtype = GetDtype(*scope, var_name);
ss << ":" << dtype; ss << ":" << dtype;
ss << "[" << GetDims(*scope, input.second[i], true) << "]"; ss << "[" << GetDims(*scope, var_name, true) << "]";
ss << "(" << GetLoD(*scope, input.second[i]) << ")"; ss << "(" << GetLoD(*scope, var_name) << ")";
}
} }
if (i != input.second.size() - 1) { if (i != input.second.size() - 1) {
ss << ", "; ss << ", ";
...@@ -223,14 +238,19 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const { ...@@ -223,14 +238,19 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const {
auto& output = *it; auto& output = *it;
ss << output.first << "["; ss << output.first << "[";
for (size_t i = 0; i < output.second.size(); ++i) { for (size_t i = 0; i < output.second.size(); ++i) {
ss << output.second[i]; auto var_name = output.second[i];
ss << var_name;
if (scope) { if (scope) {
if (!VarInited(*scope, var_name)) {
ss << "[uninited]";
} else {
int row_size = GetRowSize(*scope, output.second[i]); int row_size = GetRowSize(*scope, output.second[i]);
if (row_size >= 0) { if (row_size >= 0) {
ss << "[row_size=" << row_size << "]"; ss << "[row_size=" << row_size << "]";
} }
ss << "[" << GetDims(*scope, output.second[i], true) << "]"; ss << "[" << GetDims(*scope, var_name, true) << "]";
ss << "(" << GetLoD(*scope, output.second[i]) << ")"; ss << "(" << GetLoD(*scope, var_name) << ")";
}
} }
if (i != output.second.size() - 1) { if (i != output.second.size() - 1) {
ss << ", "; ss << ", ";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册