Repository navigation
Studio: send an explicit CFG for every FLUX family on the sd.cpp engine - #12755
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.
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 |
|
Codex Review: Didn't find any major issues. Another round soon, 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". |
Problem
On the native sd.cpp engine, every FLUX family renders at the wrong CFG. FLUX.1-schnell comes out almost black, FLUX.1-dev looks like a burnt cartoon, FLUX.2-dev turns the subject solid red, and FLUX.2-klein is oversharpened. This happens in both server and one-shot mode.
_map_guidancereturnedcfg_scale = Noneforflux.1,flux.2-kleinandflux.2-dev:--cfg-scalewhen it is not None, so it had none;build_img_gen_requestonly writesguidance.txt_cfgwhen it is not None, so the server request had none.The docstring assumed an unset cfg means sd-cli's 1.0. It does not. At the pinned build (
master-813-bfbef5b-u1d02858):sd_sample_params_initsetstxt_cfg = 7.0(src/stable-diffusion.cpp:446). The CLI options and the server defaults both start from it (examples/common/common.cpp:1024,--cfg-scalehelp "default: 7.0" at 1206).examples/server/routes_sdcpp.cpp:358), and the JSON only overridestxt_cfgwhen the key is present (examples/common/common.cpp:2148).resolve_guidancehas no FLUX case (src/pipeline/request.cpp:276-329). The only model whose cfg it forces is MiniMax-H3. Withimg_cfgdefaulting to 1, a cfg of 7 also turns on the unconditional pass (line 313), so every distilled FLUX step ran the model twice.So all FLUX families got real CFG 7. FLUX.1 breaks visibly because it is guidance-distilled. FLUX.2 degrades more quietly (oversaturated, oversharpened), which is why it was easy to miss.
Change
_map_guidance(sd_cpp_backend.py) always returns an explicit cfg for FLUX:guidance_embeds: false; sd.cpp only enables the embedder whenguidance_inweights exist,src/model/diffusion/flux.hpp:125). It now uses the same real-CFG mapping as the other CFG families: 1.0 for 0 or 1, and the value itself above 1.Flux2KleinPipelineas real CFG) gets cfg 5. These match the reference workflows.--guidancevalue it used to send was ignored by this model, so it is no longer sent.No signature changes. The request and argv builders are untouched: None still means unset for the families that rely on it.
Results
B200, Studio's own
SdCppDiffusionBackendon the pinned sd.cpp build, main (6f4d9974dc) against this branch. Same Q4 GGUF, prompt, seed 42, 1024x1024, steps and guidance per model default. Each arm ran in server mode and in forced one-shot mode (sd-server hidden). The control is main's own one-shot sd-cli argv, replayed with only the cfg (and the embedded guidance) set to the reference workflow's values.distilled_guidance 3.5txt_cfg 1.0,distilled_guidance 3.5distilled_guidance 0.0txt_cfg 1.0,distilled_guidance 0.0distilled_guidance 1.0txt_cfg 1.0distilled_guidance 5.0txt_cfg 5.0distilled_guidance 4.0txt_cfg 1.0,distilled_guidance 4.0sample_params.guidance).--guidance <g>; this PR sends--cfg-scale 1 --guidance <g>,--cfg-scale 1(klein) and--cfg-scale 5(klein-base).Columns: reference workflow render of the same GGUF, the sd.cpp control, main, this PR (server mode).
Tests
test_map_guidance_flux_uses_distilled_guidancenow expects(1.0, g)for FLUX.1, Kontext and FLUX.2-dev. It previously assertedcfg is None.test_map_guidance_flux2_klein_distilled_off_base_real_cfg: klein at 1.0 gives cfg 1, at 5.0 gives cfg 5, and no embedded guidance is sent.test_flux_oneshot_argv_sends_explicit_cfgandtest_flux_server_request_sends_txt_cfg, each parametrized over FLUX.1-dev, schnell, Kontext, FLUX.2-dev, klein 4B / 9B and klein-base 4B / 9B at Studio's own default guidance for that repo. They rungenerateand check the built sd-cli argv (--cfg-scale,--guidance) and the server body (txt_cfg,distilled_guidance).test_sd_cpp_*.py+test_h3_native_server.py, 1040 passed, 1 skipped.Not covered