Nodes/ComfyUI Model Bending/DiT Block Bending
ComfyUI Node

DiT Block Bending

Bend whole transformer blocks, on the image grid

By abuzreq·Created 2 years ago·Updated 11 days ago· 26
DiT Block Bending
  • model
  • bending_module
  • MODEL
  • report
◄blocksdouble:0-3►
◄streamimg►
◄spatialtrue►
◄t_start1.00►
◄t_end0.00►
◄strictfalse►

Modern image and video models aren't UNets any more. Flux, SD3, WAN, Qwen-Image, LTX and HunyuanVideo are all transformer stacks, with double_blocks / single_blocks lists instead of the old input_blocks/middle_block/output_blocks structure. "Bend middle_block.2" is not even a sentence you can say there.

DiT Block Bending is the generic entry point for those models: pick blocks by index, pick which stream you're bending, and bend the block's output with any bending module in the pack.

How it works

It hooks into ComfyUI's native block-replace mechanism - patches_replace["dit"][("double_block", i)] and ("single_block", i) - rather than reaching into the module tree directly. That's the same seam the model's own patching uses, so it composes with whatever else is patching blocks, and it works across families because ComfyUI already normalised the names.

Two details do the heavy lifting:

  • Streams. Double blocks carry separate image and text streams; stream picks img, txt or both. Single blocks carry a joint [txt; img] token tensor, which the node splits at the known text length before bending (using the model's own image-token slice where available).
  • Spatial. With spatial on (the default), image tokens are laid out on their 2-D grid before the module runs, so a rotate rotates the picture rather than shuffling a token list. For video models the grid is (frames, height, width), which is what makes temporal modules work here at all. If the grid can't be inferred it warns and bends the flat token list.

There's also a diffusion-time window (t_start, default 1.0; t_end, default 0.0, i.e. everything) and a NaN guard: if a bend produces non-finite values they're replaced, with one warning per run rather than a screenful.

Inputs and outputs

  • model - the chain to patch. Output is a cloned MODEL; put it before the sampler.
  • bending_module - any BENDING_MODULE: Multiply Scalar, Rotate, Scale, Translate, Gaussian Blur, Sharpen, Flip, or a temporal one.
  • blocks - double:0-3 by default. The grammar is kind:range pairs: double:0-6, single:25-37, or double:* for the lot. Double blocks are the joint attention/MLP blocks; single blocks are the long tail most models have more of.
  • stream - img (default), txt or both. Worth reading the warning: on WAN-style blocks that only return an image stream, text simply isn't available here - the text context is read through cross-attention, not transformed block to block. Use Attention Map Bending if you want to touch how text is attended.
  • spatial - on by default. Turn it off only when you want to act on the token list.
  • Optional t_start, t_end, strict.

Outputs are MODEL and a report string that tells you the model class, the block lists it found and their counts, which blocks you hit, and your stream/spatial choices. That report is how you confirm a model was actually patched rather than silently skipped.

Blocks or layers?

Pick blocks if you want a predictable, broad effect and don't want to read a layer dump. Pick a specific leaf path via Model Bending if you've used Bendable Layer Catalogue to find something surgical. Bending a block bends everything downstream of it inside that block; bending someone.attn1.to_out bends one projection.

Rough geography on the models people run: early blocks shape layout and composition, middle blocks are where style and structure live, late blocks are detail. On WAN 2.1 1.3B the middle of interest is roughly blocks 13–18 of 30 (the DiT Block Bending workflow uses double:10-20, and the README suggests starting 13-18).

Install

ComfyUI Manager → search "ComfyUI Model Bending", or:

cd ComfyUI/custom_nodes
git clone https://github.com/abuzreq/ComfyUI-Model-Bending
pip install -r ComfyUI-Model-Bending/requirements.txt

Dependencies: kornia, scikit-learn. Restart ComfyUI; the pack logs under [model-bending].

Where people get burned

  • Running it on an SDXL or SD 1.5 UNet. It finds no double_blocks and warns that no block patch was called. Nothing happens, by design - use Model Bending (SD Layers) or Model Bending (SD Blocks) on UNets instead.
  • Bending single:* when you meant double:*. Different seams, different effects. Single blocks are the second half of the stack on most architectures; the report lists counts so you can see what you're actually addressing.
  • stream: both on a model that has no text stream at those blocks. A warning, not an error, unless strict is on - which is exactly what strict is for, incidentally. Flip it on while you're setting a graph up, off once it works.
  • Expecting a bend to be subtle. Start with a modest module (multiply 1.3, or rotate 15°) on a small block range. A rotate at 90° across every block is not a style, it's a render failure.
  • Assuming "blocks" means the same thing in every model. They're indices into whatever list the model exposes. Read the report; don't assume WAN's block 15 is Flux's block 15.
Categorymodel_bending

Inputs (8)

NameTypeDefaultDescription
modelMODEL—
bending_moduleBENDING_MODULE—
blocksSTRINGdouble:0-3e.g. 'double:0-6, single:25-37', 'double:*'
streamCOMBOimg3 options: img, txt, both
spatialBOOLEANtrueLay image tokens out on their 2-D grid before bending
t_startoptFLOAT1.000–1—
t_endoptFLOAT0.000–1—
strictoptBOOLEANfalse—

Outputs (2)

NameTypeDescription
MODELMODEL—
reportSTRING—