Nodes/Comfy_z-sampling/Z-Sampler (Zigzag)
ComfyUI Node

Z-Sampler (Zigzag)

The KSampler that backs up, inverts, and redraws

By sal063·Created 7 months ago·Updated 7 months ago· 1
Z-Sampler (Zigzag)
  • model
  • positive
  • negative
  • latent_image
  • z_settings
  • samples
seed0
steps30
cfg5.5
sampler_name
scheduler
denoise1.00
preview_every1
show_zigzag_phasesfalse
preview_methodauto

This node replaces your KSampler with something slower that sometimes looks better. It's a ComfyUI port of Z-Sampling, an inference-time refinement trick from the Xie lab's zigzag diffusion research, and it was built for - and only really tested on - Anima and other Cosmos-based models. If you're generating anime on Anima and want to squeeze a bit more quality out of the same step count, this is the whole pitch. Just know what you're signing up for before you queue a 30-step batch.

How the zigzag works

A normal sampler takes one step down the noise ladder per iteration and never looks back. Z-Sampler doesn't trust itself. For each step it first does a regular denoise pass, then deliberately walks back up the noise ladder for a moment (an inversion step run at weak or no guidance), then steps forward again with full guidance. Rinse and repeat t_max times. The idea is those extra forward-backward laps give the model a chance to correct its own mistakes instead of committing to a bad trajectory.

That costs real compute. Every zigzag round is two extra model evaluations on top of the normal one, so at defaults you're paying roughly three model passes per step. A 30-step Z-Sample feels like a 60–90 step normal sample in wall-clock time. Whether that buys anything depends on the model - on Anima it's where the author tuned it; on SDXL you're gambling on fixed preview matrices and an untested path.

Inputs and outputs

The core sockets are the same shape as a KSampler: model, positive, negative, latent_image, then seed, steps (30), cfg (5.5), sampler_name, scheduler, denoise. Same wiring, same VAE Decode on the other end. The samples output is a plain LATENT.

The interesting part is the optional z_settings input. Wire a Z-Sampling Settings node in and its four knobs take over: cfg gets replaced by the settings' gamma_1 for the denoise legs, and gamma_2, lambda_step, and t_max decide how deep the zigzag goes. Skip the settings node entirely and Z-Sampler runs with sensible defaults (gamma_1 = your cfg, gamma_2 = 0, zigzag on every step but the last, one round per step).

The rest of the optional inputs are about the live preview, which is genuinely the friendliest thing here. preview_method defaults to auto, meaning it tries TAESD if you have it and otherwise falls back to a built-in latent2rgb preview that needs no extra model files at all. preview_every controls how often (default every step) and show_zigzag_phases shows the intermediate inversion frames instead of just the denoise progress.

Install

Two ways, both painless. ComfyUI Manager → search "Comfy_z-sampling" → install. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/sal063/Comfy_z-sampling

then restart ComfyUI. There are no pip requirements and no model downloads - no TAESD, no safetensors - the whole pack is one Python file on top of ComfyUI core. That's refreshing.

Where people get burned

  • The sampler dropdown is decorative. The node accepts sampler_name with 44 choices, but the sampling kernel always steps with plain Euler internally - the choice changes nothing. Pick one and move on.
  • Channel mismatches. The node detects Anima/Cosmos (16 latent channels) vs SD/SDXL (4) and throws a clear error if your latent doesn't match. With Anima, the author's own advice is to feed it an Empty Cosmos Latent Video with length 1.
  • It's slow, and previews hide it. Previewing every step makes the progress bar crawl; set preview_every to 5 or so for long runs.
  • It's a single-commit, AI-assisted port - the README literally says "held together by hopes, dreams and claude opus." Only tested on Anima. Treat it as an experiment worth a weekend, not a production default.

Worth one aside: this is not the "ZSampler Turbo" that ships with Alibaba's Z-Image workflow. Same name, different lineage, don't confuse your downloads.

Categorysampling/z-sampling

Inputs (14)

NameTypeDefaultDescription
modelMODELThe diffusion model
positiveCONDITIONINGPositive prompt
negativeCONDITIONINGNegative prompt
latent_imageLATENTInput latent
seedINT00–18446744073709550000
stepsINT301–500
cfgFLOAT5.51–30
sampler_nameCOMBO44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38
schedulerCOMBO9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3
denoiseFLOAT1.000–1
z_settingsoptZSETTINGSOptional Z-Sampling config
preview_everyoptINT11–50Show preview every N steps
show_zigzag_phasesoptBOOLEANfalseShow intermediate zigzag phase previews
preview_methodoptCOMBOautoPreview method: auto tries TAESD first, falls back to latent2rgb

Outputs (1)

NameTypeDescription
samplesLATENT