Skip to content

Wait for the first request in the async continuous batching bootstrap - #48304

Merged
remi-or merged 9 commits into
mainfrom
fix-cb-bootstrap-wait
Aug 27, 2026
Merged

remi-or merged 9 commits into
mainfrom
fix-cb-bootstrap-wait

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

CPU CI GPU run-slow

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 batch when the queue is still empty at background-thread start.

Validation: start() followed by a 5s sleep and then add_request generates normally (crashed before; repro in the issue).

Who can review?

@remi-or (continuous batching)

qgallouedec and others added 3 commits August 25, 2026 12:11
… 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.
@qgallouedec qgallouedec changed the title Wait for the first request in the async continuous batching bootstrap instead of crashing Wait for the first request in the async continuous batching bootstrap Aug 25, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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 remi-or left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
remi-or enabled auto-merge August 27, 2026 06:38
@remi-or
remi-or added this pull request to the merge queue Aug 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 33046465766:1
Result: success | Jobs: 15 | Tests: 179,614 | Failures: 0 | Duration: 15h 34m

Merged via the queue into main with commit 01846b5 Aug 27, 2026
112 checks passed
@remi-or
remi-or deleted the fix-cb-bootstrap-wait branch August 27, 2026 07:04
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async continuous batching crashes at start() if no request is queued yet

3 participants