Repository navigation
fix: reject oversized Transformers requests before generation - #19
Merged
Merged
Conversation
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.
The in-process Transformers backend sends tokenized prompts to generation without checking the context budget. A model can fail on oversized input; the streaming worker then tries to pass an error string to a tensor-only streamer, hiding the original failure behind a queue timeout.
Validate the tokenized prompt plus requested output against the reported context window in one shared path before sync or streaming generation. For example, a 9-token prompt with 1 requested output token and an 8-token window now raises a descriptive
ValueErrorbefore the model or a generation thread starts. Streams propagate worker exceptions, skip the input prompt and preserve successive text deltas. Deferred annotations also preserve the optional-dependency import error instead of evaluating missing torch types.Validation: 476 tests passed, 16 skipped, 238 subtests passed, including official OpenAI/MCP SDK checks. Eight focused offline regression tests cover oversized prompts, output budgets, exact boundaries, public chat/completion entry points, worker errors and correct deltas. Ruff, Black and a fresh strict Sphinx build passed. The regression cases failed on the old implementation. No real model weights or GPU were used; the email did not include the exact model, input or traceback, so its specific
IndexErroris not claimed as a live-model reproduction.The streamer behavior follows the official Transformers API. This fix is listed as Unreleased and is not present in PyPI 0.3.0.