ggml-alloc : share meta compute buffers through a borrower alias - #88
Open
Piggidragon wants to merge 2 commits into
Open
Piggidragon wants to merge 2 commits into
Piggidragon wants to merge 2 commits into
Conversation
Piggidragon
marked this pull request as ready for review
September 13, 2026 20:51
A meta buffer maps its tensors to the per-device tensors for one graph at a time and rebuilds that map when a new graph is computed. Under --split-mode tensor the target and MTP contexts shared one meta compute buffer, so the draft graph dropped the target mappings and the next target decode hit GGML_ASSERT(tensor) in ggml_backend_tensor_set. The owner no longer creates a shared entry for a meta buffer type, so each context keeps its own. Other buffer types are still shared. Assisted-by: Claude Opus 5
Keeping meta buffers private fixed the crash but gave up the shared workspace under --split-mode tensor. The memory can be shared, only the tensor map inside a meta buffer can not. ggml_backend_meta_buffer_alias creates a second meta buffer over the same simple buffers with its own tensor map. The shared entry keeps one alias for the borrower and rebuilds it when the entry is resized. Assisted-by: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016qzvRnpuN7dvnXNzK1F8dV
Piggidragon
force-pushed
the
mgpu/phase-workspace-meta
branch
from
September 14, 2026 21:54
f734761 to
034262d
Compare
This was referenced Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
--phase-aware-workspacewith an MTP draft crashes under--split-mode tensoron the first target decode:The target and MTP contexts share one resizable compute buffer per buffer type (#36). Under
-sm tensorthat buffer is a meta buffer. A meta buffer maps each tensor to its per-device tensors, and it keeps that map for one graph at a time:ggml_backend_meta_graph_computerotates and clears it when a new graph runs. The sequence that breaks:set_inputsgetsnullptrThe first commit kept meta buffers out of the shared workspace. That fixed the crash, but it gave up the sharing under tensor split, which is the point of the phase-aware workspace.
The second commit shares the memory again. Only the tensor map can not be shared, the simple per-device buffers can:
ggml_backend_meta_buffer_aliascreates a second meta buffer over the same simple buffers, with its own tensor map and split state cache. It does not own the simple buffers.Testing
Qwen3.8-27B-UD-Q4_K_XL, RTX 3060 + RTX 4070,
--device CUDA1,CUDA0 -ts 0.55,0.45 --spec-type draft-mtp --phase-aware-workspace -np 2 -c 16384 -ub 512, KV on GPU. Peak VRAM sampled withnvidia-smievery 200 ms over load and one request:llama/dev(1a04ed9),-sm tensorGGML_ASSERT(tensor)on first decode-sm tensor-sm tensor-sm layer-sm tensorwith a 2568-token prompt and a follow-up request: ok, the workspace switches prefill/decode several times with the draft attached, draft acceptance 44 % and 90 %.test-alloc:test_resizable_buffers_owner_borrower_meta_aliasruns owner compute, borrower alloc + compute, then owner compute on the reused graph over a two-device CPU meta backend. Without the alias it fails with the sameGGML_ASSERT(tensor)as the server. The rest oftest-allocpasses.test-llama-archs --test-phase-workspace: passes.--no-kv-offload --kv-cpu-pinned --recurrent-state-offload --kv-gpu-layers 0) under-sm tensorhits a different assert in warmup on this base,GGML_ASSERT(i_start == cgraph->n_nodes), before MTP runs. ggml-meta : split a host-resident KV cache by head #66 fixes that.Tested with #66 merged on top (local branch, not part of this PR), same model and devices,
-sm tensor --spec-type draft-mtp --phase-aware-workspace -np 2 -c 16384plus the host KV flags above. Target KV 544 MiB and draft KV 64 MiB onCUDA_Host, recurrent state 673 MiB onMeta(), draft borrows the target workspace:test-alloc,test-llama-archs --test-sched-copy-nameand--test-phase-workspacepass on the merged build.Requirements
Assisted-by:commit trailers.🤖 Generated with Claude Code
https://claude.ai/code/session_016qzvRnpuN7dvnXNzK1F8dV