Nodes/ComfyUI Model Bending/Model Bending (SD Layers)
ComfyUI Node

Model Bending (SD Layers)

Bend one Conv layer inside a block

By abuzreq·Created about a year ago·Updated 3 months ago· 21
Model Bending (SD Layers)
  • model
  • bending_module
  • MODEL
blockinput_blocks
layer_num0

Model Bending (SD Blocks) aims at a whole block. Model Bending (SD Layers) takes that one step deeper: it numbers the individual convolution layers inside the block you pick, and you bend just one of them. Blocks are big, coarse targets - individual conv layers are where the finer, stranger effects live, and this node is how you get at them without writing a path.

Think of it as the precision counterpart to the block node, in the same pack and the same SD-UNet family. The tradeoff: you now need to know which number is which layer, which means a little exploration first.

How it works

The node scans the block you select and collects every leaf Conv2d module inside it, in model order, then indexes that list by your number. layer_num is therefore a per-conv counter, not the raw PyTorch module numbering you might see in Model Inspector - a block with attention modules, norms, and resnets will have many modules but fewer actual Conv2d layers, and this node counts only the convs.

  • block - input_blocks, middle_block, or output_blocks.
  • layer_num (INT, default 0) - which Conv2d in that block to bend.

Same forward-hook machinery as the rest of the pack: clone the model, resolve the target, install the hook for the run. An out-of-range layer_num clamps to the last conv instead of crashing. The one required input beyond those two is bending_module (BENDING_MODULE), and the sole output is the patched MODEL for your sampler.

The input that matters

layer_num is the knob you'll actually iterate on. The practical loop:

  1. Put Model Bending (SD Layers) between your checkpoint and the sampler.
  2. Feed it a Multiply Scalar Module (Bending) at 0.0 - this ablates (kills) one conv layer.
  3. Bump layer_num up one at a time and rerun.

Ablating layers one by one is the fastest way to map which conv does what: some will barely register, others will erase whole concepts. Once you find a layer that matters, switch the module to Rotate or Add Scalar and play with magnitude. The README's result catalog is built exactly this way - multiplying one layer's activations by 0 (ablation), 0.5, 1, 1.5, 2 and sorting the outputs top-to-bottom by layer depth.

Installing

This is one node in the ComfyUI-Model-Bending pack:

cd ComfyUI/custom_nodes
git clone https://github.com/abuzreq/ComfyUI-Model-Bending

Restart ComfyUI and refresh the browser, or use ComfyUI Manager (search ComfyUI-Model-Bending). Dependencies are light - kornia, scikit-learn - and there's nothing to download. Name the clone folder ComfyUI-Model-Bending; the README's ComfyUI-Web-Bend-Demo folder name is stale copy-paste.

Where people get tripped up

The layer numbering not matching Model Inspector's tree confuses everyone once. If you're cross-referencing the Inspector, remember you're counting Conv2d leaves, not every module. And the same identity-default trap applies: a Multiply Scalar at 1 or Rotate at 0 is a pass-through, so "nothing changed" usually means the module is at its default value, not that the layer is inert. If you're on Flux or another transformer model, this node is SD-only - use Model Bending with a custom path there.

Categorymodel_bending

Inputs (4)

NameTypeDefaultDescription
modelMODEL
bending_moduleBENDING_MODULE
blockCOMBOinput_blocks3 options: input_blocks, middle_block, output_blocks
layer_numINT0

Outputs (1)

NameTypeDescription
MODELMODEL