@@ -74,6 +74,12 @@ static DDim GetDims(const Scope& scope, const std::string& name,
74
74
}
75
75
}
76
76
77
+ static bool VarInited (const Scope& scope, const std::string& name) {
78
+ Variable* var = scope.FindVar (name);
79
+ if (var == nullptr ) return false ;
80
+ return var->IsInitialized ();
81
+ }
82
+
77
83
static std::string GetDtype (const Scope& scope, const std::string& name) {
78
84
Variable* var = scope.FindVar (name);
79
85
if (var == nullptr ) {
@@ -87,8 +93,12 @@ static std::string GetDtype(const Scope& scope, const std::string& name) {
87
93
}
88
94
return DataTypeToString (ToDataType (tensor.type ()));
89
95
} else if (var->IsType <SelectedRows>()) {
90
- return DataTypeToString (
91
- ToDataType (var->Get <SelectedRows>().value ().type ()));
96
+ auto tensor = var->Get <SelectedRows>().value ();
97
+ if (UNLIKELY (!tensor.IsInitialized ())) {
98
+ return " uninited" ;
99
+ } else {
100
+ return DataTypeToString (ToDataType (tensor.type ()));
101
+ }
92
102
} else {
93
103
return " " ;
94
104
}
@@ -197,16 +207,21 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const {
197
207
auto & input = *it;
198
208
ss << input.first << " [" ;
199
209
for (size_t i = 0 ; i < input.second .size (); ++i) {
200
- ss << input.second [i];
210
+ auto var_name = input.second [i];
211
+ ss << var_name;
201
212
if (scope) {
202
- int row_size = GetRowSize (*scope, input.second [i]);
203
- if (row_size >= 0 ) {
204
- ss << " [row_size=" << row_size << " ]" ;
213
+ if (!VarInited (*scope, var_name)) {
214
+ ss << " [uninited]" ;
215
+ } else {
216
+ int row_size = GetRowSize (*scope, var_name);
217
+ if (row_size >= 0 ) {
218
+ ss << " [row_size=" << row_size << " ]" ;
219
+ }
220
+ std::string dtype = GetDtype (*scope, var_name);
221
+ ss << " :" << dtype;
222
+ ss << " [" << GetDims (*scope, var_name, true ) << " ]" ;
223
+ ss << " (" << GetLoD (*scope, var_name) << " )" ;
205
224
}
206
- std::string dtype = GetDtype (*scope, input.second [i]);
207
- ss << " :" << dtype;
208
- ss << " [" << GetDims (*scope, input.second [i], true ) << " ]" ;
209
- ss << " (" << GetLoD (*scope, input.second [i]) << " )" ;
210
225
}
211
226
if (i != input.second .size () - 1 ) {
212
227
ss << " , " ;
@@ -223,14 +238,19 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const {
223
238
auto & output = *it;
224
239
ss << output.first << " [" ;
225
240
for (size_t i = 0 ; i < output.second .size (); ++i) {
226
- ss << output.second [i];
241
+ auto var_name = output.second [i];
242
+ ss << var_name;
227
243
if (scope) {
228
- int row_size = GetRowSize (*scope, output.second [i]);
229
- if (row_size >= 0 ) {
230
- ss << " [row_size=" << row_size << " ]" ;
244
+ if (!VarInited (*scope, var_name)) {
245
+ ss << " [uninited]" ;
246
+ } else {
247
+ int row_size = GetRowSize (*scope, output.second [i]);
248
+ if (row_size >= 0 ) {
249
+ ss << " [row_size=" << row_size << " ]" ;
250
+ }
251
+ ss << " [" << GetDims (*scope, var_name, true ) << " ]" ;
252
+ ss << " (" << GetLoD (*scope, var_name) << " )" ;
231
253
}
232
- ss << " [" << GetDims (*scope, output.second [i], true ) << " ]" ;
233
- ss << " (" << GetLoD (*scope, output.second [i]) << " )" ;
234
254
}
235
255
if (i != output.second .size () - 1 ) {
236
256
ss << " , " ;
0 commit comments