Skip to content

Commit 4d84243

Browse files
committed
fix: use ggml_graph_cpy to keep hash-set/use-counts in Phase 2 capture (#huanglawsded)
1 parent 8b7df8a commit 4d84243

2 files changed

Lines changed: 3 additions & 13 deletions

File tree

src/llama-context.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,12 +1884,6 @@ llm_graph_result * llama_context::process_ubatch(const llama_ubatch & ubatch, ll
18841884
phase2_gf = model.build_graph(gparams, nullptr, nullptr, &moe_weight_cache);
18851885
if (!phase2_gf) { ret = GGML_STATUS_FAILED; return nullptr; }
18861886

1887-
// Inputs must be written and CPU-assigned before capture.
1888-
// alloc_graph needs the final shapes and host-buffer inputs,
1889-
// and the persistent graph will share these tensor objects.
1890-
force_idxs_to_cpu_p2();
1891-
res->set_inputs(&ubatch);
1892-
18931887
// Persist the Phase 2 graph structure across res->reset().
18941888
// Tensor objects remain shared with the freshly built graph, so
18951889
// framework-owned backend metadata is preserved exactly.

src/moe-hijacker.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,12 @@ void capture_phase2_graph(phase2_graph_cache & cache, ggml_cgraph * src_gf) {
161161
return;
162162
}
163163

164+
// ggml_graph_cpy copies nodes/leafs AND the visited_hash_set + use_counts,
165+
// which the scheduler's allocator and compute rely on.
166+
ggml_graph_cpy(src_gf, cache.persistent_gf);
164167
cache.persistent_gf->order = src_gf->order;
165168
cache.persistent_gf->uid = src_gf->uid;
166169

167-
for (int i = 0; i < n_leafs; i++) {
168-
cache.persistent_gf->leafs[cache.persistent_gf->n_leafs++] = ggml_graph_leaf(src_gf, i);
169-
}
170-
for (int i = 0; i < n_nodes; i++) {
171-
cache.persistent_gf->nodes[cache.persistent_gf->n_nodes++] = ggml_graph_node(src_gf, i);
172-
}
173-
174170
cache.valid = true;
175171
fprintf(stderr, "capture_phase2_graph: %d nodes + %d leafs (shallow, size=%d)\n", n_nodes, n_leafs, gsize);
176172
}

0 commit comments

Comments
 (0)