From 97165993838c86dddb2c809ed22ad607991004b6 Mon Sep 17 00:00:00 2001 From: HuangJi <32611516+IPostYellow@users.noreply.github.com> Date: Thu, 23 Apr 2026 12:41:26 +0800 Subject: [PATCH] [diffusion] fix: avoid illegal memory access in qwen image (#22953) --- .../configs/pipeline_configs/qwen_image.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/sglang/multimodal_gen/configs/pipeline_configs/qwen_image.py b/python/sglang/multimodal_gen/configs/pipeline_configs/qwen_image.py index c6ff94aca..f30333487 100644 --- a/python/sglang/multimodal_gen/configs/pipeline_configs/qwen_image.py +++ b/python/sglang/multimodal_gen/configs/pipeline_configs/qwen_image.py @@ -247,6 +247,18 @@ class QwenImagePipelineConfig(QwenImageRolloutPipelineMixin, ImagePipelineConfig # img_shapes: for global entire image img_freqs, txt_freqs = rotary_emb(img_shapes, txt_seq_lens, device=device) + max_txt_seq_len = max(txt_seq_lens) if txt_seq_lens else 0 + txt_cache_len = int(txt_freqs.shape[0]) + if max_txt_seq_len > txt_cache_len: + overflow = max_txt_seq_len - txt_cache_len + raise ValueError( + "QwenImage RoPE text cache overflow before denoising: " + f"required_txt_seq_len={max_txt_seq_len}, txt_cache_len={txt_cache_len}, " + f"overflow={overflow}. " + "Please reduce the number of input images, shorten the prompt, " + "or lower the requested resolution." + ) + # flashinfer RoPE expects a float32 cos/sin cache concatenated on the last dim img_cos_half = img_freqs.real.to(dtype=torch.float32).contiguous() img_sin_half = img_freqs.imag.to(dtype=torch.float32).contiguous()