From 8c88b3213cb941aed807c49fa96f33e9d52bcf2d Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Wed, 4 Mar 2026 18:36:07 +0100 Subject: [PATCH] Add spatial smoothing to remove latent grid artifacts The per-element correction creates a visible mesh pattern at the VAE's 8x8 patch boundaries. A 3x3 box blur in latent space (24x24 pixels) smooths adjacent corrections while preserving the large-scale correction structure. Co-Authored-By: Claude Opus 4.6 --- nodes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nodes.py b/nodes.py index 4cfd450..9b1532b 100644 --- a/nodes.py +++ b/nodes.py @@ -1,4 +1,5 @@ import torch +import torch.nn.functional as F class SMCCFGCtrl: @@ -101,6 +102,13 @@ class SMCCFGCtrl: phi = s.std().clamp(min=1e-6) u_sw = -K_eff * torch.tanh(s / phi) + # Spatial smoothing: the per-element correction creates a grid + # pattern at latent boundaries (each latent = 8x8 pixels). A mild + # 3x3 box blur in latent space removes these artifacts while + # preserving the large-scale correction structure. + if u_sw.ndim == 4: + u_sw = F.avg_pool2d(u_sw, kernel_size=3, stride=1, padding=1) + # Corrected guidance error (in normalized noise space) guidance_eps = guidance_eps + u_sw