[Bug] Qwen-Image-2.1 edits come out oversaturated and over-sharpened (CUDA, bf16 safetensors), text-to-image is fine
Git commit
1b0ba10893f4e2e0656103011fc1c4645a02a734 (master-956), built from source with -DSD_CUDA=ON
Operating System & Version
Ubuntu 24.04.5 LTS, kernel 7.0.0-1019-nvidia, aarch64
GGML backends
CUDA
Command-line arguments used
sd-cli --diffusion-model qwen_image_2.1_bf16.safetensors --vae qwen_image_2.1_vae_bf16.safetensors --llm qwen3vl_8b_bf16_heretic.safetensors --fa --cfg-scale 1.0 --sampling-method euler --steps 25 -s 42 -W 1024 -H 1024 -r fox.png -p "put a knitted red scarf around the fox neck, keep everything else the same" -o edit.png
Steps to reproduce
- Generate a 1024x1024 image with the same three files, no reference (
-p "a red fox sitting on a mossy rock in a misty forest, morning light, photo"). This comes out fine. - Feed that image back with
-rand an edit prompt, command above. - Compare the result with the input.
What you expected to happen
The edit applied and the rest of the picture left roughly as it was. That's what ComfyUI gives with the same three files (official 2.1 edit template, 25 steps, cfg 1, euler/simple).
What actually happened
The edit itself is applied correctly (the fox gets its scarf, composition is kept), but the whole image comes back heavily oversaturated and over-sharpened. A soft misty background turns into loud orange/purple/green blotches. Mean HSV saturation goes from 66 on the input to 131 on the output, and the stddev of V from 44 to 72.
It looks like the same thing that was mentioned in passing in #2006 ("works but makes the image high contrast sharpened"). That report used the int8 convrot model and the GGUF encoder + mmproj, so it doesn't seem tied to the weight format.
Text-to-image with the same files and settings is fine, so it's only the reference path.
Things I tried, all give practically the same output (saturation 131-135):
- cfg 6, 4 and 1
- with and without
--fa --model-args qwen_image_2_1_prefix_cache=false(byte-identical file to the cached run)- 40 steps instead of 25
flow_shift5.0 throughsd_cpp_extra_argson sd-server, alone and with 40 steps--linear-scale 0.0078125 --attn-scale 0.0078125and0.00390625for both, from the troubleshooting guide- sd-server
/v1/images/edits(started with--strength 1.0) vssd-cli -r: same result
The VAE seems fine on its own: img2img on the same picture with -i and --strength 0.08 (2 steps) comes back with saturation 66, same as the input, with or without --vae-conv-direct.
Since nothing on the sampling side changes the result at all, my guess is something in how the reference latents/tokens are handed to the DiT in edit mode, but I haven't dug into the code.
Logs / error messages / stack trace
No errors or warnings apart from the auto-fit one. Relevant lines:
[I] Version: Qwen Image 2.1 --- diffusion_engine.cpp:997
[W] auto-fit: no GPU devices; using the default backend --- backend_fit.cpp:444
[I] Weight type stat: bf16: 1253 --- diffusion_engine.cpp:1526
[I] Using flash attention --- diffusion_engine.cpp:1190
[I] total params memory size = 29751.86MB (VRAM 29751.86MB, RAM 0.00MB): text_encoders 15536.43MB(VRAM), diffusion_model 13571.05MB(VRAM), vae 644.38MB(VRAM)
[I] running in FLOW mode --- diffusion_engine.cpp:1470
[I] preprocess ref[0]: 1024x1024 crop=(0,0,1024,1024) resize=1024x1024 pad=(0,0) output=1024x1024 filter=auto(0) antialias=false --- image_preprocess.cpp:266
[I] generate_image 1024x1024 --- image.cpp:814
[I] Using 'qwen' preset for reference images --- diffusion_engine.cpp:3121
[I] get_sigmas with Flux scheduler --- denoiser.hpp:1196
[I] sampling using Euler method --- request.cpp:422
[I] EDIT mode --- image.cpp:274
[I] encode_first_stage completed, taking 1.34s --- image.cpp:398
[I] get_learned_condition completed, taking 2.53s --- image.cpp:529
[I] sampling completed, taking 86.06s --- image.cpp:899
[I] generate_image completed in 93.33s --- image.cpp:1050
With -v the edit run also prints Flux scheduler: image_seq_len=4096, steps=25, mu=0.694, shift_terminal=0.020.
Additional context / environment details
- NVIDIA DGX Spark (GB10, unified memory), driver 580.178.04, CUDA 13.0
- Diffusion model and VAE:
qwen_image_2.1_bf16.safetensorsandqwen_image_2.1_vae_bf16.safetensorsfrom Comfy-Org/Qwen-Image-2.1 - Text encoder:
qwen3vl_8b_bf16_heretic.safetensorsfrom pottokao/Qwen-Image-2.1-Text-Encoder-Heretic. It's a refusal-ablated Qwen3-VL-8B in the Comfy single-file layout with the vision tower included (log says "enable llm vision", so no separate--llm_vision). I don't have the stock encoder on this box any more to cross-check, but the #2006 comment was with the stock GGUF one. - Not tested on master-959; the three commits since 956 don't look related.
I'll add the input and output images in a comment.
input:
output edit:
I reproduced this, and the results match the noise replay behavior already reported in ComfyUI #16607 and Qwen-Image-2.1 #9. The Qwen pipeline contributor also diagnosed this scenario in Diffusers #14824.
Related reports: https://github.com/Comfy-Org/ComfyUI/issues/16607#issuecomment-5893821034 https://github.com/QwenLM/Qwen-Image-2.1/issues/9 https://github.com/huggingface/diffusers/issues/14824#issuecomment-5763057767
I cross-tested two independently generated references. All edits used 1024×1024, Euler, 25 steps and CFG 1.
For reference A, generated with sd.cpp's CUDA RNG at seed 42, editing with sd.cpp at seed 42 produced oversaturated, over-sharpened output. Editing the same reference with ComfyUI's CPU RNG at seed 42 was clean, as was changing the sd.cpp edit seed to 43.
For reference B, generated with ComfyUI's CPU RNG at seed 42, the result was reversed: editing with sd.cpp's CUDA RNG at seed 42 was clean, while ComfyUI's CPU RNG at seed 42 produced severe sharpening and grain. Changing the ComfyUI edit seed to 43 removed that degradation.
The attached comparison shows both directions. I also supplied ComfyUI with the exact starting noise from the failing sd.cpp run; it reproduced the same oversaturated appearance. The failure follows replaying the reference's original starting noise, rather than one particular application or the number 42 itself.
Using the same numeric seed across these defaults does not generate the same noise: sd.cpp defaults to the CUDA RNG, while ComfyUI uses a CPU RNG. Reusing the same RNG, seed and latent shape can instead reproduce the exact starting noise that generated the reference, triggering this known behavior.
I suggest trying a different seed—for example, changing -s 42 to -s 43. This eliminated the corresponding artifacts in both of my local test cases.
Thanks, that was it. My fox reference was generated with the default seed (42) and I edited it with -s 42 too, so it was replaying the same starting noise. Reran it with the same files and settings: seed 42 still comes out oversaturated (mean saturation 117 vs 40 on the input), seed 43 and a random seed are both clean (49 and 47). Our server already runs with --seed -1, and an edit through it also came out fine.
So not an sd.cpp bug. Closing this.