Skip to content

[Bug] Qwen Image Edit 2509/2511: reference images reach the vision encoder at full size; edits turn into a drawing above ~0.6 MP of references #2427

Done

Description

@chris83-dev

Git commit

79dc7ca (origin/master 5fa203c has no change on this path)

Operating System & Version

Windows 10 (x64)

GGML backends

CPU, CUDA

Command-line arguments used

sd-cli --diffusion-model qwen-image-edit-2511-Q8_0.gguf --vae qwen_image_vae.safetensors --llm Qwen2.5-VL-7B-Instruct.Q8_0.gguf --llm_vision Qwen2.5-VL-7B-Instruct.mmproj-f16.gguf --model-args qwen_image_zero_cond_t=true -r ref.png --cfg-scale 4 --sampling-method euler --flow-shift 3 --steps 20 --seed 42 -W 1024 -H 1024 -p "Make it night with a full moon above the street, keep the sign and the shop exactly as they are"

Steps to reproduce

  1. Take a 1024×1024 photo of a shop front with a painted sign (ours was made with Qwen-Image 2.1).
  2. Run the command above with ref.png at 1024×1024, then the same image downscaled to 896×896 and to 768×768 (seed 42, everything else equal).
  3. Optionally: a 512×512 output with the 1024×1024 reference; the text encoder on the CPU (--backend clip=cpu); two references.

What you expected to happen

The same photo at night with a moon, shop and sign kept, whatever the size of the reference (as with diffusers' QwenImageEditPlusPipeline).

What actually happened

Seed 42, everything else equal:

  • reference 768×768: correct edit (night, moon, sign text intact)
  • 896×896: the sign text is wrong, no moon
  • 1024×1024: the whole scene is redrawn as an illustration, sign garbled
  • 512×512 output from the 1024×1024 reference: an unrelated scene
  • the same with the text encoder and vision on the CPU (--backend clip=cpu), with the VAE on the CPU, at cfg 1 / 2.5 / 4, at 20 or 40 steps, with the GGUF or the Comfy bf16 text encoder: not a CUDA or precision issue
  • text-only (no reference): fine
  • two references of 768×768 each: the instruction is ignored and the inside is drawn; the same two at 528×528: a correct composition

So the edit degrades with the total size of the references given to the vision encoder, from about 0.6 MP.

Logs / error messages / stack trace

[V] resize conditioner ref image 0 from 768x768 to 756x756 --- conditioner.hpp:2903      (correct edit)
[V] resize conditioner ref image 0 from 1024x1024 to 1036x1036 --- conditioner.hpp:2903  (drawing)

Additional context / environment details

Cause, from the code: in src/api/generation_image.cpp (image_references), Qwen Image Edit (not 2.1) passes reference_<i>_original as the prompt media, i.e. the reference at its original size, and the Qwen Image conditioner (src/conditioning/conditioner.hpp, the QwenImageEditPlusPipeline branch) only rounds it to a multiple of 28: a 1024×1024 reference becomes 1036×1036, 37×37 = 1369 vision tokens (896: 1024 tokens; 768: 729). Diffusers' QwenImageEditPlusPipeline resizes each image to CONDITION_IMAGE_SIZE = 384 * 384 for the VL encoder (about 188 tokens) and to VAE_IMAGE_SIZE = 1024 * 1024 for the VAE; ComfyUI's TextEncodeQwenImageEditPlus also uses a 384×384 area. The VAE path of sd.cpp is already fitted to min(1 MP, output area). The example docs/dgl/qwen_image_edit/qwen-image-edit-2511.dgl also passes reference_0_original.

Suggested fix: give the vision encoder each reference resized to a ~384×384 area (aspect kept, multiple of 28) for the Qwen Image Edit Plus models, independently of the VAE reference. Workaround until then: downscale the references so their total area stays under ~0.6 MP (one 768×768, or two 528×528).

Files: unsloth/Qwen-Image-Edit-2511-GGUF (Q8_0), mradermacher/Qwen2.5-VL-7B-Instruct-GGUF (Q8_0 + mmproj-f16), Comfy-Org/Qwen-Image (qwen_image_vae, and qwen_2.5_vl_7b bf16 for the cross-check). GPU: NVIDIA V100 (sm_70), CUDA 12.6; same results on the CPU path. sd-server shows the same through /sdcpp/v1/img_gen; within the limit, the lightx2v Lightning 8-step LoRA also gives correct edits.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions