| ggml_build_backward_expand | R Documentation |
Extends graph in place with the nodes that compute gradients of its
output with respect to every tensor marked by ggml_set_param.
After computing the graph, read a gradient with
ggml_graph_get_grad.
ggml_build_backward_expand(ctx, graph)
ctx |
GGML context |
graph |
Graph from |
The graph must come from ggml_build_forward_expand_grads:
ggml_build_forward_expand produces one without gradient
storage, and that is rejected rather than allowed to abort inside ggml.
NULL, invisibly; graph is modified in place
Every step is required; skipping one gives either an error or – for the last – gradients that are silently all zero.
ggml_set_param on each tensor to differentiate
build the forward ops
ggml_set_loss on the output
ggml_build_forward_expand_grads
ggml_build_backward_expand()
ggml_graph_reset – seeds d(loss)/d(loss) = 1
ggml_graph_compute
ggml_graph_get_grad to read a gradient
Gradients flow only through operations that implement a backward pass. Most
do, but not all – ggml_clamp is a notable exception, and among
the state-space ops only ggml_ssm_conv is differentiable.
ggml_build_forward_expand_grads,
ggml_graph_get_grad, ggml_set_param
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.