Learn R Programming

ggmlR (version 0.8.4)

ggml_graph_expand: Add Another Root to an Existing Computation Graph

Description

ggml_build_forward_expand() always creates a fresh graph, so it can only express a single root. A model with several independent output branches needs every output expanded into the same graph: an output that is unreachable from the first root never enters the graph, the scheduler never assigns it a buffer, and reading it back fails. This appends tensor and its ancestors to a graph that already exists.

Usage

ggml_graph_expand(graph, tensor)

Value

NULL, invisibly. graph is modified in place.

Arguments

graph

Graph object returned by ggml_build_forward_expand().

tensor

Additional output tensor to expand into graph.

Examples

Run this code
# \donttest{
ctx <- ggml_init(16 * 1024 * 1024)
a <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 4)
b <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 4)
ggml_set_f32(a, 1:4)
ggml_set_f32(b, 5:8)
# Two independent outputs -- neither reachable from the other.
o1 <- ggml_add(ctx, a, a)
o2 <- ggml_add(ctx, b, b)
graph <- ggml_build_forward_expand(ctx, o1)
ggml_graph_expand(graph, o2)
ggml_graph_compute(ctx, graph)
ggml_free(ctx)
# }

Run the code above in your browser using DataLab