Skip to content

Instantly share code, notes, and snippets.

@linoytsaban
Last active December 9, 2024 06:26
Show Gist options
  • Save linoytsaban/aec23eee5cc168726f594c04413ead7a to your computer and use it in GitHub Desktop.
Save linoytsaban/aec23eee5cc168726f594c04413ead7a to your computer and use it in GitHub Desktop.
Flux with CFG and negative prompts
# download FluxCFGPipline
!wget https://raw.githubusercontent.com/linoytsaban/diffusers/refs/heads/dreambooth-lora-flux-exploration/examples/community/pipeline_flux_with_cfg.py
# load pipeline
import diffusers
import torch
from pipeline_flux_with_cfg import FluxCFGPipeline
pipe = FluxCFGPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
### original output, w/o cfg
prompt = "an impressionist painting of a magnificant macaron"
torch.manual_seed(0)
pipe(prompt).images[0].resize((512,512))
### with cfg (true_cfg > 1) and empty negative prompt
prompt = "an impressionist painting of a magnificant macaron"
negative_prompt = ""
torch.manual_seed(0)
pipe(prompt=prompt, negative_prompt=negative_prompt, true_cfg=3, guidance_scale=1).images[0].resize((512,512))
### with cfg (true_cfg > 1) and negative prompt
prompt = "an impressionist painting of a magnificant macaron"
negative_prompt = "photo, photorealistic"
torch.manual_seed(0)
pipe(prompt=prompt, negative_prompt=negative_prompt, true_cfg=4, guidance_scale=1).images[0].resize((512,512))
@linoytsaban
Copy link
Author

output examples:
Group 2-15

@linoytsaban
Copy link
Author

Thanks @remixer-dec! updated the link to be the right one :)

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