Skip to content

meta: recreate all subgraphs when the arena is reallocated - #30453

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
Xanewok:fix/meta-subgraph-realloc
Oct 13, 2026
Merged

ggerganov merged 2 commits into
ggml-org:masterfrom
Xanewok:fix/meta-subgraph-realloc

Conversation

@Xanewok

@Xanewok Xanewok commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Overview

While I looked how to speed up running 2x5060 Ti via -sm tensor, I hit a segfault while trying some local experiment for Qwen3.8 and discovered that we:

  1. do not fully recreate later subgraphs when max_nnodes_raised triggers or
  2. recreate all slots, but too small, if cgraph->n_nodes < max_nnodes (with added graph of more subgraphs but fewer nodes)

And so a later graph within both max values (max_subgraphs, max_nnodes) skips reallocation and uses freed subgraph or overflows a small one.

Added test to test-alloc.cpp but can separate a meta backend-specific one if desired?

Requirements

  • I have read and agree with the contributing guidelines: yes
  • AI usage disclosure: YES, the AI loop helped pinpoint the offending lines and wrote the fix and the test case, but verified it manually

@Xanewok
Xanewok force-pushed the fix/meta-subgraph-realloc branch from 9bb2335 to fddebd3 Compare October 13, 2026 13:40
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning labels Oct 13, 2026

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I presumably made a mistake when refactoring and this is the correct fix. My opinion is that the new expected value of the new test case is too low in terms of catching such mistakes in the future so it should be stripped from the PR. (Unless @ggerganov disagrees?)

@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 13, 2026
@Xanewok

Xanewok commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

(...) it should be stripped from the PR

Yeah, that's a fair point - I've removed them in 44035c4.

Thank you guys for such a quick turnaround!

@ggerganov

Copy link
Copy Markdown
Member

@Xanewok What is the impact on normal uses? Does this patch prevent crashes in some cases?

@Xanewok

Xanewok commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@ggerganov thankfully I didn't hit this myself in stock/master setup, no; only in some local experiments so far

@ggerganov
ggerganov merged commit ecdd29e into ggml-org:master Oct 13, 2026
27 of 33 checks passed
@Xanewok
Xanewok deleted the fix/meta-subgraph-realloc branch October 13, 2026 15:01
@BrewTestBot BrewTestBot mentioned this pull request Oct 15, 2026
1 task done
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
…30453)

* meta: recreate all subgraphs when the arena is reallocated

* chore: revert added test cases
MuFengMuXue pushed a commit to MuFengMuXue/llama.cpp-gfx906 that referenced this pull request Oct 25, 2026
Brings the fork from upstream b11553 to the v0.7.0 release (116 upstream commits). Every fork feature is kept; where both sides changed the same code the two changes are combined, not chosen between.

Textual conflicts (10 hunks, 8 files):
- common/speculative.cpp: upstream's LiliCorr setup (ggml-org#30506) placed ahead of the fork's fallback to the target vocab's mask token.
- ggml/src/ggml-backend-meta.cpp: upstream's subgraph recreation (ggml-org#30453) is the fork's own fix; the fork's comment is kept.
- ggml/src/ggml-cuda/common.cuh: the fork's context fields kept, with upstream's `= {}` initializers for the stream and cuBLAS arrays.
- ggml/src/ggml-cuda/gated_delta_net.cu: includes both the fork's chunk kernel header and upstream's MMA header.
- src/llama-context.cpp: both call sites use upstream's sched_new() member (it adds the graph realloc callback, ggml-org#30329); the fork's sync-non-graph-inputs policy moves into it.
- src/llama-ext.h: the fork's MTP prefill and pre-norm accumulation declarations kept, upstream's wording for the decision head comment.
- src/llama-model.cpp: the fork's skip for contexts with nothing to allocate kept without the per-file buffer map that upstream removed (ggml-org#30405); load_tensors() ends with upstream's load_tensors_hadamard() and then the fork's PLE prefault.
- tools/server/server-context.cpp: release() resets the speculative state as the fork does and also drops the prompt of stateless tasks as upstream does.

Merged without a textual conflict but changed here:
- common/speculative.cpp: LiliCorr stores the projected rows of each inject in the eager path only. The fork's deferred prompt encode replays the injects in flush_pending_upto() without that step, so a LiliCorr drafter stays on the eager path.
- ggml/src/ggml-cuda/gated_delta_net.cu: upstream's MMA chunked kernel (ggml-org#29353) writes only the final state. When the fork's snapshot ring keeps more than one state (K > 1) the call goes to the fork's kernels. On HIP the MMA path runs on RDNA3.5 only, so gfx906 does not take it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants