Skip to content

fix: reject oversized Transformers requests before generation - #19

Merged
1Utkarsh1 merged 2 commits into
mainfrom
fix/transformers-streaming-context
Oct 24, 2026
Merged

1Utkarsh1 merged 2 commits into
mainfrom
fix/transformers-streaming-context

Conversation

@1Utkarsh1

Copy link
Copy Markdown
Owner

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 ValueError before 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 IndexError is 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.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 11:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@1Utkarsh1
1Utkarsh1 merged commit 306576b into main Oct 24, 2026
10 checks passed
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.

2 participants