HSpace Bending
HSpace Bending
- model
- pcs
- MODEL
This is the payoff node for Compute PCA, and arguably the most elegant idea in the whole pack. Instead of bending a layer with noise or a scalar - which is poking it blind - HSpace Bending moves the model along directions it itself told you about. It's the diffusion-model analog of the StyleGAN h-space steering trick: you compute principal components of the middle-block activations, then add a scaled component back in at each denoising step. Result: generations that slide along a "natural" axis of variation the model learned, rather than a random distortion.
Here's how it actually runs. It hooks the UNet's middle block and, on every denoising step, adds pcs[direction, current_step] * scale to that block's output. The pcs tensor comes from Compute PCA, which is shaped as [component, denoising_step, channel, height, width] - so each principal component has its own per-step slice, which is why the model can follow the direction smoothly across the whole denoising trajectory instead of getting yanked at one step. The hook is registered per-forward and removed after, so the shared model stays clean.
Inputs:
- model - the model to patch.
- pcs - the
PCSoutput ofCompute PCA. Wire it straight across. - direction - which principal component to follow, default 0, range 0–9. Component 0 is the largest axis of variation; higher indexes get increasingly subtle and weird. You'll want to sweep this.
- scale - how hard to push along that direction, default 1.0. Negative values steer the opposite way along the axis, which is often where the interesting variations live.
The workflow is baked into the pack's PCA_HSpace_bending.json: run Compute PCA (give it a real number of batches - more data, better directions), then feed PCS into this node. It's marked experimental in the source, and it shows in the cost: PCA is a multi-generation investment before you even bend anything. But the quality of the effect is a cut above the blunt modules - a good direction at moderate scale produces coherent, almost "intentional" variation that looks like the model changed its mind, not like you broke it.
Install: ComfyUI Manager → search "ComfyUI-Model-Bending" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/abuzreq/ComfyUI-Model-Bending
pip install -r requirements.txt # scikit-learn is mandatory for Compute PCA
The realistic caveat: this pack has essentially no community footprint, so there's no shared lore on which directions "mean" what on which model - you'll be discovering that yourself. And because PCA is fit on whatever prompts you ran, your directions are specific to your sampling setup: change the checkpoint and the axes mean different things. That's not a bug, but re-run PCA when you switch models.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| pcs | LATENT | — | |
| direction | INT | 00–9 | — |
| scale | FLOAT | 1.00 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |