Add stop_strings and stopping_criteria support to TransformerBridge.generate#1374
Merged
jlarson4 merged 1 commit intoJun 9, 2026
Merged
Conversation
Contributor
Author
|
Both red checks are the known flakes, not this PR: Notebook Checks (BERT) (import-cell stderr mismatch, passes locally) and Docstring Test (HF-429 on the model-loading doctests). |
Collaborator
|
Excellent work on this! False negative CI tests have passed on a re-run, merging as is |
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.
Description
stop_stringsandstopping_criteriatoTransformerBridge.generate()andgenerate_stream(), alongside the existingstop_at_eos. HuggingFace-native stopping is already reachable viahf_generate(). This brings the same stopping surface to the bridge's own generation loop, which previously supported only EOS stopping.stop_stringsreuses HuggingFace'sStopStringCriteriarather than a hand-rolled matcher, so its matching behavior is identical to HuggingFace.stop_at_eos,stop_strings, andstopping_criteria) are independent: any one of them ends a sequence.NotImplementedError. Stateful/SSM models raise only when run withuse_past_kv_cache=False(their default keeps them on the supported path).Notes for review
None(the default), generation output is byte-for-byte identical to before, so existing callers are unaffected.stop_at_eos=Falseinteraction required a change to shared loop logic, so the diff touches the existing EOS-handling path: the early-exit and finished-row padding were previously gated onstop_at_eos, and are now gated on whether any stop signal is active. Without this, astop_stringsmatch withstop_at_eos=Falsewould mark a sequence finished but never actually end generation.use_past_kv_cache=Truepath and is skipped on macOS-arm64 (the upstream KV-cache NaN, issue [Bug Report] [macOS-arm64] Cached eager attention NaNs in transformers v5 — blocks bridge KV-cache generation #1322), registered intests/QUARANTINES.mdper repo policy. Every other test runs on all platforms.Tests added
A new integration suite covering single and list
stop_strings, custom criteria (bare, list, andStoppingCriteriaList), thestop_at_eos=Falsecase, no-op defaults, batched generation,generate_streamparity, and the error contracts.Closes #595
Type of change
Checklist: