| 38 | using tensorflow::GraphDef; |
| 39 | |
| 40 | void LogDumpGraphDef(int log_level, const string& message, |
| 41 | const GraphDef& tf_graph) { |
| 42 | if (!VLOG_IS_ON(log_level)) { |
| 43 | return; |
| 44 | } |
| 45 | std::set<string> ops; |
| 46 | for (const auto& node : tf_graph.node()) { |
| 47 | ops.insert(node.op()); |
| 48 | } |
| 49 | string dump; |
| 50 | toco::port::AppendF(&dump, R"MSG( |
| 51 | BEGIN DUMP OF TENSORFLOW GRAPHDEF (%s) |
| 52 | There are %d nodes. |
| 53 | There are %zu different op types: |
| 54 | )MSG", |
| 55 | message, tf_graph.node_size(), ops.size()); |
| 56 | for (const auto& op : ops) { |
| 57 | toco::port::AppendF(&dump, " %s\n", op); |
| 58 | } |
| 59 | dump.append(R"MSG( |
| 60 | PROTO DUMP |
| 61 | )MSG"); |
| 62 | for (const auto& node : tf_graph.node()) { |
| 63 | toco::port::AppendF(&dump, R"MSG( |
| 64 | BEGIN NODE: name = %s |
| 65 | op = %s |
| 66 | inputs = [ |
| 67 | )MSG", |
| 68 | node.name(), node.op()); |
| 69 | for (const auto& input : node.input()) { |
| 70 | toco::port::AppendF(&dump, " %s\n", input); |
| 71 | } |
| 72 | dump.append(" ]\n"); |
| 73 | for (const auto& attr : node.attr()) { |
| 74 | toco::port::AppendF(&dump, " ATTR: name = %s\n", attr.first); |
| 75 | if (attr.second.value_case() == AttrValue::kFunc) { |
| 76 | dump.append(" func\n"); |
| 77 | } else if (attr.second.value_case() == AttrValue::kPlaceholder) { |
| 78 | toco::port::AppendF(&dump, " placeholder: %s\n", |
| 79 | attr.second.placeholder()); |
| 80 | } else if (attr.second.value_case() == AttrValue::kS) { |
| 81 | dump.append(" string:\n"); |
| 82 | dump.append(R"MSG( |
| 83 | BEGIN EMBEDDED STRING |
| 84 | )MSG"); |
| 85 | const auto& lines = absl::StrSplit(attr.second.s(), '\n'); |
| 86 | for (const auto& line : lines) { |
| 87 | toco::port::AppendF(&dump, " %s\n", line); |
| 88 | } |
| 89 | dump.append(R"MSG( |
| 90 | END EMBEDDED STRING |
| 91 | )MSG"); |
| 92 | } else if (attr.second.value_case() == AttrValue::kI) { |
| 93 | toco::port::AppendF(&dump, " int: %lld\n", attr.second.i()); |
| 94 | } else if (attr.second.value_case() == AttrValue::kF) { |
| 95 | toco::port::AppendF(&dump, " float: %g\n", attr.second.f()); |
| 96 | } else if (attr.second.value_case() == AttrValue::kB) { |
| 97 | toco::port::AppendF(&dump, " bool: %s\n", |