Repository navigation
Wait for the first request in the async continuous batching bootstrap - #48304
Merged
Merged
Conversation
… instead of crashing The async-batching path bootstraps the first batch unconditionally at background-thread start and raises 'Failed to bootstrap the first batch' when the request queue is still empty. Whether a manager works therefore depends on a race between start() and the first add_request; user code that starts the manager and submits from another thread wins or loses it nondeterministically. Wait for the first request with the same stop conditions as the main loop instead.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
remi-or
approved these changes
Aug 27, 2026
Collaborator
There was a problem hiding this comment.
Thanks, I never had this issue before! I just committed a de-duplication of the code, I think we are good to merge.
For the record, this is the code I ran to check the fix works:
import time
import torch
from transformers import AutoModelForCausalLM, ContinuousBatchingConfig
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Meta-Llama-3-8B-Instruct", device_map="cuda", attn_implementation="paged|sdpa"
)
cb_config = ContinuousBatchingConfig(use_async_batching=True)
with model.continuous_batching_context_manager(continuous_batching_config=cb_config) as manager:
time.sleep(5)
manager.add_request(input_ids=torch.randint(0, 100, (10,)).tolist(), max_new_tokens=10)
x = manager.get_result(timeout=10)
remi-or
enabled auto-merge
August 27, 2026 06:38
Contributor
CI recapDashboard: View test results in Grafana |
qgallouedec
added a commit
that referenced
this pull request
Aug 29, 2026
Three conflicts, resolved as follows. The async bootstrap loop takes main's version. Our fix for it (#48304) was merged upstream and refactored into `_generation_loop_body(batch_processor, bootstrapping=True)`, which waits, retries and exits after the first step with the same stop conditions, so the explicit loop here was redundant. `paged|sdpa` with no cache takes main's version, which raises. This branch still had the earlier redirect-to-the-base-implementation approach; #48297 landed the raise instead after review, so keeping the redirect would have reverted a decision this branch itself asked for. The warmup comment keeps both lines: one says why the log line is there, the other is main's TODO for a progress bar. Checked against the merge rather than assumed: data parallel 2.32 s/step, tensor parallel with the KV cache released each step 2.46 s/step with the parameters changing, and the release/restore and CPU offloading tests in tests/generation/test_continuous_batching.py.
sbucaille
pushed a commit
to sbucaille/transformers
that referenced
this pull request
Sep 16, 2026
…huggingface#48304) * Wait for the first request in the async continuous batching bootstrap instead of crashing The async-batching path bootstraps the first batch unconditionally at background-thread start and raises 'Failed to bootstrap the first batch' when the request queue is still empty. Whether a manager works therefore depends on a race between start() and the first add_request; user code that starts the manager and submits from another thread wins or loses it nondeterministically. Wait for the first request with the same stop conditions as the main loop instead. * Trim comment * Reduce the amount of duplicate code * Style --------- Co-authored-by: remi-or <[email protected]> Co-authored-by: Rémi Ouazan <[email protected]>
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 does this PR do?
Fixes #48303. Part of #48294.
Change: the async-batching bootstrap waits for the first request with the same stop conditions as the main loop (hard stop, or flush with nothing pending), instead of raising
Failed to bootstrap the first batchwhen the queue is still empty at background-thread start.Validation:
start()followed by a 5s sleep and thenadd_requestgenerates normally (crashed before; repro in the issue).Who can review?
@remi-or (continuous batching)