Repository navigation
Studio: Qwen-Image-Layered on the native sd.cpp engine - #12777
Conversation
_map_guidance returned no cfg for flux.1, flux.2-klein and flux.2-dev, so the one-shot argv had no --cfg-scale and the server request had no guidance.txt_cfg. sd.cpp then applied its own default cfg of 7.0, which renders FLUX.1-dev and schnell dark or burnt and oversaturates FLUX.2. Guidance-distilled FLUX (FLUX.1 dev / schnell / Kontext, FLUX.2-dev) now runs one pass at cfg 1.0 with the embedded guidance. FLUX.2-klein has no guidance embedder, so it takes the real-CFG mapping: the 4-step models default to 1.0, the undistilled klein-base to its real CFG of 5.0.
…sd.cpp engine
The native engine refused every edit-only family at load ("has no native
sd.cpp asset mapping"), because qwen-image-edit and flux.1-kontext declared
no single-file VAE or text encoders, although the pinned sd.cpp build runs
all of them with the source image as a reference image.
- Asset mapping: Qwen-Image-Edit (original, 2509, 2511) takes Qwen-Image's
VAE, the Qwen2.5-VL Q4_K_M encoder and its mmproj vision projector, euler,
flow shift 3. 2511's zero-timestep conditioning is detected by sd.cpp
from the __index_timestep_zero__ tensor the GGUF carries. Kontext takes
the FLUX.1 VAE and CLIP-L + T5-XXL.
- Guidance: Kontext runs cfg 1.0 with the embedded guidance; the Qwen edit
checkpoints keep real CFG, the value the diffusers path passes as
true_cfg_scale.
- Edit-only workflow on both transports: an input image is an edit, the
source is sent as the one --ref-image / ref_images entry, the output takes
the source size snapped to the grid as on the diffusers engine, and
status() advertises only "edit". Qwen edit needs its projector loaded.
- Same refusals as the diffusers engine for text-to-image, the reference
workflow, reference images and masks on these families.
Qwen-Image-Layered had no family, and the layered keyword guard routed every layered id away from qwen-image, so the public GGUFs were refused as unsupported. Add a qwen-image-layered family on QwenImageLayeredPipeline with the ComfyUI Image to Layers defaults (20 steps, cfg 2.5, shift 1, 2 layers at 640), an RGBA input, and each decomposed RGBA layer returned as its own output image. The public GGUFs store time_text_embed.addition_t_embedding (an nn.Embedding) in BF16, which diffusers keeps packed outside its GGUFLinear layers, so the first step read raw bytes. Dequantise packed parameters that sit outside the quantizer's linears after a GGUF transformer load; no other shipped family has any. A local pipeline whose model_index declares a family that its folder name rules out stays refused in both the listing and the loader.
Qwen-Image-Layered now has a Studio family (the diffusers route), but the native engine still refused it: the family had no single-file assets, and the engine had no way to ask for a layer count or to collect the layers. The pinned sd.cpp build decomposes it from a reference image with --qwen-image-layers / "qwen_image_layers". - Assets: the layered model's own 4-channel VAE, taken from the vendor base's vae/diffusion_pytorch_model.safetensors (the file the diffusers route fetches; sd-cli reads it as is and its layers are pixel-identical to the ComfyUI repack's), and the Qwen2.5-VL Q4_K_M encoder. No projector: sd.cpp never runs the vision tower for this model. euler, flow shift 1.0, the diffusers route's ComfyUI shift. - The layer count goes out on both transports: --qwen-image-layers on the one-shot argv, qwen_image_layers in the sd-server body. - sd.cpp decodes layers + 1 images, the first being its reconstruction of the input. That frame is dropped, as the diffusers pipeline drops it, so both engines return the same layers; every layer carries its seed. The server's all-or-nothing count check expects the extra images, and the one-shot path collects sd-cli's numbered output files. - The input is resized to the family's 640 canvas at its aspect ratio, the same canvas the diffusers engine decomposes at.
…io/sdcpp-edit-routes
…ly on sd.cpp now)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…io/sdcpp-edit-routes
…tudio/sdcpp-qwen-layered
…tudio/sdcpp-qwen-layered
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d5767beb15
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # ``use_layer3d_rope`` in the base's transformer config, which a GGUF pick reads through ``config=``), and its | ||
| # own RGBA VAE. Its own entry, so the name outranks "qwen-image" in detect_family and the layered keyword | ||
| # guard no longer refuses it. | ||
| name = "qwen-image-layered", |
There was a problem hiding this comment.
Gate Layered on an sd.cpp architecture marker
On hosts with an existing runnable pre-Layered sd.cpp installation, or a custom older SD_CLI_PATH, this family leaves sd_cpp_arch_marker unset. Consequently, sd_cpp_binary_runs_family treats every binary as capable, the router can select the native backend, and an old one-shot binary may be committed as ready before rejecting the architecture or --qwen-image-layers at generation time. Runnable same-accelerator installations are deliberately reused rather than upgraded, so this newly added architecture needs a binary marker like the Qwen-Image-2.1 family to trigger fallback instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8bdac33: the family now sets sd_cpp_arch_marker = "qwen_image_layers". Layered landed upstream in master-744 (556f04b); the pinned sd-cli and sd-server both carry the literal, so an older reused build falls back instead of failing at generation.
| if source_sized and _layer_count(fam): | ||
| # A layered family decomposes at its own canvas, whatever the source's size: resize the source to it, as the | ||
| # layered pipeline does before encoding. | ||
| width, height = _layered_canvas_size(fam, images[0].size) | ||
| if images[0].size != (width, height): | ||
| images[0] = images[0].resize((width, height), Image.LANCZOS) |
There was a problem hiding this comment.
Use the same source aspect ratio on both engines
For source images whose dimensions are not multiples of 16, this computes the native canvas from the original size, while the diffusers path first applies _snap_to_multiple(init_pil, 16) and then calls _layered_canvas. The rounding can materially change the result—for example, a 500×521 input becomes a 608×672 canvas under diffusers but 640×640 here—so selecting a different engine changes the output dimensions and distorts the source differently. Apply the same pre-snap on this path, or exempt Layered from the generic diffusers snap so both use the original ratio.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8bdac33: the native canvas is now picked from the 16 px snapped source, as the diffusers engine does (500x521 -> 608x672 on both), with a test against _layered_canvas(_snap_to_multiple(...)).
| { match: "qwen-image-layered", steps: 20, guidance: 2.5 }, | ||
| { match: "qwen_image_layered", steps: 20, guidance: 2.5 }, |
There was a problem hiding this comment.
Cover the compact Layered alias in generation defaults
When an automatically detected repository or local path uses the supported qwenimagelayered alias declared by this family, neither of these new matches applies, and the generic qwen-image key does not match either. defaultsFor therefore selects the fallback 9 steps and guidance 0 instead of the intended 20/2.5; for a page-initiated load, lastLoad.current prevents the resident-model effect from reseeding those controls afterward. Add the compact alias here, and to the mirrored backend defaults table, so every accepted family spelling receives the same recipe.
Useful? React with 👍 / 👎.
| // Editing families the backend now SUPPORTS: not hidden despite the edit keyword. Mirrors the | ||
| // backend's qwen-image-edit family. | ||
| const SUPPORTED_EDIT_KEYWORDS = ["qwen-image-edit", "kontext"] as const; | ||
| // backend's qwen-image-edit, flux.1-kontext and qwen-image-layered families. | ||
| const SUPPORTED_EDIT_KEYWORDS = ["qwen-image-edit", "kontext", "qwen-image-layered"] as const; |
There was a problem hiding this comment.
Keep the underscore Layered alias visible in the image picker
For a supported repository or local filename using the backend's qwen_image_layered alias, idHasSegment(id, "qwen-image-layered") does not match because the separators inside the keyword differ, while the later standalone layered check does match. isImageEditModel therefore treats this supported family as an unsupported edit model and filters it out of the task-scoped image picker. Include the underscore spelling in the supported set or normalize separators before comparing.
Useful? React with 👍 / 👎.
…ale small sources up to the minimum side
… from the 16 px snapped source like diffusers
…owance and the 20 / 2.5 defaults
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…erage in Backend CI (#12843) #12766 added the VAE seam guard and #12775 / #12777 added the qwen-image-layered family right after it, with no entry in vae_tile_configs.json. The seam guard fails on main: test_every_family_has_a_vae_config, then a KeyError in the geometry check. Add Qwen/Qwen-Image-Layered's vae/config.json at revision 8f0ca708df (the 4-channel RGBA AutoencoderKLQwenImage). With it the full seam guard passes: 27 passed. The coverage check lives in a module that importorskips torch and diffusers, so it only ran in the path-filtered seam-guard job. A dependency-free copy now runs in Backend CI, plus a shape check on each entry.
Stacked on #12775 (Qwen-Image-Layered on the diffusers engine) and #12776 (sd.cpp edit routes, itself on #12755). Merge those first; this PR adds one commit on top of their merge.
Problem
The native sd.cpp engine cannot run Qwen-Image-Layered, although the pinned sd.cpp build (
master-813-bfbef5b-u1d02858) decomposes it from a reference image:'unsloth/Qwen-Image-Layered-GGUF' is not a supported diffusion image model.begin_loadrefuses it:Family 'qwen-image-layered' has no native sd.cpp asset mapping.--output, while sd-cli writes<stem>_0.png ... <stem>_N.pngfor a multi-image result.Change
Asset mapping (
diffusion_families.py,qwen-image-layered)Qwen/Qwen-Image-Layeredvae/diffusion_pytorch_model.safetensors.Comfy-Org/Qwen-Image-Layered_ComfyUI,qwen_image_layered_vae.safetensors), so no community repack is needed.qwen-imageuses. No vision projector: sd.cpp never runs the vision tower for this model (enable_vision = version != VERSION_QWEN_IMAGE_LAYERED).eulerwith flow shift 1.0: the diffusers route's ComfyUI AuraFlow shift, the same schedule formula.Layer count on both transports (
sd_cpp_args.py)SdCppGenParams.qwen_image_layersputs--qwen-image-layers Non the one-shot argv.build_img_gen_request(qwen_image_layers=N)puts the top-levelqwen_image_layersfield in the sd-server body.sd_cli_output_paths()gives sd-cli's file naming for a multi-image run (examples/cli/main.cppsave_results).SdCppEngine.generatechecks the first numbered file instead of--output, which a layered run never writes.Engine (
sd_cpp_backend.py)layer_count(2) is sent as the layer count.batch x (layers + 1)images. The one-shot path collects every numbered file.editonly, an input image is required.Results
B200, Studio's own
SdCppDiffusionBackendin process, on the pinned sd.cpp build.qwen-image-layered-BF16.ggufandqwen-image-layered-Q4_K_M.gguf, with the same input as the diffusers route's proof (object.png, 768x768). Prompt "A product photo of an object on a plain studio background", seed 42, 20 steps, cfg 2.5.f865421355)2f35d5e728)c2a0d16d5f)What this PR sends. Server body
qwen_image_layers: 2,width/height 640, one 640x640ref_imagesentry,txt_cfg 2.5,sample_method euler,flow_shift 1.0. The server returned 3 images and Studio kept the last 2. The one-shot argv carries--ref-image,--qwen-image-layers 2,--width 640 --height 640,--cfg-scale 2.5,--sampling-method euler,--flow-shift 1.0.LPIPS, vgg / alex, each layer composited over gray:
Columns: input, layer 1 and layer 2 over gray, the layers composited. Rows: the diffusers Layered route BF16, this PR BF16, this PR Q4_K_M.
Tests
test_sd_cpp_qwen_layered.py, 8 cases:sd_cli_output_pathsnaming;_layered_canvason four sizes;test_sd_cpp_edit_families.py: the layered-refusal case now expects Qwen-Image-Layered to resolve to its family, and still refuses a FLUX layered or inpaint variant.test_sd_cpp_*.py,test_h3_native_server.py,test_diffusion_backend.py,test_diffusion_engine_router.py,test_cached_gguf_routes.py,test_diffusion_more_families.py,test_diffusion_gated_base.py,test_diffusion_gguf_compile.py,test_diffusion_gguf_offload_route.py,test_native_gguf_companion.py,test_diffusion_unified_edit.py,test_diffusion_qwen_layered.py.test_sd_cpp_qwen_layered.pycannot import on main (sd_cli_output_paths).test_generate_guard_uses_the_hint_the_load_planned_with, reads live free VRAM on a shared GPU.Not covered