fix(ernie-image): pass attn_mask=None when text is unpadded#13802
Open
Ace3Z wants to merge 1 commit into
Open
Conversation
4bf7bcc to
5f37368
Compare
5f37368 to
fb49e96
Compare
ErnieImageTransformer2DModel.forward built a bool attention mask from
text_lens on every call, including the common case where every sample
already has full-length text. flash-attn 2 rejects any non-None
attn_mask, so set_attention_backend('flash') crashed even though the
all-True mask was effectively a no-op. Z-Image's _prepare_for_attention
takes the same shortcut.
Closes huggingface#13801
fb49e96 to
84ae4b4
Compare
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.
Fixes #13801.
pipeline.transformer.set_attention_backend("flash")onErnieImagePipelinecrashes withValueError: attn_mask is not supported for flash-attn 2. The same code works onZImagePipelineandFlux2KleinPipeline.ErnieImageTransformer2DModel.forwardalways built a bool attention mask fromtext_lens, even when every sample had full-length text. In that case the mask is all True and flash-attn legitimately refuses it. Z-Image's_prepare_for_attentionalready takes the shortcut: skip the mask whenall(seq == max_seqlen). This PR does the same.The previous all-True mask was a no-op on sdpa, cudnn and native paths, so behavior on those backends is unchanged. I checked numerically: with the same seed, baseline and fix produce bit-identical output in both the uniform and padded cases.
Before submitting
docs/source/en/.cc @yiyixuxu @sayakpaul