| 80 | |
| 81 | template <typename VarType> |
| 82 | static std::string DebugString( |
| 83 | const std::string& name, |
| 84 | const std::vector<std::shared_ptr<VarType>>& vars) { |
| 85 | std::stringstream ss; |
| 86 | ss << name << "{"; |
| 87 | |
| 88 | for (size_t i = 0; i < vars.size(); ++i) { |
| 89 | if (i > 0) ss << ", "; |
| 90 | |
| 91 | if (vars[i] == nullptr) { |
| 92 | ss << "NULL"; |
| 93 | continue; |
| 94 | } |
| 95 | ss << GetNameFromVar(vars[i]) << "["; |
| 96 | const framework::Variable& var = vars[i]->Var(); |
| 97 | if (!var.IsInitialized()) { |
| 98 | ss << "NOT_INITED_VAR"; |
| 99 | } else if (var.IsType<DenseTensor>()) { |
| 100 | auto& tensor = var.Get<DenseTensor>(); |
| 101 | ss << "DenseTensor<"; |
| 102 | if (tensor.IsInitialized()) { |
| 103 | ss << framework::DataTypeToString( |
| 104 | framework::TransToProtoVarType(tensor.dtype())) |
| 105 | << ", "; |
| 106 | ss << tensor.place() << ", "; |
| 107 | ss << "(" << tensor.dims() << ")"; |
| 108 | } else { |
| 109 | ss << "NOT_INITED"; |
| 110 | } |
| 111 | ss << ">"; |
| 112 | } else if (var.IsType<phi::SelectedRows>()) { |
| 113 | ss << "SelectedRows<"; |
| 114 | auto& selected_rows = var.Get<phi::SelectedRows>(); |
| 115 | auto& tensor = selected_rows.value(); |
| 116 | auto& rows = selected_rows.rows(); |
| 117 | if (tensor.IsInitialized()) { |
| 118 | ss << framework::DataTypeToString( |
| 119 | framework::TransToProtoVarType(tensor.dtype())) |
| 120 | << ", "; |
| 121 | ss << tensor.place() << ", "; |
| 122 | ss << "height(" << selected_rows.height() << "), rows("; |
| 123 | std::for_each(rows.cbegin(), rows.cend(), [&ss](const int64_t r) { |
| 124 | ss << r << " "; |
| 125 | }); |
| 126 | ss << "), dims(" << tensor.dims() << ")"; |
| 127 | } else { |
| 128 | ss << "NOT_INITED"; |
| 129 | } |
| 130 | ss << ">"; |
| 131 | } else { |
| 132 | ss << "UNRESOLVED_TYPE"; |
| 133 | } |
| 134 | ss << "]"; |
| 135 | } |
| 136 | |
| 137 | ss << "}"; |
| 138 | return ss.str(); |
| 139 | } |