Repository navigation
Conversation
Retain the scheduler while its node capacity is sufficient, and recreate it when the required capacity grows. Cover sampler detach, replacement and clearing with a compute-buffer capacity regression test. Builds on the scheduler-retention approach in ggml-org#28872.
1 of 5 tasks
am17an
reviewed
Nov 7, 2026
am17an
left a comment
Contributor
There was a problem hiding this comment.
Tested and verified this change on my setup. Thanks for the PR.
Contributor
|
@ggerganov can we merge this? Really nice speed-up when using backend sampling |
Member
|
I'll push an alternative version soon. |
Member
|
Superseded by #32009 |
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
Fixes #31840.
This follows the scheduler-retention approach proposed by @douyamv in #28872. That draft remains open. This continuation applies the approach to the current code, adds a node-capacity growth guard, and adds regression coverage.
With backend sampling, finishing a request detaches its sampler and triggers
sched_reserve(). Recreating the scheduler also destroys its allocator and compute buffers, including pinned host buffers. Keep the existing scheduler when its node capacity is sufficient; recreate it when the required capacity grows. Graph invalidation, synchronization, allocation planning, and the explicit pipeline-parallel fallback remain in place.The new
test_sampler_buffer_reusechecks retained compute capacity across sampler removal, replacement, a larger sampling graph, and clearing all samplers. It also checks valid backend tokens and the return to raw logits after detaching all samplers. The test fails before the change and passes afterward on both CPU and CUDA.Additional information
RTX 5070, Qwen3-0.6B BF16 GGUF, unified FP16 KV, backend sampling, pinned memory enabled throughout. The fixed workload from #31840 contains 256 requests in eight sequential batches of 32 concurrent requests. Each run has an extra 32-request warmup; startup and warmup are excluded.
Wall time decreased 16.15%. All six runs passed 256/256 length checks, with 133966 output tokens each. No request, model, KV, or sampling parameters were changed between builds.
In a separate first-32-request Nsight diagnostic, measurement-window
cudaMallocHost/cudaFreeHostcalls fell from 33 / 33 to 0 / 0. Cumulativesched_reservetime fell from 1.435 s to 0.042 s. A full-lifetime trace confirmed successful pinned allocations before measurement and their release after measurement, so this does not disable pinned memory.Measurements were made against
31424b7c. The final rebase is ontoc0ab6e5c; the only intervening upstream change adds the missing pthread link. The CPU/CUDA sampler suites and allocator test were rerun on the final commit.Validation with the same Qwen3-0.6B model:
test-alloc, EditorConfig checks on the changed files, andgit diff --checkpass.14.7147 +/- 1.51865before and after.llama-benchchecks show no material change: pp512 38287 -> 38233 tokens/s; tg128 408.31 -> 408.43 tokens/s.The existing allocator retains its high-water buffer capacity until growth requires reallocation or the context is destroyed. This change does not introduce a new allocator or modify kernels/public APIs.
Requirements