Add per-sequence thread budget to SamplingConfig#1
Closed
FuJacob wants to merge 2 commits into
Closed
Conversation
createSequence now reads SamplingConfig.thread_count for a context's n_threads / n_threads_batch, falling back to the all-cores default when it is <= 0. This lets a caller cap a background sequence (e.g. the visual-context summarizer) to a smaller thread budget so it decodes concurrently with latency-critical autocomplete instead of oversubscribing every core and starving it — the dominant reason two CPU sequences showed no real concurrency before. Backward compatible: thread_count == 0 preserves prior behavior.
This reverts commit c58a938.
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
Adds a
thread_countfield toSamplingConfigso each sequence'sllama_contextcan be created with its ownn_threads/n_threads_batchbudget.createSequenceuses it when positive and falls back to the all-cores default when<= 0.Why: previously every context was created with
n_threads = hardware_concurrency()(all cores). Running two sequences at once — e.g. autocomplete + the visual-context summarizer — spawned two full sets of compute threads contending for the same physical cores, so on CPU-only machines the two streams oversubscribed and showed no real concurrency (and a background summary degraded autocomplete latency). With this, a caller can give the background sequence a smaller budget so the two decode concurrently on disjoint cores.Validation
The concurrent-sequences test now creates its background "summary" sequence with
thread_count: 2to exercise the reduced-budget path; the autocomplete sequence keeps the default (0).Linked issues
Risk / rollout notes
SamplingConfiggains a trailingthread_countfield, so every Swift call site of the bridged memberwise initializer must pass it. Consumers (the Cotabby app'sLlamaRuntimeCore.samplingConfig(from:)) need a companion change + a dependency pin bump before this takes effect.thread_count == 0reproduces prior all-cores behavior exactly. No change until a caller sets a positive budget.