Repository navigation
[Bugfix][Qwen3.5] Give image prompts embedding spans so prefix hits past an image don't crash - #3041
Draft
syang-genai wants to merge 1 commit into
Draft
syang-genai wants to merge 1 commit into
syang-genai wants to merge 1 commit into
Conversation
…an image don't crash Qwen3.5 image prompts reached the runner without `embedding_spans`, so they took the whole-image merge: every vision row is scattered into the image tokens of the forward. After a prefix-cache hit that ends inside or past the image, the forward holds fewer image tokens than the vision tower returns rows, and `merge_multimodal_embeddings` dies with a shape mismatch. `build_qwen_vl_inputs` now returns each image's run of image tokens as an embedding span for the `qwen3_5` and `qwen3_5_moe` model types (the same gate as the Qwen3.5 MRoPE path), plus the media `cache_seed`. The runner then scatters only the slice of each image a forward contains, and image prompts can be chunked instead of prefilled in one forward. Image tokens that do not match the grids are rejected when the request is built. Qwen3.8 (`qwen4_exp`) is left on the old path for now. Fixes ROCm#2865
Contributor
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
|
This branch has not been deployed
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.
Motivation: fixes #2865. Qwen3.5 image prompts reach the runner without
embedding_spans, so they take the whole-image merge inModelRunner.run_model: every vision row is scattered into the forward's image tokens. After a prefix-cache hit that ends inside or past the image, the forward holds fewer image tokens than the vision tower returns rows, andmerge_multimodal_embeddingsfails with a shape mismatch ([784, 2048]into[0, 2048]in the issue's A, B, A repro).Technical details:
build_qwen_vl_inputsreturns each image's run of image tokens as anembedding_spansentry, plus the mediacache_seed. This applies to theqwen3_5andqwen3_5_moemodel types, the same gate as the Qwen3.5 MRoPE path. The runner then takes the span path that already exists: it scatters only the slice of each image a forward contains, and the image prompt no longer needs one atomic prefill.qwen3_5_image_spanswalks the prompt and claims each image'st*h*w / merge**2tokens in turn, so adjacent images without separators split correctly. Prompts whose image tokens don't match the grids are rejected when the request is built, instead of failing in the forward.qwen4_exp) stays on the whole-image path. Its processor output differs, and I'd rather handle it separately.Test Plan:
tests/test_multimodal_inputs.py:cache_seedtells different images apart;tests/test_multimodal_runtime.py:Test Result:
atom/models/qwen3_5_vl.pyreverted to main: 13 of the 14 new tests fail. The one that passes is the check that other model types are unchanged.Not done yet: I haven't run an end-to-end check on MI3xx/MI355X. I don't have one, and ATOM has no gfx11 path to test on my machine. If someone could rerun the issue's
ATOM_GDN_STATE_MIDSTEP=1A, B, A repro on this branch, that would close the gap. Opening as a draft until then.@ZLkanyo009, if you'd rather fold this into #2636, I'll close this one.