talker: reserve prefill compute buffer at load time (max_prefill_tokens) - #16
Open
DerGary wants to merge 1 commit into
Open
talker: reserve prefill compute buffer at load time (max_prefill_tokens)#16DerGary wants to merge 1 commit into
DerGary wants to merge 1 commit into
Conversation
DerGary
force-pushed
the
talker-prefill-warmup-reserve
branch
from
July 23, 2026 12:15
6cf5054 to
8edef25
Compare
Author
|
@ServeurpersoCom friendly ping — would appreciate a look when you have a moment. |
ggml_backend_sched grows its compute/activation buffer to fit the largest graph it has ever built, and never shrinks it back. The talker prefill graph is shaped by the KV-padded context length (GGML_PAD(T_ctx, 256), see talker_forward_core), so the first prefill that lands in a new 256-token bucket ratchets VRAM usage up permanently. In a GPU-memory-constrained deployment (multiple models sharing one card) this makes VRAM usage on tts-server unpredictable: it grows the first time a long-enough prompt arrives on live traffic instead of being fixed at startup. This mirrors how llama.cpp handles the same problem for --ctx-size: reserve the worst-case compute buffer once, up front, via an explicit reservation pass, instead of letting it grow lazily. - qwen.h: bump QT_ABI_VERSION to 4, add qt_init_params.max_prefill_tokens (0 = disabled, matches previous behavior for zero-initialized older callers). - qwen.cpp / pipeline-tts.h / pipeline-tts.cpp: thread the new field through to pipeline_tts_load, which -- when max_prefill_tokens > 0 -- runs one throwaway talker_forward_prefill call on KV set 0 with a zero-filled embedding of that length (clamped to the KV cache's max_seq_len), discards the result, and resets the KV set. This forces the scheduler to reserve the compute buffer for that prefill bucket before the server starts accepting connections. - tools/tts-server.cpp: new --max-prefill-tokens <n> CLI flag wiring into the above. Failure to reserve (almost always CUDA OOM) is fatal, not a logged warning: this is a capacity check, not a performance warmup. A deployment that cannot afford its own configured worst case should refuse to start loudly at boot, instead of succeeding here and then failing unpredictably mid conversation once a live request finally needs that memory. Tested on a memory-constrained Pascal (sm_61, 8GB) box sharing the GPU with other models. Confirmed via nvidia-smi: - Without a reservation: VRAM ratcheted up ~10MB the first time a request crossed into a new 256-token decode/prefill bucket, and never came back down. - With --max-prefill-tokens 512: the log line "[Pipeline] Reserving talker prefill compute buffer for T=512..." appears before "[Server] listening on ...", and VRAM is flat across repeated requests within that bucket. - Server still starts and serves correctly with --max-prefill-tokens omitted (default 0, no behavior change). Note: this only reserves the prefill bucket (scales with input text length). Decode/codec buffers (scale with output audio length) still grow lazily the first time a longer generation is requested -- out of scope for this change.
DerGary
force-pushed
the
talker-prefill-warmup-reserve
branch
from
July 25, 2026 09:32
8edef25 to
ae0362a
Compare
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.
Summary
ggml_backend_schedgrows its compute/activation buffer to fit the largest graph it has ever built, and never shrinks it back. The talker prefill graph is shaped by the KV-padded context length (GGML_PAD(T_ctx, 256), seetalker_forward_core), so the first prefill that lands in a new 256-token bucket ratchets VRAM usage up permanently. In a GPU-memory-constrained deployment (multiple models sharing one card) this makes VRAM usage ontts-serverunpredictable: it grows the first time a long-enough prompt arrives on live traffic instead of being fixed at startup.This mirrors how
llama.cpphandles the same problem for--ctx-size: reserve the worst-case compute buffer once, up front, via an explicit reservation pass, instead of letting it grow lazily.Changes
qwen.h: bumpQT_ABI_VERSIONto 4, addqt_init_params.max_prefill_tokens(0 = disabled, matches previous behavior for zero-initialized older callers).qwen.cpp/pipeline-tts.h/pipeline-tts.cpp: thread the new field through topipeline_tts_load, which — whenmax_prefill_tokens > 0— runs one throwawaytalker_forward_prefillcall on KV set 0 with a zero-filled embedding of that length (clamped to the KV cache'smax_seq_len), discards the result, and resets the KV set. This forces the scheduler to reserve the compute buffer for that prefill bucket before the server starts accepting connections.tools/tts-server.cpp: new--max-prefill-tokens <n>CLI flag wiring into the above.Failure to reserve (almost always CUDA OOM) is fatal, not a logged warning: this is a capacity check, not a performance warmup. A deployment that cannot afford its own configured worst case should refuse to start loudly at boot, instead of succeeding here and then failing unpredictably mid conversation once a live request finally needs that memory.
Testing
Deployed on a memory-constrained Pascal (sm_61, 8GB) box sharing the GPU with other models. Confirmed via
nvidia-smi:--max-prefill-tokens 512: the log line[Pipeline] Reserving talker prefill compute buffer for T=512...appears before[Server] listening on ..., and VRAM is flat across repeated requests within that bucket.--max-prefill-tokensomitted (default 0, no behavior change).Note: this only reserves the prefill bucket (scales with input text length). Decode/codec buffers (scale with output audio length) still grow lazily the first time a longer generation is requested — out of scope for this PR, handled operationally on our end with an additional end-to-end warmup synthesis at the application layer.