MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_graph_dump_dot

Function ggml_graph_dump_dot

ggml.c:18076–18196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18074}
18075
18076void ggml_graph_dump_dot(const struct ggml_cgraph * gb, const struct ggml_cgraph * gf, const char * filename) {
18077 char color[16];
18078
18079 FILE * fp = fopen(filename, "w");
18080 GGML_ASSERT(fp);
18081
18082 fprintf(fp, "digraph G {\n");
18083 fprintf(fp, " newrank = true;\n");
18084 fprintf(fp, " rankdir = LR;\n");
18085
18086 for (int i = 0; i < gb->n_nodes; i++) {
18087 struct ggml_tensor * node = gb->nodes[i];
18088
18089 if (ggml_graph_get_parent(gb, node) != NULL) {
18090 continue;
18091 }
18092
18093 if (node->is_param) {
18094 snprintf(color, sizeof(color), "yellow");
18095 } else if (node->grad) {
18096 if (ggml_graph_find(gf, node)) {
18097 snprintf(color, sizeof(color), "green");
18098 } else {
18099 snprintf(color, sizeof(color), "lightblue");
18100 }
18101 } else {
18102 snprintf(color, sizeof(color), "white");
18103 }
18104
18105 fprintf(fp, " \"%p\" [ "
18106 "style = filled; fillcolor = %s; shape = record; "
18107 "label=\"",
18108 (void *) node, color);
18109
18110 if (strlen(node->name) > 0) {
18111 fprintf(fp, "%s (%s)|", node->name, ggml_type_name(node->type));
18112 } else {
18113 fprintf(fp, "(%s)|", ggml_type_name(node->type));
18114 }
18115
18116 if (node->n_dims == 2) {
18117 fprintf(fp, "%d [%" PRId64 ", %" PRId64 "] | <x>%s", i, node->ne[0], node->ne[1], ggml_op_symbol(node->op));
18118 } else {
18119 fprintf(fp, "%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] | <x>%s", i, node->ne[0], node->ne[1], node->ne[2], ggml_op_symbol(node->op));
18120 }
18121
18122 if (node->grad) {
18123 fprintf(fp, " | <g>%s\"; ]\n", ggml_op_symbol(node->grad->op));
18124 } else {
18125 fprintf(fp, "\"; ]\n");
18126 }
18127 }
18128
18129 for (int i = 0; i < gb->n_leafs; i++) {
18130 struct ggml_tensor * node = gb->leafs[i];
18131
18132 snprintf(color, sizeof(color), "pink");
18133

Callers 2

ggml_opt_resume_gFunction · 0.70
sched_compute_splitsFunction · 0.70

Calls 10

fprintfFunction · 0.85
ggml_graph_get_parentFunction · 0.70
ggml_graph_findFunction · 0.70
ggml_type_nameFunction · 0.70
ggml_op_symbolFunction · 0.70
ggml_nelementsFunction · 0.70
ggml_get_i32_1dFunction · 0.70
ggml_get_f32_1dFunction · 0.70

Tested by

no test coverage detected