Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
yiyixuxu merged 2 commits into
huggingface:mainfrom
akshan-main:fix-flux-cfg
Jun 16, 2026
Merged

fix(flux): enable true CFG with precomputed negative embeds#13957
yiyixuxu merged 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.

@yiyixuxu yiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yiyixuxu yiyixuxu merged commit 9408331 into huggingface:main Jun 16, 2026
14 of 15 checks passed
DN6 pushed a commit that referenced this pull request Jul 1, 2026
* fix(flux): enable true CFG with precomputed negative embeds in img2img/inpaint/controlnet

* test(flux): cover true CFG via precomputed negative embeds
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.

3 participants