comfy-cfg-megapack Introduction
comfy-cfg-megapack is a collection of ComfyUI nodes for exploring classifier-free guidance (CFG): the process that steers an image toward your prompt during generation. It gives you ways to change when that steering happens, how it works, and where it has the strongest effect.
The pack offers two ways to work:
- Stage nodes let you adjust one part of guidance at a time. You can change its timing, its effect on fine detail, or its final strength while keeping the rest of your workflow the same.
- 50 method nodes implement published guidance approaches, including APG, CFG-Zero*, PAG, SEG, Perp-Neg, FDG, and Guidance Interval. Each has settings associated with its method.
This makes the pack useful when a high CFG value follows your prompt but produces harsh colors, when you want to sharpen detail without pushing the whole image equally, or when you want to compare guidance methods using the same prompt and seed.
The nodes support SDXL, SD1.5 through the same UNet hooks as SDXL, and Anima and other supported Cosmos-Predict2 flow-matching transformers. Not every weak-branch method is available for every architecture; the model-specific differences are explained below.
APG compared with plain CFG at scale 14
How comfy-cfg-megapack Works
Imagine that, at each sampling step, the image model offers two suggestions: one informed by your prompt and one without it. Ordinary CFG looks at the difference between those suggestions and uses the CFG scale to push the result toward the prompt. A stronger push can improve prompt adherence, but it can also exaggerate colors or other features.
comfy-cfg-megapack separates that decision into seven stages. Think of them as controls on the same steering system:
| Stage | The question it answers | What you might change |
|---|---|---|
| When | At which steps should guidance act? | Use stronger guidance early, late, or only within a window. |
| Weak branch | Is there another model prediction to steer away from? | Compare the normal prediction with one made using altered self-attention. |
| Combine | How should the predictions be mixed? | Replace ordinary CFG with a different guidance rule. |
| Where | Which parts of the prediction need more guidance? | Treat coarse structure and fine detail differently, or use a region mask. |
| Correct | Has guidance made the result too strong? | Pull its magnitude back toward the prompt-conditioned prediction. |
| Govern | Has the result moved too far in direction? | Keep its angle relative to a reference prediction within a chosen band. |
| Measure | What happened during sampling? | Record per-step scale, sizes, and angles for inspection. |
The stages run in that order, regardless of the order in which you connect their nodes between the model loader and sampler. If you add two nodes for the same stage, the later node replaces the earlier one; corrections are the exception and stack in order. A method node can occupy a stage too, so you can combine a published method with other stage controls.
For a first comparison, open Workflow > Browse Templates > Custom Nodes > comfy-cfg-megapack, or load an example from example_workflows/. Each example renders plain CFG and a variant from the same seed. A minimal chain is:
Load Checkpoint → CFG Megapack node → KSampler
The node modifies the MODEL connection. The sampler’s cfg value supplies the guidance scale unless the chosen node sets its own. Keep the seed, prompt, model, and other sampling settings fixed when comparing methods so that the guidance change is easier to see.
comfy-cfg-megapack Features
Stage controls
- CFG When: Schedule and Window changes the scale over the sampling run or limits guidance to selected steps. Try it when you want guidance to shape the initial composition differently from the finishing details.
- CFG Weak Branch: Perturbed Self-Attention makes an additional prediction with altered self-attention and steers away from it. The available alteration depends on your model architecture.
- CFG Mix: Scale Rules, Direction Rules, Pentachoron offers different ways to combine predictions. These are alternatives to changing the sampler’s CFG number alone; see HOWTO.md for each control.
- CFG Where: Frequency Bands, Region Mask varies guidance by coarse versus fine image information, or by masked versus unmasked area. For example, you can experiment with preserving broad color and layout while guiding detail more strongly.
- CFG Correct: Magnitude adjusts the size of the guided result toward the prompt-conditioned prediction. It is relevant when strong guidance produces an overdone appearance.
- CFG Govern: Angle Band limits how far the guided result turns away from its chosen reference: the prompt-conditioned or unconditional prediction. You can apply it to the whole image, each pixel’s channel vector, or each channel. The full 0–180° band leaves the result unchanged; a narrower band constrains direction.
- CFG Measure: Per-Step Probe writes step-by-step measurements to
output/cfg_probe/. Use it when you want to inspect how scale, prediction sizes, or angles changed during a run.
CFG Plan Readout shows the guidance plan currently attached to a model, and CFG Clear Plan removes it. CFG Guider: Positive, Negative and Null is for SamplerCustomAdvanced workflows that need to keep the negative prompt separate from a truly empty, or null, prompt.
The author also includes CFG Mix: Pentachoron and CFG Govern: Angle Band as in-house directions. The former transforms each pixel’s CFG push using groups of four latent channels; the latter acts only when a prediction leaves its chosen angle band. Their background is linked to AlephLLM and amoe-lora. You do not need to understand that research to use the nodes: start from a comparison workflow and change one setting at a time.
Published and community methods
The 50 method nodes are organized in CFG Megapack > papers by what they change. The table below is a choosing guide, not a claim that one method is best for every image. Each node has its own settings and defaults; HOWTO.md provides the individual node descriptions and controls.
| Research line | Nodes | What to explore |
|---|---|---|
| Combining predictions | CFG; Guidance Rescale; Dynamic Thresholding; Mimic-Scale Thresholding; APG; CFG-Zero*; TCFG; beta-CFG; ADG; Power-Law CFG; EP-CFG; CFG-Renorm; CFGNorm; MAMBO-G; Skimmed CFG; Automatic CFG; Mahiro; Reinhard tonemap; SMC-CFG; PMC-CFG; AdaMaG; FBG; VAGS; CFG-OEC; HiGS; TSR; Epsilon Scaling | Alternatives to ordinary CFG’s mixing rule. Several address excessive magnitude, color, or guidance strength; others change direction, adapt to the current step, or use earlier steps. |
| When to guide | Adaptive Guidance; Transition-Point Guidance; Guidance Interval; Increasing guidance schedules; TV-CFG; C2FG; Early-high, late-unconditional; CFG Truncation | Move, increase, reduce, or stop guidance during different portions of sampling. |
| Weak branch | PAG; SEG; STG attention skip | Add a prediction made with altered self-attention, then steer away from it. These methods require an extra model pass. |
| Negative prompts | Perp-Neg Guider; Composable NOT Guider; Signed guidance; ContrastiveCFG Guider; Safe Latent Diffusion Guider; Windowed negative prompt | Change how a negative concept affects the image, including its direction, strength, or timing. These are guider nodes. |
| Frequency and space | SAMG; FDG; FreSca; HiWave; LF-CFG; ZeResFDG | Apply different guidance to pixels, coarse structure, or fine detail. |
Some useful starting points:
- Colors become too intense at high CFG: Compare APG, Guidance Rescale, Mimic-Scale Thresholding, or FDG with plain CFG.
- You want different behavior at different steps: Try Guidance Interval, Increasing guidance schedules, or CFG When.
- A negative prompt removes something you wanted to keep: Explore Perp-Neg Guider and the other negative-prompt guiders.
- You want to change detail without pushing broad color and layout as hard: Compare FDG, HiWave, or CFG Where: Frequency Bands.
These are experiment ideas, not guaranteed outcomes. The included SDXL and Anima comparisons in HOWTO.md show methods alongside plain CFG; the full comparison graphs are in docs/showcase/ and can be loaded through Workflow > Open.
comfy-cfg-megapack Models
The pack does not provide image-generation checkpoints. Its nodes modify guidance while you sample with a compatible model.
| Model family | Support and considerations |
|---|---|
| SDXL | Tested with SDXL base 1.0. The readme’s SDXL method comparisons use 1024 × 1024 images and a consistent prompt and seed. |
| SD1.5 | Uses the same UNet hooks as SDXL. |
| Anima and supported Cosmos-Predict2 transformers | Uses a different flow-matching prediction format and 16-channel latents. Anima base 1.0 was tested; the pack accounts for its timestep shift. For its transformer blocks, use SEG or attention skip as weak-branch alternatives to PAG. |
A method may therefore produce a different-looking comparison on SDXL and Anima, even with similar settings. The HOWTO.md comparisons include all paper nodes on SDXL and a selection on Anima.
Troubleshooting comfy-cfg-megapack
A node gives an error when I use PAG with Anima
- Check whether your workflow uses the PAG method node with Anima.
- Replace PAG with SEG or STG attention skip, which are supported weak-branch options for Anima’s transformer blocks.
- Run the workflow again, keeping the other settings fixed for a clear comparison.
My second guidance node seems to undo the first
- Use CFG Plan Readout to inspect the plan on the model connected to your sampler.
- Check whether both nodes control the same stage. In that case, the later node replaces the earlier one.
- Keep the node whose rule you want active, or combine nodes from different stages. Magnitude corrections are an exception: they stack in order.
Another pack’s CFG node does not combine as expected
- Check whether you have connected a CFG-function node such as RescaleCFG, Mahiro, or RenormCFG alongside this pack.
- These nodes share ComfyUI’s single CFG-function slot; the one chained last wins.
- Test each configuration separately to identify which rule is active. Pre- and post-CFG nodes can compose with the pack, but the shared CFG-function slot cannot hold two winning rules at once.
Two runs that should match are slightly different
Keep the model, seed, prompt, sampler, steps, and other settings identical. For a pixel-exact A/B comparison, the author advises queueing one run with another seed first after loading the model: ComfyUI’s first sampling pass after a model load can round slightly differently from later passes. Some rules that work in noise or velocity space can also introduce small rounding differences, particularly on Anima.
Frequently asked questions
Do I need to use all seven stages?
No. You can place a single CFG Megapack node between the model loader and sampler, then add others only when you have a specific change to test.
Does changing node order change the seven-stage processing order?
No. The stages run in their defined order. Chain order matters when a later node replaces an earlier rule for the same stage, and for corrections that stack.
Where does the CFG scale come from?
Usually from the sampler’s cfg setting. A node that sets its own scale is an exception.
Can I see what the nodes are doing during a run?
Yes. CFG Plan Readout displays the attached plan, while CFG Measure: Per-Step Probe writes measurements to output/cfg_probe/.
Will every method work with every model?
The author reports default runs for all 50 paper nodes on the tested SDXL and Anima models except PAG on Anima. Model architecture matters most for methods that alter self-attention; use SEG or attention skip there.
Learn More about comfy-cfg-megapack
- HOWTO.md is the main guide to every node, its settings, and the comparison workflows. Start here when you want to understand a control before changing it.
example_workflows/contains paired plain-CFG and variant examples using the same seed.docs/showcase/contains the full graphs for the documented image comparisons. Open a graph in ComfyUI with Workflow > Open.- The research catalog groups guidance methods by what they change and identifies methods that have a node, are planned, or are outside the pack’s sampler scope.
- The project repository and Comfy Registry listing identify the pack and its available project materials.
The roadmap in the original documentation describes further weak-model, negative-guidance, and sampler methods as planned. They are not part of the 50 method nodes described here.
