Repository navigation
perf(context): a context's schedulers place their graphs in one compute buffer - #190
Merged
Merged
Conversation
…te buffer Each retained graph held a compute buffer of its own on every device beside the main scheduler's, as large as the largest graph its slot ever held. On four RTX PRO 6000 S with GLM-5.3 Flash a 69-row reply graph's was 394 to 404 MiB a card, so 32 retained graphs could hold 12.6 GiB a card, which is what kept a long-context pool to 32 of them. A context computes one graph at a time and every tensor of a graph is written again at each compute, so the main scheduler and the slots' now place their graphs in one buffer a buffer type: ggml_gallocr_shared in ggml-alloc, which an allocator takes when its plan is one chunk that fits and grows only while no other allocator has a graph in it, set on a scheduler with ggml_backend_sched_set_shared_buffers. The reserve sizes it for the largest batch, as it sized the main scheduler's. A graph that does not fit gets a buffer of its own, and only such a slot is given back when a device is short of memory. Nothing waits for it. A graph's inputs are host tensors, and what a scheduler writes to a device (its copies of them, the graph's kernels) is queued on the device behind the graph computed before, its output reads and the draft index rows kept from it: the order a prompt's passes already relied on, each built in the main scheduler's buffer over the one before. Not with pipeline parallelism. LLAMA_GRAPH_BUFFER_SHARED_LEGACY=1 keeps a buffer a scheduler. The trace's build line says buf_shared. test-llama-archs: test_glm_shared_buffers decodes six shapes in turn, five retained and one on the main scheduler, on the target and on the MTP head, and gets the legacy switch's logits bit for bit with as many graphs reused; --glm-shared-buffers-device runs it on named devices.
The meta backend keeps, for a buffer, the simple tensors of the tensors initialized in it and their split states, and clears the split states of the whole buffer when a graph in it is built again. With one compute buffer for all of a context's schedulers every build then cleared the states of every retained graph, each computed again at the graph's next input copy or output read. An allocator set to share now gets, for a meta buffer type, a meta buffer of its own over the shared one's device memory (ggml_backend_meta_buffer_alias), so only the memory is shared and the bookkeeping is a scheduler's, as with LLAMA_GRAPH_BUFFER_SHARED_LEGACY=1. llama_get_memory_breakdown counts a shared buffer once, not once a scheduler. test_glm_shared_buffers gains an arm without a read between decodes: a round's six shapes are decoded back to back, each queued on the devices behind the one before, and only the last decode's logits are read and compared with the switch's. Its buffer count is now the context's compute memory, which stays what the reserve allocated where a buffer a scheduler adds the retained graphs'.
Member
Author
|
Follow-up on this branch (head 8668bd1): main merged in; each scheduler set to share now holds a meta buffer of its own over the shared device memory ( |
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.
What
A context's main scheduler and its graph slots' schedulers place their graphs in one compute buffer a buffer type, where each slot held a buffer of its own beside the main scheduler's.
ggml-alloc:ggml_gallocr_shared, a set of buffers graph allocators share. An allocator takes a type's shared buffer when its plan is one chunk that fits, and a buffer of its own otherwise. The shared buffer is allocated again, larger, only while no allocator has a graph in it.ggml-backend:ggml_backend_sched_set_shared_buffers,ggml_backend_sched_buffer_is_shared.llama_context: the set is made at the reserve, the main scheduler and every slot join it, and when a device is short of memory only a slot that holds a buffer of its own is given back.LLAMA_GRAPH_BUFFER_SHARED_LEGACY=1keeps a buffer a scheduler. Not used with pipeline parallelism.Why
On four RTX PRO 6000 S with GLM-5.3 Flash a kept 69-row reply graph's buffer was 394 to 404 MiB a card (Nov 11 box, build lines'
buf_mib), so 32 kept graphs could hold 12.6 GiB a card. That is what held a long-context pool to 32 kept graphs. With one buffer a kept graph costs no compute buffer (it still costs its CUDA executable).Why it is sound
A context computes one graph at a time and every tensor of a graph is written again at each compute. What a kept graph needs between computes lives in buffers of its own (pool tables, the draft bank, the NextN store, the recurrent state).
Nothing waits for it. A graph's inputs are host tensors (no input is pinned to a device), and what a scheduler writes to a device, its copies of the inputs and the graph's kernels, is queued on the device behind the graph computed before, its output reads and the draft index rows kept from it. A prompt's passes already rely on that order: each is built in the main scheduler's one buffer over the one before, with no synchronize between.
Read so far
Fixture, one RTX 5070 Ti, 23 sessions (four at 30,000 tokens), three turns, 32 kept graphs, traced:
The slots held 900 + 572 MiB there (target and draft), and the peak fell 1,488. Run times of this final form against the switch are being read now, three interleaved untraced pairs; they go in the TORAD.md row.
Not read: the four cards. No serving gain is claimed from this alone: it gives memory back.
Checks
ctest -L maininbuild-cpu, 109 tests, 108 passed and 1 skipped by design.test-llama-archs -a glm5nexton the CPU passes with the buffers shared by default.test_glm_shared_buffers: six shapes in turn, five retained and one on the main scheduler, target and MTP head, bit-equal logits to the switch with as many graphs reused. Passes on one and two CPU ranks, onCUDA0and onCUDA0,CUDA0(tensor split), three seeds.