From 83ee1cd741655f594e3e548d08f92426217ad132 Mon Sep 17 00:00:00 2001 From: xaedes Date: Sat, 6 May 2023 13:05:29 +0200 Subject: [PATCH] fix bug when using ggml_opt to optimize params in one context and use a renewable context for eval and opt when not keeping gradients of model parameters they are overwritten by tensors created by opt, which may be invalid after opt context is renewed. so we need to keep the original gradients and make dups for opt --- ggml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggml.c b/ggml.c index d67e49b95..ce7fda0e7 100644 --- a/ggml.c +++ b/ggml.c @@ -15131,7 +15131,7 @@ enum ggml_opt_result ggml_opt( // build forward + backward compute graphs struct ggml_cgraph gf = ggml_build_forward (f); - struct ggml_cgraph gb = ggml_build_backward(ctx, &gf, false); + struct ggml_cgraph gb = ggml_build_backward(ctx, &gf, true); switch (params.type) { case GGML_OPT_ADAM: