Skip to content

[CB] Fail faster - #48334

Merged
remi-or merged 7 commits into
mainfrom
cb-better-errors
Aug 27, 2026
Merged

remi-or merged 7 commits into
mainfrom
cb-better-errors

Conversation

@remi-or

@remi-or remi-or commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

CPU CI GPU run-slow

This PR fixes #48303 and makes error handling more redundant in CB:

  • the fatal_error attribute lived awkwardly next to background_thread_status, an object meant to keep track of the bg thread status (shockingly). Since fatal_error is there for consumers to check if the thread is still running, and if not why, it is now an attribute of the background_thread_status object
  • add_request now returns ealry when you try to add a request after a fatal error. It does not fail, because the current API is not built that way, but we can change that downstream.
  • get_outputalso returns early if the manager had a fatal_error
  • unlike in Fail fast when the continuous batching background thread has died #48301, get_output timeout stayed similar but the way pending_requests are failed now ensures that even if the processor is not created when the manager fail, there will be an output delivered for pending request. This eliminates the need for a more granular timeout
  • changed the behavior of is_finished because it's mostly used as is_finished_or_failed, there might be a name change down the road but out of scope here

It supersedes #48301.

Tests run well. This script no finishes fast:

import traceback
from time import perf_counter

import torch

from transformers import AutoModelForImageTextToText, AutoTokenizer


model_id = "Qwen/Qwen3-VL-4B-Instruct"  # any ForConditionalGeneration model
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(model_id, dtype=torch.bfloat16, device_map="cuda:0")

prompt = tokenizer.apply_chat_template([{"role": "user", "content": "Hi!"}], add_generation_prompt=True)["input_ids"]

with model.continuous_batching_context_manager(warmup=False) as cb:
    start = perf_counter()
    try:
        request_id = cb.add_request(prompt)
        print(f"[{perf_counter() - start:.2f}s] add_request returned {request_id = }")
        result = cb.get_result(request_id, timeout=100)
        print(f"[{perf_counter() - start:.2f}s] get_result returned {result = }  <-- BUG: silent timeout")
    except Exception:
        print(f"[{perf_counter() - start:.2f}s] failed fast with:")
        traceback.print_exc()

@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.

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 32961394376:1
Result: success | Jobs: 1 | Tests: 6 | Failures: 0 | Duration: 24s

@remi-or
remi-or requested a review from ArthurZucker August 26, 2026 14:46
@remi-or remi-or self-assigned this Aug 26, 2026
@remi-or remi-or moved this from Backlog to In progress in Continuous batching Aug 26, 2026
@remi-or remi-or moved this from In progress to In review in Continuous batching Aug 26, 2026
@qgallouedec

Copy link
Copy Markdown
Member

Thks, this does the trick. Delivering FAILED outputs even when the batch processor was never created removes the case my granular timeout was working around. Closing #48301 in favour of this.

One thing to confirm: get_result returns None both for "queue empty" and "thread dead", so a waiting consumer must poll background_thread_status.fatal_error or it spins forever. Workable for me (my loop will check it and treat FAILED outputs as poisoning their group), but maybe worth a line in the docstring? no strong opinion.

@remi-or
remi-or added this pull request to the merge queue Aug 27, 2026
Merged via the queue into main with commit b6c0bfe Aug 27, 2026
113 checks passed
@remi-or
remi-or deleted the cb-better-errors branch August 27, 2026 04:37
@github-project-automation github-project-automation Bot moved this from In review to Done in Continuous batching Aug 27, 2026
sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
* Regroup fatal error under the bg thread status

* Fail at add request

* Fail fast in get outputs

* Nit

* Actually fail the request before processor is created

* No more loud failure

* Fixed some issues with is_finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

3 participants