Repository navigation
Studio: Qwen-Image-Layered on the diffusers engine, GGUF included - #12775
Conversation
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.
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. |
|
@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: e3af2c0c13
ℹ️ 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".
| // 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.
Whitelist the underscore alias in the picker
For a Hub repository named with the newly supported qwen_image_layered alias, none of these supported tokens matches, but the generic layered segment does. Consequently isImageEditModel() returns true and the Images picker hides a model that backend detection explicitly accepts; include the underscore spelling or normalize separators before applying the edit-model exclusion.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 542a09e: the picker's supported list now carries every spelling the backend accepts (qwen-image-layered, qwen_image_layered, qwenimagelayered).
| { 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.
Apply layered defaults to the compact alias
The family registry also accepts qwenimagelayered, but this defaults table only covers the hyphenated and underscored spellings. Selecting a repository with that compact alias therefore seeds the Studio controls with the fallback 9 steps and guidance 0 rather than the intended 20/2.5 recipe, which can materially degrade the decomposition; add the compact alias here and to the matching backend defaults table.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 542a09e: qwenimagelayered added to both the frontend and backend defaults tables, with tests covering each spelling.
…owance and the 20 / 2.5 defaults
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 542a09e5a2
ℹ️ 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".
| const SUPPORTED_EDIT_KEYWORDS = [ | ||
| "qwen-image-edit", | ||
| "kontext", | ||
| "qwen-image-layered", |
There was a problem hiding this comment.
Keep unsupported layered variants out of the picker
For an ID such as org/Qwen-Image-Layered-Inpaint, this newly whitelisted token makes isImageEditModel() return false immediately, so the Images picker exposes the model despite the additional reserved inpaint segment. Backend detect_family() checks every _EDIT_KEYWORDS segment against the matched family and rejects this same ID, leaving users with a selectable model that cannot load. Only bypass the exclusion when all reserved variant segments are supported by the matched family rather than when any supported token is present.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: no such repo exists, and the allowlist has the same shape for the shipped qwen-image-edit and kontext entries; a hypothetical layered-inpaint id is outside the families this PR adds.
| # ComfyUI's Image to Layers template: ModelSamplingAuraFlow 1, 2 layers, the input scaled to 640. | ||
| comfy_flow_shift = 1.0, | ||
| layer_count = 2, | ||
| layer_resolution = 640, |
There was a problem hiding this comment.
Expose the layered canvas instead of claiming source-sized output
For every Qwen-Image-Layered generation, the pipeline derives a fixed approximately 640² canvas from the source aspect ratio, not from the source's pixel dimensions. Because the family is exposed only as a generic edit workflow and layer_resolution is not included in the status capabilities, the Images page instead tells users that output size comes from the source and that uploading a smaller image will reduce it; neither is true for this family. Surface the fixed bucket/decomposition behavior so the UI can report the actual output sizing and an actionable memory remedy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this here: it is copy on the Images page, not a wrong render; the decomposition still runs at the pipeline's own canvas and returns correct layers.
| if layer_count: | ||
| # Every decomposition denoises layers + 1 frames beside the encoded input, all at the canvas | ||
| # size: the frames past the first are extra tokens on top of the output-sized one. | ||
| guard_condition_pixels += (layer_count + 1) * guard_width * guard_height |
There was a problem hiding this comment.
Reserve layered frames when choosing the load placement
On cards where this large model needs weight offloading, load-time placement still reserves the generic single-frame 1024² headroom (about 8 GiB), while this generation-time calculation charges four 640² frames for the two-layer configuration (about 12.8 GiB). Qwen-Image-Layered has no calibrated placement entry, so measured_request_extra_mib() returns zero and cannot release additional resident groups; the subsequent activation guard can therefore reject every render after a successful default load even though offloading roughly another 5 GiB of weights would make it runnable. Include the family's fixed layer/canvas cost in load planning, including the unified-memory preflight.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 66c6311: the planning estimate for a qwen-image-layered load now reserves the decomposition's footprint (640 canvas, output + input + layers frames), so planned equals what the guard charges (12800 MiB both) and an offloaded load no longer refuses its default render. Load planning, the unified preflight and the guard's planned figure share that estimator; other families unchanged.
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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.
Problem
Studio refuses every Qwen-Image-Layered checkpoint on the diffusers engine, including the public
unsloth/Qwen-Image-Layered-GGUFBF16 file:There was no family for it at all, GGUF or full repo:
detect_family(diffusion_families.py) matchesqwen-imagefor aqwen-image-layeredid, then_EDIT_KEYWORDS = ("edit", "kontext", "inpaint", "layered")rejects it, becauselayeredis not in the qwen-image tokens. The tests asserted that refusal (test_detect_family_rejects_layered).family_override="qwen-image"would have loadedQwenImagePipeline, which cannot run this transformer.Adding the family exposed a second bug on the GGUF route. The public GGUFs store
time_text_embed.addition_t_embedding(annn.Embedding(2, 3072)) in BF16. diffusers' GGUF quantizer only dequantises inside thenn.Linearlayers it swaps forGGUFLinear, and BF16 stays packed (numpy has no bf16). The embedding therefore returns raw bytes, and the first step dies withThe size of tensor a (3072) must match the size of tensor b (6144). The BF16 and UD-Q4_K_XL files both hit it.Change
qwen-image-layeredfamily (diffusion_families.py):QwenImageLayeredPipeline+QwenImageTransformer2DModel, baseQwen/Qwen-Image-Layered. A GGUF pick reads the transformer config from the base throughconfig=, which is whereuse_additional_t_cond/use_layer3d_ropecome from. The RGBA VAE also comes from the base.edit=True: an input image is required and the only workflow isedit, as for Kontext and Qwen-Image-Edit.condition_image_mode="RGBA", because the layered VAE encodes 4 channels.true_cfg_scale), ModelSamplingAuraFlow shift 1 (comfy_flow_shift=1.0), 2 layers, input scaled to 640.layer_count(2) andlayer_resolution(640). Every other family haslayer_count=0.qwen-imageindetect_family.layeredstays in_EDIT_KEYWORDS, so a layered variant of any other family is still refused.diffusion.py, only whenlayer_countis set):layersandresolution._dequantize_gguf_outside_linears(diffusion.py): after a GGUF transformer load, any GGUF-packed parameter outside aGGUFLinearis dequantised to the compute dtype. These are embedding tables and norms, a few KB.qwen-image-layeredwhosemodel_index.jsondeclares a plainQwenImagePipelinestays refused in both the picker listing (catalog_classification._local_model_task) and the loader (detect_family_for_pick). Without this, the name would now route it to the layered pipeline. A real savedQwenImageLayeredPipelineresolves from its index._TRUSTED_NON_GGUF_REPOSgainsqwen/qwen-image-layered._PIPELINE_MIN_DIFFUSERSgainsQwenImageLayeredPipeline: 0.37.0. It is absent from the 0.36.0 wheel'sdiffusers/__init__.pyand exported by 0.37.0's.sd_cpp_*fields are left empty, so the native engine still refuses it. That route is separate work.Results
B200, Studio's in-process
DiffusionBackendon the pickunsloth/Qwen-Image-Layered-GGUF, main (f865421355) against this branch. Same input (object.png, 768 x 768 RGB), prompt "A product photo of an object on a plain studio background", seed 42, 20 steps, guidance 2.5,speed_mode=off,text_encoder_quant=none. BF16 is the public file through Studio's own resolver. UD-Q4_K_XL is the repacked public-candidate file.LPIPS, each layer alpha-composited over mid-gray, plus the composite of all layers over gray:
dequantised 1 non-linear parameter(s): time_text_embed.addition_t_embedding.weightfor both files.Rows: this PR BF16, this PR UD-Q4_K_XL, reference workflow BF16. Columns: input, layer 1 over gray, layer 2 over gray, composite.
Tests
test_diffusion_qwen_layered.py, 16 tests:config="Qwen/Qwen-Image-Layered",subfolder="transformer";generate(), against a double with the pipeline's own signature:layers,resolution,true_cfg_scale, empty negative, RGBA input with its alpha, and two RGBA outputs with seeds[7, 7];_dequantize_gguf_outside_linearson a BF16-packed embedding beside aGGUFLinear.test_diffusion_qwen_layered.py+test_diffusion_backend.py+test_cached_gguf_routes.py+test_diffusion_gguf_compile.py+test_diffusion_gguf_offload_route.py+test_gguf_route_cursor_reset.py+test_diffusion_unified_edit.py+test_diffusion_flow_shift.py+test_diffusion_auto_policy.py+test_diffusion_precision.py+test_diffusion_transformer_quant.py:test_pipeline_class_guard_passes_every_shipped_family, the same one main has (Qwen-Image-2.1 needs diffusers 0.41).test_diffusion_*.py,test_sd_cpp_*.py,*famil*andtest_images*file (168 files): the failing test IDs on this branch are a subset of main's on the same interpreter. No new failures.Not covered
Qwen/Qwen-Image-Layeredrepo load (non-GGUF) is unit-tested only; its 41 GB transformer was not downloaded.speed_mode=offonly (no compiled path), on B200 only.UI before / after
Images page model picker, searching "Qwen-Image-Layered" (base
192554deevs this branch). Before, the picker hid every layered repo as an unsupported edit model; now the GGUF is listed.