Fix Qwen Image edit pipelines to forward multimodal token type IDs#14189
Open
wutachiang wants to merge 1 commit into
Open
Fix Qwen Image edit pipelines to forward multimodal token type IDs#14189wutachiang wants to merge 1 commit into
wutachiang wants to merge 1 commit into
Conversation
Contributor
|
Hi @wutachiang, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. |
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 #14194
What does this PR do?
This PR forwards
mm_token_type_idsfrom the processor to the Qwen2.5-VL text encoder in the following pipelines:QwenImageEditPipelineQwenImageEditPlusPipelineQwenImageEditInpaintPipelineThe argument is forwarded only when:
mm_token_type_ids.forwardsignature.This keeps the change backward compatible with older Transformers versions and processors.
Why is this needed?
Recent Transformers versions moved multimodal token classification into the processor. The processor now returns
mm_token_type_ids, where text, image, and video tokens are identified explicitly.Qwen2.5-VL uses these token type IDs to compute multimodal 3D RoPE position IDs. However, the Qwen Image edit pipelines currently select processor outputs manually and do not forward
mm_token_type_idsto thetext encoder.
As a result, the text encoder cannot compute the correct multimodal position IDs. This does not raise an exception because
position_ids=Noneis a valid fallback for the language model. Instead, inferencesilently falls back to regular position inference, which changes prompt embeddings and generated images.
Older Transformers versions did not require this argument because Qwen2.5-VL inferred multimodal positions directly from special image and video tokens in
input_ids.Backward compatibility
The new argument is not passed unconditionally.
Therefore:
Validation
The issue was traced through the Qwen2.5-VL encoding path:
Tests added in this PR verify that:
Existing CPU inference tests were also run with an older processor that does not emit mm_token_type_ids, and their expected outputs remained unchanged.
Tests
All targeted tests and checks pass.