Repository navigation
Studio: route Qwen-Image-Edit / Edit-2509 / Edit-2511 and FLUX.1-Kontext GGUFs to the native sd.cpp engine - #12776
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.
…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. |
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: c75709f8e6
ℹ️ 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".
| "Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf", | ||
| "qwen2vl", | ||
| ), | ||
| ("unsloth/Qwen2.5-VL-7B-Instruct-GGUF", "mmproj-F16.gguf", "llm_vision"), |
There was a problem hiding this comment.
Require the projector when loading edit-only models offline
When a non-user-initiated/cache-only load has the Qwen edit GGUF, VAE, and text encoder cached but lacks mmproj-F16.gguf, the existing _fetch_assets logic silently skips every missing llm_vision asset because that was optional for Qwen-Image-2.1 text-to-image. For this newly mapped family the projector is mandatory and status() consequently exposes no workflows, so the load reports success but every generation is unusable. Make this projector optional only for families that retain a non-edit workflow, or fail this edit-only load with the existing actionable cache error.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 243d9aa: a cache-only load of an edit-only family now fails when its projector is missing, instead of loading with no workflows. Qwen-Image-2.1 keeps skipping it.
| # An edit-only family (Kontext, Qwen-Image-Edit) has no text-to-image mode: an input image | ||
| # with no explicit workflow is an edit, as on the diffusers engine. Re-checked against the | ||
| # state this call actually runs on below. | ||
| loaded = self._state |
There was a problem hiding this comment.
Infer the implicit edit workflow from the locked state
When a generation waits behind another generation while a model load commits, this unlocked read can inspect the old family while the later code runs against the replacement state. Local/unmanaged callers do not supply expected_load, so a request with an input image can either be rejected as unsupported after a text-to-image model is replaced by an edit model, or retain an inferred edit workflow after the opposite replacement. Derive workflow and conditioned after acquiring the generation/state locks, from the same state used for the run.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: both swap directions end in a refusal (the init-image refusal for a txt2img model, or 'Image editing is not available' via _native_edit_ready under the lock), never a wrong render, and the Studio route passes expected_load for exactly this window (#9448).
| width = max(multiple, int(round(sw * fit / multiple)) * multiple) | ||
| height = max(multiple, int(round(sh * fit / multiple)) * multiple) |
There was a problem hiding this comment.
Preserve support for source images below 256 pixels
For an edit source whose snapped width or height is below 256 (for example the 64×64 input already accepted by the diffusers Qwen-Image-Edit path), these calculations leave that side below 256 and the subsequent check_output_size rejects the request. Since edit-only models ignore the requested width and height, callers cannot select a valid output size as a workaround, making small icons and narrow images work on diffusers but fail on the newly routed native engine. Source-sized edits should either follow the diffusers path without applying the text-to-image minimum or resize to a valid minimum.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 243d9aa: a source-sized edit now scales a source below 256 px up to the minimum side (aspect kept), so it renders like on the diffusers engine instead of being refused.
| if getattr(state.family, "edit", False): | ||
| # Edit-only families have no text-to-image mode, so only "edit", as on the diffusers engine. | ||
| workflows = ["edit"] if self._native_edit_ready(state) else [] |
There was a problem hiding this comment.
Keep alpha disabled for RGB edit-only families
On a newer/custom sd.cpp binary carrying _REFERENCE_FIDELITY_MARKER, this new edit-only status path still reaches the unconditional conditioning["alpha"] = full_fidelity override below, so Kontext and Qwen-Image-Edit advertise alpha support even though both families decode their source in RGB and return RGB output. A client relying on the capability can therefore submit transparency expecting it to be preserved while it is flattened; retain conditioning_capabilities()'s family-derived False value for edit-only RGB families and apply the build-level override only to RGBA-capable unified editing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the pinned build does not carry the fidelity marker, so alpha is False for these families on every shipped install; the advertised flag only moves on a custom newer binary, and the output stays RGB either way.
…ale small sources up to the minimum side
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
Stacked on #12755 (explicit FLUX cfg on sd.cpp): merge that first. One extra commit here gives #12755's two Kontext cfg tests a source image, since Kontext is edit-only on this engine now.
Problem
The native sd.cpp engine refuses every instruction-editing GGUF: Qwen-Image-Edit, Qwen-Image-Edit-2509, Qwen-Image-Edit-2511 and FLUX.1-Kontext-dev. On main, a load fails before any download with:
begin_load(sd_cpp_backend.py:2660) and the engine router (diffusion_engine_router.py:337,:532) both gate onfamily_sd_cpp_supported. That only checkssd_cpp_vaeandsd_cpp_text_encoders, and theqwen-image-editandflux.1-kontextentries indiffusion_families.pyset neither.master-813-bfbef5b-u1d02858) runs all four models. They take the source image as a reference image (-r/ref_images): sd.cppdocs/qwen_image_edit.md,docs/kontext.md,docs/edit.md.generate()refused any input image without an explicit workflow,_native_edit_readyrequiredunified_edit, andstatus()advertisedtxt2imgeven for a model that cannot do text-to-image.Change
Asset mapping (
diffusion_families.py)qwen-image-edit(one entry covers the original, 2509 and 2511):--qwen2vl), the same files theqwen-imageroute already fetches.mmproj-F16.gguffrom the same repo (--llm_vision). All three checkpoints read the source through the VLM, and a GGUF encoder has no vision weights of its own.euler, flow shift 3: the documented sd.cpp invocation, the same asqwen-image.--model-args qwen_image_zero_cond_t=true. sd.cpp enables it from the__index_timestep_zero__tensor the GGUF carries (qwen_image.hpp:37). Checked on the public Q4_K_M:qwen_image: num_layers = 60, zero_cond_t = true.flux.1-kontext: the FLUX.1 VAE and the CLIP-L + T5-XXL pair, the same files asflux.1.Guidance (
_map_guidance)true_cfg_scale.Edit-only workflow (
sd_cpp_backend.py), matching the diffusers engine:--ref-image(one-shot) orref_imagesentry (server)._snap_to_multiplerounding), and the source is resized to it. A source larger than the family's bounds is scaled down to fit, not refused.status()advertises onlyedit, as_family_workflowsdoes for these families._native_edit_readyaccepts an edit-only family when its projector is loaded (when it declares one). The Qwen-Image-2.1 unified gate is unchanged.sd_cpp_args._TE_FLAGS_BY_FAMILYgains both families. No signature changes; other families' argv, request body and workflows are unchanged.Results
B200, Studio's own
SdCppDiffusionBackendin process, on the pinned sd.cpp build. main (f865421355) against this branch.txt_cfg 2.5, euler, shift 3, 1 ref 768x768txt_cfg 1.0,distilled_guidance 2.5, 1 ref 768x768begin_loadwith theno native sd.cpp asset mappingerror above. On this branch,status()["workflows"]is["edit"]for all four, and every output is 768x768: the source size, as on the diffusers engine.--ref-image,--width 768 --height 768, and for Kontext--cfg-scale 1 --guidance 2.5; for 2511--cfg-scale 2.5 --sampling-method euler --flow-shift 3.0,--qwen2vland--llm_vision.Columns: input, the campaign's sd-cli direct BF16 render (1024 px), Studio's diffusers GGUF route BF16 render from the same campaign (768 px), this PR BF16, this PR Q4_K_M.
Tests
test_sd_cpp_edit_families.py, 23 cases:black-forest-labs/FLUX.1-schnell; layered and inpaint variants are still refused.(1.0, g); Qwen edit gives real CFG.editis advertised; Qwen edit without its projector is not edit-ready.--ref-image, the source size, cfg / guidance, the encoders, the projector and the flow shift.data:image/png;base64ref image at the source size,txt_cfg/distilled_guidance, sampler and shift, and no img2img keys._snap_to_multiple, and an oversized source is fitted. The diffusers engine's refusals hold, a text-to-image family still refuses an input image, and the Qwen-Image-2.1 unified gate is unchanged.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.pyandtest_diffusion_unified_edit.py.test_generate_guard_uses_the_hint_the_load_planned_with, fails the same way on main. It reads live free VRAM on a shared GPU (ImageActivationShortfallError).studio/sdcpp-flux-cfg), the two merge without conflicts. That PR's two Kontext cases intest_flux_oneshot_argv_sends_explicit_cfg/test_flux_server_request_sends_txt_cfgcallgenerate()without an input image, which Kontext now refuses as it does on diffusers. Whichever lands second gives the Kontext case a source image (a three-line test change); with it the merged tree passestest_sd_cpp_backend.py+test_sd_cpp_edit_families.py, 155 passed.Not covered