From e8e33629c1606e5e34e39fc300744549261515af Mon Sep 17 00:00:00 2001 From: Pascal Date: Tue, 9 Jun 2026 19:41:39 +0200 Subject: [PATCH] graph: reset scheduler before remaining shared-sched graph allocs The talker path already resets the scheduler before allocating its graph (thanks Andi Marafioti, #4 of qwentts.cpp). The same shared scheduler is also allocated elsewhere without a reset first. The scheduler keeps split and tensor->backend assignments from the previous graph. Allocating a different graph topology on a dirty scheduler can reuse stale assignments, which is exactly the CPU divergence Andi fixed for the talker. Resetting before alloc_graph is the canonical GGML contract and is idempotent when the scheduler is already clean. Suggested-by: Andres Marafioti --- src/code-predictor-forward.h | 1 + src/prompt-builder.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/code-predictor-forward.h b/src/code-predictor-forward.h index 8f39822..4265f63 100644 --- a/src/code-predictor-forward.h +++ b/src/code-predictor-forward.h @@ -240,6 +240,7 @@ static bool code_predictor_run(const CodePredictorWeights * cw, ggml_set_output(logits); ggml_build_forward_expand(gf, logits); + ggml_backend_sched_reset(sched); if (!ggml_backend_sched_alloc_graph(sched, gf)) { fprintf(stderr, "[CodePredictor] FATAL: graph allocation failed\n"); ggml_backend_sched_reset(sched); diff --git a/src/prompt-builder.h b/src/prompt-builder.h index 4feee96..1a8409e 100644 --- a/src/prompt-builder.h +++ b/src/prompt-builder.h @@ -161,6 +161,7 @@ static bool project_text_ids_backend(PipelineTTS * pt, const int32_t * ids, int struct ggml_cgraph * graph = ggml_new_graph_custom(gctx, max_nodes, false); ggml_build_forward_expand(graph, out); + ggml_backend_sched_reset(pt->sched); if (!ggml_backend_sched_alloc_graph(pt->sched, graph)) { ggml_backend_sched_reset(pt->sched); ggml_free(gctx); @@ -244,6 +245,7 @@ static void project_ref_codes_backend(PipelineTTS * pt, const int32_t * ref_code struct ggml_cgraph * graph = ggml_new_graph_custom(gctx, max_nodes, false); ggml_build_forward_expand(graph, sum); + ggml_backend_sched_reset(pt->sched); if (!ggml_backend_sched_alloc_graph(pt->sched, graph)) { ggml_backend_sched_reset(pt->sched); ggml_free(gctx);