ComfyUI-StableLayers

Decompose an image into stacked RGBA layers inside ComfyUI — Stability AI's Stable-Layers adapter on top of Qwen-Image-Layered. Background plus objects, back to front, with the hidden parts painted back in.

View on GitHub →

What it produces

Interior — sofa, table, bouquet

Reproduces Stability's own published grouping for this image: room / sofa / table / bouquet. Layer 0 has the sofa removed and the wall and carpet behind it painted back in.

source
layer 0 — room
layer 1 — sofa
layer 2 — table
layer 3 — bouquet

Flat vector landscape

Flat illustration, four layers: the model separates sky, cliffs and foreground trees even though nothing is photographically distinct.

source
layer 0 — background
layer 1
layer 2
layer 3

Rendered photo — figure with a bag

Background, figure, then the clothing-and-bag group. Each layer carries its own alpha, so any of them can be moved or recoloured independently.

source
layer 0 — street
layer 1 — figure
layer 2 — clothing + bag

The workflow

Drag example_workflows/stable_layers_decompose.json from the repo onto the ComfyUI canvas. Load the diffusion model, apply the adapter, encode the input image as a reference latent for both conditionings, sample into a layered latent, cut the layer axis into a batch, decode, then split and save with alpha intact.

the example workflow running in ComfyUI

Mid-run: per-node timings across the top, the input image on the left, and the four decoded layers previewed in Save Layers (RGBA) on the right — 91 s end to end at 640 px. Click to open full size.

Why a custom node is needed

The keys don't match

PEFT saves tensors as base_model.model.transformer_blocks.0.attn.to_q.lora_A.weight. ComfyUI's QwenImage key map accepts the bare form, transformer. and lycoris — not this one. The stock LoraLoaderModelOnly matches 0 of 840 tensors and silently applies nothing.

The scale is silently halved

PEFT keeps lora_alpha in adapter_config.json; ComfyUI reads it from an .alpha tensor and otherwise assumes alpha = rank. That is scale 1.0 instead of the intended 2.0.

Alpha never reaches disk

Core SaveImage converts to RGB and drops the alpha channel, which makes it useless for a layer stack. This pack writes real RGBA.

A correct load prints 420 patches attached (60 blocks × 7 modules) and no lora key not loaded warnings.

Settings that matter

base Qwen-Image-Layered+ Stable-Layers
samplereulerheun
steps2050
CFG2.51.0
input size640 px640 px max
LoRA strength1.0 shipped; 0.75 keeps one subject in one layer

The adapter's recipe is not the base model's recipe — a non-Heun sampler, fewer steps or a higher resolution garble the output. At full strength the adapter chases its "spread content across layers" reward hard enough to split a lone figure into torso, legs and arms: useful when you want per-limb depth, and what the Merge Layer Range node undoes when you don't.

Speed

ComfyUI's own execution_start → execution_success, RTX 5090, 640 px, 4 layers, one variable at a time.

recipetext encodertime
euler 20 · CFG 2.5GPU44 s
euler 20 · CFG 2.5CPU62 s
euler 20 · CFG 1.0CPU48 s
heun 50 · CFG 1.0CPU95 s
heun 50 · CFG 1.0 + Stable-LayersCPU97 s

The adapter itself costs about two seconds; the recipe is what you pay for. Do not time this from a client — a queue wait or the first 20.5 GB weight load dwarfs the run.