Extensions/comfyui-glitch-lab-sampler
ComfyUI Extension

comfyui-glitch-lab-sampler

A ComfyUI custom-node pack for abstract glitch art with three nodes that perturb diffusion sampling: sigma-schedule jitter, attention-map value dropout, and temporal frame interleaving for video latents.

By HitmanLoges·Created 3 months ago·Updated 3 months ago· 0
HitmanLoges/comfyui-glitch-lab-sampler
Nodes3
On cloudLocal install
Categoryglitch-lab
Stars0
Updated3 months ago
Readme

comfyui-glitch-lab-sampler

A ComfyUI custom-node pack for abstract glitch art. Three nodes that perturb diffusion sampling in ways the built-in samplers don't expose — sigma-schedule jitter, attention-map value dropout, and temporal frame interleaving for video latents.

This is not a wrapper that re-exposes existing parameters under flashier names. Every knob here corresponds to a real operation on the model's tensors. If a knob did nothing, it isn't here.

v0.2 — substantial revisions following code review by blepping (maintainer of comfyui_overly_complicated_sampling). Three real bugs were fixed and the redundant GlitchSampler node was removed in favour of the built-in SamplerEulerAncestral. See CHANGELOG.md for the specifics.

Sample outputs

All renders below are SD 1.5 base, 512×512, 20 steps. The same prompt is used for every image — "a red telephone box on a cobblestone street, london, late afternoon, photograph, sharp focus, 35mm" — so the only variable across the gallery is the preset's parameters.

The first image is unpatched (vanilla KSampler with euler_ancestral on the same prompt) so each subsequent render can be read against it.

unpatched reference

unpatched

baseline — jitter 0.05, no attention dropout

Near-vanilla. The reference point for what the sampler does at low settings.

baseline

soft-bleed — 0.15 self-attn dropout

Local feature integration starts to break down. Edges lose contact.

soft-bleed

veiled — 0.40 self-attn dropout

Heavy local-coherence suppression. Large gradients survive; detail doesn't.

veiled

schedule-burn — 0.50 sigma jitter, no attention dropout

Composition coherent (prompt influence isn't suppressed), tonal range warped because the schedule is no longer smoothly descending.

schedule-burn

slag — all perturbations near maximum

Asymptote of what the pack does — the prompt's subject dissolves into texture.

slag

To reproduce any of these, run tools/render_samples.py against a local ComfyUI on port 8000.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/HitmanLoges/comfyui-glitch-lab-sampler.git

Restart ComfyUI. Three nodes appear under the glitch-lab category in the node menu. No extra Python dependencies.

Verified on ComfyUI Desktop 0.22.2 (Windows, Python 3.12, PyTorch 2.10 + CUDA 13, RTX 3070). The patches use ComfyUI's stable ModelPatcher API (set_model_attn1_patch / set_model_attn2_patch); on other versions, the input names of SamplerCustomAdvanced / RandomNoise / CFGGuider are the most likely points of drift.

The three nodes

GlitchSigmasSIGMAS output. Builds a base scheduler curve (karras / exponential / normal / simple / ddim_uniform), applies per-step multiplicative jitter, re-pins sigmas[-1] to the base terminal value so denoising still completes. Plugs into SamplerCustomAdvanced's sigmas input.

AttentionDropoutPatcherMODEL → MODEL. Clones the incoming ModelPatcher and installs set_model_attn1_patch / set_model_attn2_patch hooks that zero a deterministic random subset of V rows before attention is computed. Self-attn dropout suppresses local feature integration; cross-attn dropout suppresses the prompt's influence on the latent. The deterministic seed is derived from the per-call context ComfyUI passes in (block, current sigma) rather than a closure counter — the counter approach was broken across sampling runs.

LatentFrameInterleaveLATENT → LATENT. Reorders the temporal axis of a 5-D (B, C, T, H, W) video latent (ComfyUI's actual layout — not (B, T, C, H, W) as an earlier version assumed). Intensity below 0.5 does probabilistic adjacent-pair swaps; above 0.5 does block-shuffle reordering. 4-D image latents pass through unchanged, so the same workflow handles still and video. AnimateDiff's (B*T, C, H, W) layout is out of scope — reshape before the node.

What's not in the pack — and why

No custom sampler node. The earlier GlitchSampler node exposed an extra_noise multiplier on the ancestral noise term. This is exactly what ComfyUI's built-in SamplerEulerAncestral exposes as s_noise (which the built-in also pairs with eta). Keeping the custom node would have been the "wrapper around existing knobs" antipattern this README explicitly disavows. The example workflows and tools/render_samples.py use SamplerEulerAncestral directly.

No flow-model support yet. The pack assumes diffusion-model sigma semantics. Flux / SD3 / Wan use a different parameterisation; supporting them properly is on the roadmap, not in this release.

Presets

presets/library.json ships 20 parameter bundles covering a deliberate spread of the parameter space (jitter × attn-dropout × interleave, plus scheduler swaps). Each preset name describes the visual behaviour, not the marketing.

Starting points:

  • baseline — near-vanilla. Reference. Start here.
  • soft-bleed — low self-attn dropout. Edges lose contact.
  • veiled — heavy self-attn dropout. Local coherence breaks down.
  • subject-loss — heavy cross-attn dropout. Output drifts toward the unconditional prior.
  • schedule-burn — heavy sigma jitter only. Granular, burned-print.
  • slag — all perturbations near maximum. Texture-only.
  • crawl / block-shuffle / frame-salad — video presets at increasing interleave intensity.

Validate the library against the schema after editing:

python -m jsonschema -i presets/library.json presets/schema.json

Example workflows

examples/baseline_api_workflow.json and examples/slag_api_workflow.json are ComfyUI prompt-API graphs (the format /prompt accepts). Replace CHECKPOINT_NAME.safetensors with a checkpoint actually in your ComfyUI/models/checkpoints/ before submitting:

curl -X POST http://localhost:8188/prompt \
  -H "content-type: application/json" \
  -d "{\"prompt\": $(cat examples/baseline_api_workflow.json)}"

(Port may differ — Desktop installer uses 8000, manual install uses 8188.)

Tests

The pure-math layer has a standalone test suite (torch only, no ComfyUI):

cd sampler && python test_sampler.py

Covers sigma-jitter determinism / boundary preservation, value-dropout seeding, the context-derived call index, frame-interleave shape / content preservation, axis-correctness (T not C is the permuted axis), and INPUT_TYPES / NODE_CLASS_MAPPINGS registration.

Reproducing the gallery

tools/render_samples.py drives a running ComfyUI on localhost:8000 via its HTTP API. Requires the node pack loaded and v1-5-pruned-emaonly.safetensors in models/checkpoints/. From the repo root:

python tools/render_samples.py

Writes PNGs to samples/ — one unpatched reference plus the five preset renders, all using the same prompt. stdlib only.

Status

v0.2. The pure-math layer is verified by the test suite. The live integration runs against the configuration above; substantial revisions in this release address bugs identified by external code review (frame-interleave axis, attention-patch determinism, sampler-node redundancy — see CHANGELOG.md).

Looking for one or two experimental glitch artists willing to drop the pack into their custom_nodes/ and tell me whether the outputs are interesting or just broken. If a node errors on your install, please open an issue with the ComfyUI release / commit you're on.

I'm not interested in marketplace integrations, paid presets, or a "creator economy". This is a sampler, that's all.

Feedback

Open an issue. Pull requests welcome.

Licence

MIT. See LICENSE.