Nodes/Anima Safe PAG/Anima Safe PAG
ComfyUI Node

Anima Safe PAG

Sharper lines and steadier faces on Anima, without a second model

By iljung1106·Created 2 months ago·Updated 2 months ago· 5
Anima Safe PAG
  • model
  • MODEL
scale4.0
block_indices18
perturbation_strength0.75
head_indices
start_percent0.000
end_percent0.700
rescale0.20
rescale_modefull

If you've been on Anima for more than a week, you know the complaint: output that follows the prompt beautifully but lands soft. Lines wobble, faces go vague, fine detail smears into mush. The usual fixes - more steps, latent upscale between two samplers - help, but they don't address why the base renders that way. Anima Safe PAG attacks the sampling itself. It's a model patch that applies a softened Perturbed Attention Guidance (PAG) to Anima and other Cosmos/Predict2-style DiTs, and for a 2B anime model with no ControlNet ecosystem to lean on, that kind of sampling-time knob is worth having in your pocket.

What it actually does

PAG is a 2024 trick that predates Anima: instead of guiding against a negative prompt, you build a weak prediction by deliberately breaking the model - perturbing self-attention in a few transformer blocks - then push the final result away from that broken prediction. The result is crisper structure and better local detail, with nothing extra loaded.

Where most PAG implementations go all-in on the perturbation, this node gives you perturbation_strength. At 1.0 you're basically at hard PAG; at 0.75 (the default) the perturbed attention is only 75% blended toward the value/identity path, so the "weak" prediction stays weak and the correction stays gentle. That's the whole pitch: hard PAG can leave edges harsh on a model this size, and Safe PAG lets you back it off until the effect is cosmetic rather than crunchy.

A few implementation details make it worth trusting. Cond, uncond, and the PAG prediction all run in one calc_cond_batch pass, so there's no separate, expensive PAG model evaluation. And the extra PAG row stays in the batch even outside the active sampling range, which keeps the batch shape stable - that's why it plays nice with Anima Layer Replay Patcher, SPEED, and other nodes that cache or replay model execution. The README says this explicitly, and the code backs it up.

The inputs that matter

You wire in a MODEL and get a MODEL out, so it slots between your checkpoint loader and the KSampler. Nine inputs, but you really set three:

  • block_indices - which transformer blocks get perturbed. A single index, a list (18,20), or a range (18-20). For 28-block Anima checkpoints the README says stay above 14; 18 is the balanced start, and 16, 18, 20, or 18-20 are good neighbors.
  • scale - strength of the PAG correction (default 4.0). Crank it if edges are still soft, back it off if lines start looking harsh.
  • start_percent / end_percent - the active window as sampling progress (0.01.0, not raw sigmas). The default 0.00.7 applies it through the early and mid phases and leaves the late steps alone, which is a sensible place to start.

perturbation_strength (0.75) and rescale (0.20) are the other two worth touching - rescale is standard guidance rescale, taming the contrast/saturation growth PAG can cause; rescale_mode full vs partial changes what it rescales against, and full is the safer default. Leave head_indices empty; the README warns manual head selection gets unpredictable on the common 16-head checkpoints.

Installing

No dependencies, no model downloads, no Python packages - the whole thing is pure Python. ComfyUI Manager → "Anima Safe PAG", or:

cd ComfyUI/custom_nodes
git clone https://github.com/iljung1106/comfyui-anima-safe-pag.git

Then restart ComfyUI. That's it.

Where people get burned

The big one is model compatibility. This node only works on Anima/Cosmos/Predict2-style models that expose diffusion_model.blocks with block-level self_attn.compute_attention. Plug it into an SDXL checkpoint and it raises a RuntimeError immediately - it's not going to silently no-op on you. If another node overrides ComfyUI's calc_cond_batch and eats the padded PAG row, you'll get a clear error telling you exactly that; drop the competing node or move this one after it. And watch the console on your first run: it prints an "active: blocks=…" line and a first-step mean |cond - pag| number, which is a genuinely useful sanity check - if that delta is near zero, the perturbation isn't reaching the blocks you picked and you should raise the index or strength.

Is it a miracle fix? No. On a soft base like Anima it's a refinement, not a rebranding - pair it with the usual artist-tag prompting and latent upscaling for the full effect. But for a small patch that adds zero VRAM and one clean knob, it's the rare Anima quality tool that's actually worth installing.

Categorymodel/patches

Inputs (9)

NameTypeDefaultDescription
modelMODEL
scaleFLOAT4.00–100
block_indicesSTRING18
perturbation_strengthFLOAT0.750–1
head_indicesSTRING
start_percentFLOAT0.0000–1
end_percentFLOAT0.7000–1
rescaleFLOAT0.200–1
rescale_modeCOMBOfull2 options: full, partial

Outputs (1)

NameTypeDescription
MODELMODEL