Nodes/CFG Megapack/CFG Mix: Direction Rules
ComfyUI Node

CFG Mix: Direction Rules

APG, TCFG, the angle cap and Mahiro

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
CFG Mix: Direction Rules
  • model
  • MODEL
◄ruleapg►
◄scale-1.0►
◄eta0.00►
◄norm_threshold15.0►
◄momentum-0.50►
◄max_angle_degrees60►
◄spaceauto (the method's own)►

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 by eta, the difference's norm is capped at norm_threshold, and a reverse momentum term carries between steps. This is the pack's high-cfg-without-burning option, and with eta 1, 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: past max_angle_degrees away 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, default 0, which is the paper's setting. 1 with zero cap and zero momentum is standard CFG.
  • norm_threshold - APG only: cap on the difference's norm in the denoised latent's units, default 15 (the paper's SDXL row), 0 disables it.
  • momentum - APG only: reverse momentum over steps, default -0.5 (the paper's value), 0 off.
  • max_angle_degrees - angle_limit only: the largest rotation away from the conditional prediction, default 60.
  • space - where the rule is computed. auto puts 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_threshold of 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.
CategoryCFG Megapack/3 mix

Inputs (8)

NameTypeDefaultDescription
modelMODEL—
ruleCOMBOapg4 options: apg, tangential_damping, angle_limit, mahiro
scaleFLOAT-1.0-1–100The guidance scale w for this rule. -1 uses the sampler's cfg value.
etaFLOAT0.00-10–10apg: weight of the part along the conditional prediction (1 with no cap and no momentum = standard CFG; paper: 0).
norm_thresholdFLOAT15.00–200apg: cap on the difference's norm, in the denoised latent's units (0 = off; paper SDXL row: 15).
momentumFLOAT-0.50-1–1apg: reverse momentum over steps (negative = reverse, the paper's -0.5; 0 = off).
max_angle_degreesFLOAT601–180angle_limit: the largest rotation away from the conditional prediction.
spaceCOMBOauto (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)

NameTypeDescription
MODELMODEL—