Nodes/ComfyUI Model Bending/Latent Operation To Module
ComfyUI Node

Latent Operation To Module

Turn a latent op into a bending module

By abuzreq·Created about a year ago·Updated 3 months ago· 21
Latent Operation To Module
  • operation
  • BENDING_MODULE

Latent Operation To Module is the pack's Rosetta Stone: it takes a LATENT_OPERATION - the function-like output produced by nodes like Latent Operation (Threshold) or Latent Operation (Rotate) - and wraps it so it can be plugged into any input that expects a BENDING_MODULE. If you've built a latent op you like, this lets you reuse that same logic to bend the UNet, a VAE, or a LoRA without rebuilding it as a module.

It's the node you discover after you've been playing with the latent operations for a while and realize, "wait, can I feed this to Model Bending?" The answer is yes, via this adapter. It's marked EXPERIMENTAL in the source, and there's a reason: the wrapper it builds is a bare nn.Module that calls your operation on whatever tensor flows through, with none of the shape handling the dedicated bending modules get.

How it works

The pack's BENDING_MODULE type is just an nn.Module subclass that implements a bend() method. The latent operations, by contrast, are plain Python callables that expect a latent-shaped tensor - the 4D B, C, H, W thing the sampler works on. This node glues them together:

class BendingModuleWrapper(nn.Module):
    def forward(self, image):
        return operation(image)

Input operation (LATENT_OPERATION) in, BENDING_MODULE out. That's the whole node - one input, one output.

The one real caveat

Bending modules get applied to activations at arbitrary layers of the model, and those activations aren't always latent-shaped. A spatial op like rotation or a sobel edge filter will happily run on a 4D feature map, but if the wrapper ever receives a 2D or 3D tensor - some attention projections output 2D - the dedicated modules normalize the shape before bending and this one does not. If you feed it an op and the run throws a shape error, that's the culprit. Prefer the purpose-built Rotate / Scale / Threshold / Multiply Scalar Module (Bending) nodes when you can; use this node when you specifically want a latent op's exact behavior (like the multi-parameter custom ops from Latent Operation (Custom)) as a model bend.

Wiring it up

Typical flow:

  1. Latent Operation (Threshold)Latent Operation To ModuleModel Bending
  2. Or the same module into Model VAE Bending or LoRA Bending - the BENDING_MODULE type is accepted by all of them.

Installing

This ships in the ComfyUI-Model-Bending pack. Install the pack and the node appears:

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

Restart ComfyUI and refresh the browser tab. ComfyUI Manager users can search ComfyUI-Model-Bending instead. Dependencies are light (kornia, scikit-learn), no model downloads, and if you follow the README's clone snippet that names the folder ComfyUI-Web-Bend-Demo, keep it as ComfyUI-Model-Bending instead - the repo name - to avoid confusion.

If your bent model produces a gray smear or an outright crash, don't overthink it: the op was never meant for that layer. Try a dedicated module node, or point Model Bending at a different path. That's the whole learning loop of this pack anyway.

Categorymodel_bending

Inputs (1)

NameTypeDefaultDescription
operationLATENT_OPERATION

Outputs (1)

NameTypeDescription
BENDING_MODULEBENDING_MODULE