CFG Mix: Direction Rules
APG, TCFG, the angle cap and Mahiro
- model
- MODEL
If you only install one node from this pack to see what the fuss is about, this is the one. CFG Mix: Direction Rules is a single node that implements four published ways of changing the direction of the guidance rather than its length, behind a dropdown. It's the closest thing here to an A/B test rig.
The four rules
apg(default) - APG, Sadat et al. ICLR 2025. Splits the guidance difference into the part that lies along the conditional prediction and the rest. The rest keeps its strength; the along-conditional part is scaled byeta, the difference's norm is capped atnorm_threshold, and a reverse momentum term carries between steps. This is the pack's high-cfg-without-burning option, and witheta1, no cap and no momentum it degrades exactly to standard CFG.tangential_damping- TCFG, Kwon et al. CVPR 2025. Removes the component of the unconditional prediction that lies off the main direction both predictions share, then runs plain CFG. Less of the negative's noise, structured advice kept.angle_limit- the angle idea from ADG, Jin et al. ICML 2025: pastmax_angle_degreesaway from the conditional prediction, stop extrapolating and rotate instead. Default cap 60°, and the pack's notes are blunt that 60° on SDXL at cfg 14 hands half the conditional estimate's confidence away per capped step - a 30° cap keeps more colour. On flow-matching models the default behaves.mahiro- the ComfyUI community node, described elsewhere in this pack's node list: it blends toward the scaled conditional prediction by how similar the two predictions are.
The inputs
One model in, one MODEL out, plus:
rule- pick one of the four above.scale- the guidance scale for the rule;-1(default) inherits the KSampler's cfg.eta- APG only: weight of the part along the conditional prediction, default0, which is the paper's setting.1with zero cap and zero momentum is standard CFG.norm_threshold- APG only: cap on the difference's norm in the denoised latent's units, default15(the paper's SDXL row),0disables it.momentum- APG only: reverse momentum over steps, default-0.5(the paper's value),0off.max_angle_degrees-angle_limitonly: the largest rotation away from the conditional prediction, default60.space- where the rule is computed.autoputs APG and the angle rule on the denoised image, which is what their papers do. Changing it changes the image for every rule here, because none of them are linear.
Every knob is on the node all the time, and only the ones the selected rule uses do anything - one node, four rules, identical wiring. It does mean a leftover max_angle_degrees of 20 sitting on an APG run is doing precisely nothing.
One thing to know before migrating
This node's APG is the paper's form - c + (w - 1)·(...) - which is one unit less than ComfyUI's built-in APG node, which uses c + w·(...). A cfg you tuned for the built-in node is not the same number here; A/B at the same cfg and expect the pack's version to look less aggressive until you raise it. Two implementations of one method with different conventions is the most reliable source of "this method doesn't work" posts.
Install
ComfyUI Manager: search CFG Megapack, install, restart. comfy-cli: comfy node install comfy-cfg-megapack. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/AbstractEyes/comfy-cfg-megapack
Restart ComfyUI. No requirements.txt and no model files - the pack only needs torch and the standard library on top of ComfyUI's newer comfy_api.latest node API. Tested on ComfyUI 0.38.0 with torch 2.11, GPU and CPU-only. CFG_MEGAPACK_VRAM_FRACTION=0.6 before launch caps its share of the card.
The pack's example workflows are worth a look if you want a starting point rather than a blank canvas: Workflow → Browse Templates → Custom Nodes → comfy-cfg-megapack, and every example renders the plain-CFG and variant images from one seed.
Traps
- It's a stage node, and the stage is exclusive. This is one of three nodes that write the "combine" stage, alongside CFG Mix: Scale Rules and CFG Mix: Pentachoron - and every paper node in the combining family writes it too. Chain two and the later one wins; you don't get APG plus TCFG.
- APG's norm cap is in latent units.
norm_thresholdof 15 is calibrated for SDXL's denoised latent scale. On a different model family it may be far too tight or effectively off. Set it to 0 to disable and see what the cap was doing. - ComfyUI has a single CFG-function slot. Another pack's RescaleCFG, Mahiro or RenormCFG chained after this node takes it. Chain the node you care about last.
- The plan is inspectable. If you're not sure which stage node actually won, CFG Plan Readout prints the whole plan on the model. It takes ten seconds and saves a lot of staring at a graph.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| rule | COMBO | apg | 4 options: apg, tangential_damping, angle_limit, mahiro |
| scale | FLOAT | -1.0-1–100 | The guidance scale w for this rule. -1 uses the sampler's cfg value. |
| eta | FLOAT | 0.00-10–10 | apg: weight of the part along the conditional prediction (1 with no cap and no momentum = standard CFG; paper: 0). |
| norm_threshold | FLOAT | 15.00–200 | apg: cap on the difference's norm, in the denoised latent's units (0 = off; paper SDXL row: 15). |
| momentum | FLOAT | -0.50-1–1 | apg: reverse momentum over steps (negative = reverse, the paper's -0.5; 0 = off). |
| max_angle_degrees | FLOAT | 601–180 | angle_limit: the largest rotation away from the conditional prediction. |
| space | COMBO | auto (the method's own) | Where the rule is computed. Linear rules give the same image in any space; nonlinear ones do not. 'auto' uses the space the method was published in (noise for most, denoised for APG and the angle rule, velocity for flow models). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |