Nodes/KJNodes for ComfyUI/Latent Patch Grid Remove KJ
ComfyUI Node Runs on cloud

Latent Patch Grid Remove KJ

Getting that faint checkerboard off your flat colors

By kijai·Created 3 years ago·Updated 3 days ago· 3,521
Latent Patch Grid Remove KJ
  • samples
  • LATENT
◄patch_size2►

What it's for

You generated something with a big flat area - a studio backdrop, a sky, a wall - and after decoding there's a faint, perfectly regular grid across it. Not noise, not banding: a grid. Change the seed and it's still there, in the same places.

That's a patch-offset artifact. Some diffusion transformers leave a small fixed bias at each position inside their patch_size × patch_size latent patch. The DiT is supposed to be position-agnostic inside a patch, and when it isn't, the bias survives all the way to the VAE and prints as a grid. With patch_size 2 and an 8× VAE that lands at 16 pixels, which is exactly the sort of spacing that reads as "screen door" over a smooth gradient.

This node subtracts that bias and nothing else. It's a very narrow tool - the author says so himself, naming Ming-Image as where he saw it - and it's the correct answer to that specific artifact rather than a general prettifier.

How it works

It unfolds the latent into blocks of patch_size × patch_size, computes how far each of the nine-or-four-or-whatever positions sits from its own block's mean, and averages that across every block, frame and channel. The result is a tiny tile - the artifact's signature - which then gets repeated back over the full image and subtracted.

Two consequences worth understanding:

  • It's estimated from the whole latent, per image, frame and channel. So it's a single measured offset, not a filter or a blur. Fine detail has nothing to lose here because nothing is being smoothed.
  • If the model has no fixed offset, the estimate is close to zero and the node does almost nothing. Which is why it's safe to leave in a workflow, and also why "I added it and saw no difference" is the expected result on a busy, detailed image.

The author's own line - "busy, detailed images see little change" - is the honest framing. This isn't a quality node. It's artifact surgery for one model family's specific misbehavior.

The inputs that matter

Only two required inputs, no optional ones:

samples - the LATENT, i.e. the sampler's output. Put the node between the sampler and VAE Decode, as the description says. Whatever latent the decoder sees should be the corrected one; if you hand it the pre-fix latent you'll never see a difference.

patch_size - an INT from 2 to 8, default 2. The tooltip is the whole story: 2 for most DiTs. If you get it wrong the tile you subtract has the wrong period and the grid survives (or you introduce a slightly different one). Get this from the model, not from guesswork - if you're running Ming-Image or a similar DiT with an unusual patch size, that's the number to change.

Output is a single LATENT. Wire it to VAE Decode, or to whatever comes next in a video pipeline.

KSampler(LATENT) → Latent Patch Grid Remove KJ(samples, patch_size=2) → VAE Decode

Installing it

No download, no model, no special dependency - it's pure tensor math on the latent, so it works the moment the pack loads.

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
pip install -r ComfyUI-KJNodes/requirements.txt

Restart ComfyUI, or just use Manager and search the pack title "KJNodes for ComfyUI". Portable Windows:

python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt

The pack's dependency list is short (pillow, color-matcher, matplotlib, mss, opencv-python-headless), which is part of why KJNodes ends up in nearly everybody's install and almost never starts a pip fight.

Common issues

The grid is still there. Check patch_size first. Then check that the node is actually upstream of the decode - a bypassed node, or a second decode fed from the raw sampler, will happily waste your time.

Different spacing, or edges instead of a grid. This removes a fine, regular, fixed offset. Block boundaries at the VAE's tile size, or a seam down the middle of the image, are a different problem with a different fix, and this node won't touch them.

"I don't see any change." Expected on detailed images, and expected on models that don't leave the offset. If you're not seeing the artifact in the first place, take the node out - adding it to every workflow is harmless but pointless, and a graph with fewer mystery nodes is a graph you can still debug in six months.

CategoryKJNodes/latents

Inputs (2)

NameTypeDefaultDescription
samplesLATENT—
patch_sizeINT22–8Spatial patch size of the diffusion model (2 for most DiTs).

Outputs (1)

NameTypeDescription
LATENTLATENT—