Skip to content

refactor: img-cond->img_uncond#1594

Merged
leejet merged 4 commits into
leejet:masterfrom
stduhpf:2-cond
Jun 3, 2026
Merged

refactor: img-cond->img_uncond#1594
leejet merged 4 commits into
leejet:masterfrom
stduhpf:2-cond

Conversation

@stduhpf
Copy link
Copy Markdown
Contributor

@stduhpf stduhpf commented Jun 1, 2026

Summary

Re-implement some changes that were dropped from #929

  • Optimizes inference speed with --img-cfg-scale 1
  • Fixes inconsistency with the way kontext refs and concat refs are handled

Before this change the conditionning were:

  • cond: positive prompt, concat, kontext refs
  • uncond: negative prompt, no concat, kontext refs
  • img_cond: negative prompt, concat, no kontext refs

With this PR, they become:

  • cond: positive prompt, concat, kontext refs
  • uncond: negative prompt, concat, kontext refs
  • img_uncond: negative prompt, no concat, no kontext refs

In a way it's just swapping the roles of uncond and img_(un)cond for inpaint / unet edit models.

Related Issue / Discussion

N/A

Additional Information

Checklist

@stduhpf
Copy link
Copy Markdown
Contributor Author

stduhpf commented Jun 2, 2026

Alternatively I could just revert the name changes and just include the optimisations, but this naming makes more sense to me.

@leejet
Copy link
Copy Markdown
Owner

leejet commented Jun 2, 2026

I think there are some issues with the PR implementation, which may degrade editing quality.

.\bin\Release\sd-cli.exe --diffusion-model  ..\..\ComfyUI\models\diffusion_models\flux-2-klein-base-4b.safetensors --vae ..\..\ComfyUI\models\vae\flux2_ae.safetensors  --llm ..\..\ComfyUI\models\text_encoders\qwen_3_4b.safetensors -r ..\assets\flux\flux1-dev-q8_0.png -p "change 'flux.cpp' to 'klein.cpp'" --cfg-scale 4.0 --sampling-method euler -v --diffusion-fa --offload-to-cpu

PR:
output

Master:

output

@stduhpf
Copy link
Copy Markdown
Contributor Author

stduhpf commented Jun 2, 2026

I think there are some issues with the PR implementation, which may degrade editing quality.

.\bin\Release\sd-cli.exe --diffusion-model  ..\..\ComfyUI\models\diffusion_models\flux-2-klein-base-4b.safetensors --vae ..\..\ComfyUI\models\vae\flux2_ae.safetensors  --llm ..\..\ComfyUI\models\text_encoders\qwen_3_4b.safetensors -r ..\assets\flux\flux1-dev-q8_0.png -p "change 'flux.cpp' to 'klein.cpp'" --cfg-scale 4.0 --sampling-method euler -v --diffusion-fa --offload-to-cpu

PR: output

Master:

output

What if you set --img-cfg-scale 1?

@leejet
Copy link
Copy Markdown
Owner

leejet commented Jun 2, 2026

I don’t think this PR should change the default behavior.

@stduhpf
Copy link
Copy Markdown
Contributor Author

stduhpf commented Jun 2, 2026

@leejet I think the default img cfg scale should always be 1.

I know it has been set to = txt-cfg for a while, but this is not right. As I shown in this comment: #929 (comment), or in your exemple, higher img cfg scale can cause issues at a higher degree than higher txt cfg. (apg can help handle it but that's besides the point)

The results with edit models are changed from current Master, because there is a discrepency between the way kontext-like ref images and concat latents are handled with img cfg (forgot to mention that in the PR summary)

Master:

  • uncond: negative prompt, no concat, kontext refs
  • img_cond: negative prompt, concat, no kontext refs

PR:

  • uncond: negative prompt, concat, kontext refs
  • img_uncond: negative prompt, no concat, no kontext refs

@leejet leejet merged commit 4513e3f into leejet:master Jun 3, 2026
14 checks passed
@leejet
Copy link
Copy Markdown
Owner

leejet commented Jun 3, 2026

I’ve set the default image CFG to 1.f, and everything looks OK now. Thanks for your contribution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants