Nodes/CFG Megapack/Mahiro: positive-biased guidance (ComfyUI)
ComfyUI Node

Mahiro: positive-biased guidance (ComfyUI)

The no-knob guidance node that makes bad negatives behave

By AbstractEyes·Created 5 days ago·Updated 5 days ago· 3
Mahiro: positive-biased guidance (ComfyUI)
  • model
  • MODEL
◄scale-1.0►
◄spaceauto (the method's own)►

Mahiro is the odd one out in this pack: a community trick rather than a paper. It landed as a ComfyUI pull request, got the nickname, and now shows up in several packs including this one. It has exactly two input fields beyond the model, and its job is to fix a specific annoyance - the negative prompt that argues with your positive prompt and drags the image back toward mush.

What it does

Plain CFG extrapolates away from the unconditional prediction by a fixed multiple. Mahiro asks, first, how much the unconditional and conditional predictions actually resemble each other once they've been scaled. It measures that as a single similarity score - a cosine, taken on signed square roots of the scaled predictions - and then uses the score to blend between plain CFG and simply using the scaled conditional prediction.

When the two predictions are aligned, the score goes up and the result leans toward the scaled conditional: the negative stops being subtracted from an image it doesn't disagree with. When they're genuinely different - a negative doing real work - plain CFG is what you get back. So it's positive-biased, and conservative in the sense that it only intervenes when the negative wasn't pulling in a useful direction anyway.

Set the KSampler's cfg to 1 and the whole thing is moot; there's no guidance difference left to bias. On a guidance-distilled model that's the correct setting anyway, and this node is then just a passenger in your graph.

The inputs

  • scale - the guidance scale for the rule; -1, the default, means "use the KSampler's cfg". As with every combine node in this pack, tuning cfg on the sampler is the normal workflow.
  • space - auto (the method's own) is correct. Changing it changes the image, since the similarity test isn't linear.

Output: a single MODEL. Loader → Mahiro → KSampler, and you're done.

That's genuinely the whole interface, which is why people like it. There is no strength dial, and I'd argue that's a feature: it's a behaviour, not a parameter. If you want to tune a similar idea by hand, this pack's CFG Mix: Direction Rules exposes the mahiro rule in a multi-rule node alongside APG and the other direction-based rules, so you can compare them without adding nodes.

Install

Mahiro-style nodes also ship elsewhere, but the version here is part of CFG Megapack, which is one install for all of its nodes.

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. No requirements.txt, no model files, no extra packages - torch and the Python standard library over ComfyUI's newer node API (comfy_api.latest). Tested on ComfyUI 0.38.0 with torch 2.11 on GPU and CPU. CFG_MEGAPACK_VRAM_FRACTION=0.6 before launching caps its VRAM share on a busy card.

Traps

  • It's batch-coupled, and this is the one that catches people. The similarity score is a single scalar computed across both pixels and the batch, so in a batch of eight, one image's similarity steers all eight. If you're doing batch experiments and the results look correlated in a way that doesn't make sense, that's why.
  • Chaining order across packs matters more here than usual. Mahiro and this pack's node both want ComfyUI's single CFG-function slot, and the node chained last wins. If you're stacking this with another pack's RescaleCFG or RenormCFG, chain the one you care about last and check the result changed.
  • It does nothing visible on many prompts, and that's the method. The node's effect scales with how much your negative and positive disagree. A prompt with a light negative will look identical; that's not an install problem.
  • It replaces other combine nodes. Drop an APG node after Mahiro and you've swapped the stage, not stacked the two - a later node of the same stage takes over. The pack's CFG Plan Readout prints exactly which node is holding each stage, which is the fastest way to stop guessing.
CategoryCFG Megapack/papers/combining the two predictions

Inputs (3)

NameTypeDefaultDescription
modelMODEL—
scaleFLOAT-1.0-1–100The guidance scale w for this rule. -1 uses the sampler's cfg value.
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—