fix(bridge): decode every batch row in generate_stream - #1757
Merged
jlarson4 merged 1 commit intoSep 8, 2026
Merged
Conversation
generate_stream(return_type="str") decoded tokens[0] only, so a batched stream yielded the first sequence's text and the rest of the batch was unreachable — generation itself was fine, only the decode step dropped the other rows. Decode each row and keep generate()'s unwrap convention: a bare string for a one-row batch, one string per row otherwise. Covered at the unit tier with a stubbed token stream and at the integration tier against distilgpt2. Fixes TransformerLensOrg#1756
emerardd
force-pushed
the
fix/generate-stream-batch-decode
branch
from
September 8, 2026 15:04
f7b9432 to
65c5205
Compare
Collaborator
|
Great work on this @emerardd! Assuming Full Code Coverage passes, I will merge |
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
TransformerBridge.generate_stream(..., return_type="str")decodedtokens[0]only, so a batched stream yielded the first sequence's text and the rest of the batch was unreachable. Generation itself was fine — all rows are produced, andreturn_type="tokens"yields the full[batch, seq_len]tensor — only the decode step dropped them.This decodes every row and keeps
generate()'s unwrap convention: a bare string for a one-row batch, one string per row otherwise. The yield type widens toGenerator[Union[torch.Tensor, str, List[str]], None, None].generate_stream(prompts, ...)'The capital of France is the capital of the'['The capital of France is the capital of the', 'My favourite colour is the red. I']Single-string and single-row streaming are unchanged, which is why
tests/acceptance/model_bridge/test_generate_stream.py::test_stream_returns_stringspassed throughout.HookedTransformer.generate_streamdoes not share the bug — it never decodes and always yields tensors, even forreturn_type="str". That is a separate inconsistency, so no mirroring change (AGENTS.md §2) is required here.Fixes #1756
Type of change
Checklist:
Tests added — both fail on
devand pass with the fix:tests/unit/model_bridge/test_generate_stream_batch_decode.py— stubbed token stream, no model load; pins the batchedlist[str]yield and the single-row bare-string unwrap.tests/integration/model_bridge/test_generate_stream_batched.py— distilgpt2 end-to-end; each yield carries one string per prompt and the first yield echoes each row's own prompt.