Skip to content

fix(flux): enable true CFG with precomputed negative embeds#13957

Open
akshan-main wants to merge 2 commits into
huggingface:mainfrom
akshan-main:fix-flux-cfg
Open

fix(flux): enable true CFG with precomputed negative embeds#13957
akshan-main wants to merge 2 commits into
huggingface:mainfrom
akshan-main:fix-flux-cfg

Conversation

@akshan-main

@akshan-main akshan-main commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Addresses the flux review (#13584), Issue 2: FluxImg2ImgPipeline, FluxInpaintPipeline, and FluxControlNetPipeline gated true CFG on true_cfg_scale > 1 and negative_prompt is not None, so passing precomputed negative_prompt_embeds / negative_pooled_prompt_embeds (with negative_prompt=None) silently did not enable CFG.

Base FluxPipeline (and FluxKontextPipeline) already handle this correctly:

has_neg_prompt = negative_prompt is not None or (
    negative_prompt_embeds is not None and negative_pooled_prompt_embeds is not None
)
do_true_cfg = true_cfg_scale > 1 and has_neg_prompt

This brings the three pipelines in line. The downstream if do_true_cfg: block already forwards the precomputed embeds through encode_prompt, so only the gate needed fixing. Verified the gate flips False -> True for the precomputed-embeds case and copies/ruff stay clean.

Before submitting

Who can review?

@hlky @sayakpaul @yiyixuxu

@github-actions github-actions Bot added pipelines size/S PR with diff < 50 LOC labels Jun 14, 2026
@github-actions github-actions Bot added the tests label Jun 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @akshan-main, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/S PR with diff < 50 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant