Skip to content

generate stream properly handles padding_side - #2031

Merged
jlarson4 merged 1 commit into
devfrom
fix/generate-stream-padding-side
Nov 19, 2026
Merged

jlarson4 merged 1 commit into
devfrom
fix/generate-stream-padding-side

Conversation

@jlarson4

Copy link
Copy Markdown
Collaborator

Description

  • generate_stream reads padding_side on token input – the argument was accepted and never read for a token tensor, so a left-padded batch streamed as though its pads were context while generate masked them; the prompt mask is now read off the pad token, and a padded row streams what its prompt does alone.
  • One helper derives the mask for both – generate's pad-token scan moved into _padded_prompt_mask, which generate_stream now calls too, so both raise the same ValueError when the bridge has no tokenizer or the tokenizer has no pad id.
  • Encoder-decoder models receive the derived mask – generate derived a mask from padding_side and never passed it to the encoder, and generate_stream never derived one, so the encoder attended the pads; both now forward it as the encoder's attention mask, as forward already did.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@jlarson4
jlarson4 merged commit 6062a01 into dev Nov 19, 2026
31 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.

1 participant