Commit 456f52d for stable-diffusion.cpp
commit 456f52d2dea22c22d5eebc2b7f5c73d177bfe1d1
Author: leejet <leejet714@gmail.com>
Date: Thu Nov 26 21:03:58 2026 +0800
fix: resize Qwen Image Edit vision references (#2433)
diff --git a/docs/models/qwen_image_edit.md b/docs/models/qwen_image_edit.md
index 3dacdae..fd701f2 100644
--- a/docs/models/qwen_image_edit.md
+++ b/docs/models/qwen_image_edit.md
@@ -178,3 +178,9 @@ To use the new Qwen Image Edit 2511 mode, `--model-args qwen_image_zero_cond_t=t
```
<img alt="qwen_image_edit_2509" src="../../assets/qwen/qwen_image_edit_2511.png" />
+
+## Notes and limitations
+
+The vision encoder uses a target area of `384 × 384` pixels for each reference
+image, preserving its aspect ratio up to the encoder's patch alignment. VAE
+reference latents use a separate resize based on the output size.
diff --git a/src/conditioning/conditioner.hpp b/src/conditioning/conditioner.hpp
index 331e33b..cefb905 100644
--- a/src/conditioning/conditioner.hpp
+++ b/src/conditioning/conditioner.hpp
@@ -2931,6 +2931,13 @@ struct LLMEmbedder : public Conditioner {
int h_bar = static_cast<int>(std::round(static_cast<double>(height) / factor) * factor);
int w_bar = static_cast<int>(std::round(static_cast<double>(width) / factor) * factor);
+ if (version == VERSION_QWEN_IMAGE) {
+ constexpr double target_area = 384.0 * 384.0;
+ const double scale = std::sqrt(target_area / (static_cast<double>(width) * height));
+ h_bar = std::max(factor, static_cast<int>(std::round(height * scale / factor)) * factor);
+ w_bar = std::max(factor, static_cast<int>(std::round(width * scale / factor)) * factor);
+ }
+
LOG_VERBOSE("resize conditioner ref image %d from %dx%d to %dx%d", i, height, width, h_bar, w_bar);
auto resized_image = clip_preprocess(image, w_bar, h_bar);