MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / ggml_graph_dump_dot

Function ggml_graph_dump_dot

subprojects/llama.cpp/ggml/src/ggml.c:7347–7472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7345}
7346
7347void ggml_graph_dump_dot(const struct ggml_cgraph * gb, const struct ggml_cgraph * cgraph, const char * filename) {
7348 char color[16];
7349
7350 FILE * fp = ggml_fopen(filename, "w");
7351 GGML_ASSERT(fp);
7352
7353 fprintf(fp, "digraph G {\n");
7354 fprintf(fp, " newrank = true;\n");
7355 fprintf(fp, " rankdir = TB;\n");
7356
7357 for (int i = 0; i < gb->n_nodes; i++) {
7358 struct ggml_tensor * node = gb->nodes[i];
7359 struct ggml_tensor * grad = ggml_graph_get_grad(gb, node);
7360
7361 if (ggml_graph_get_parent(gb, node) != NULL) {
7362 continue;
7363 }
7364
7365 if (node->flags & GGML_TENSOR_FLAG_PARAM) {
7366 snprintf(color, sizeof(color), "yellow");
7367 } else if (grad) {
7368 if (ggml_graph_find(cgraph, node)) {
7369 snprintf(color, sizeof(color), "green");
7370 } else {
7371 snprintf(color, sizeof(color), "lightblue");
7372 }
7373 } else {
7374 snprintf(color, sizeof(color), "white");
7375 }
7376
7377 fprintf(fp, " \"%p\" [ "
7378 "style = filled; fillcolor = %s; shape = record; "
7379 "label=\"",
7380 (void *) node, color);
7381
7382 if (strlen(node->name) > 0) {
7383 fprintf(fp, "%s (%s)|", node->name, ggml_type_name(node->type));
7384 } else {
7385 fprintf(fp, "(%s)|", ggml_type_name(node->type));
7386 }
7387
7388 if (ggml_is_matrix(node)) {
7389 fprintf(fp, "%d [%" PRId64 ", %" PRId64 "] | <x>%s", i, node->ne[0], node->ne[1], ggml_op_symbol(node->op));
7390 } else {
7391 fprintf(fp, "%d [%" PRId64 ", %" PRId64 ", %" PRId64 "] | <x>%s", i, node->ne[0], node->ne[1], node->ne[2], ggml_op_symbol(node->op));
7392 }
7393
7394 if (grad) {
7395 fprintf(fp, " | <g>%s\"; ]\n", ggml_op_symbol(grad->op));
7396 } else {
7397 fprintf(fp, "\"; ]\n");
7398 }
7399 }
7400
7401 for (int i = 0; i < gb->n_leafs; i++) {
7402 struct ggml_tensor * node = gb->leafs[i];
7403
7404 snprintf(color, sizeof(color), "pink");

Callers

nothing calls this directly

Calls 10

ggml_fopenFunction · 0.85
ggml_graph_get_gradFunction · 0.85
ggml_graph_get_parentFunction · 0.85
ggml_graph_findFunction · 0.85
ggml_type_nameFunction · 0.85
ggml_is_matrixFunction · 0.85
ggml_op_symbolFunction · 0.85
ggml_nelementsFunction · 0.85

Tested by

no test coverage detected