Nodes/ComfyUI_GradientDeepShrink/GradientPatchModelAddDownscaleAdvanced (Kohya Deep Shrink)
ComfyUI Node

GradientPatchModelAddDownscaleAdvanced (Kohya Deep Shrink)

Keyframes for Kohya Deep Shrink — shape the downscale curve however you want

By kinfolk0117·Created 3 years ago·Updated 2 years ago· 30
GradientPatchModelAddDownscaleAdvanced (Kohya Deep Shrink)
  • model
  • MODEL
block_number3
downscale_after_skiptrue
interpolatetrue
config0 0.5 1 1

The one that lets you draw the curve

The plain GradientPatchModelAddDownscale gives you a single downscale factor and one linear ramp. Fine for most cases. But the moment you push an SD 1.5 render toward 4k, or wish the low-res phase would just hold instead of fading on schedule, you hit the wall this node exists for. It throws out the single factor and window entirely and lets you define your own curve as a list of percentage → scale factor pairs. Keyframes for deep shrink.

This is the more interesting half of the pack, and not by accident. In the author's r/StableDiffusion thread announcing the gradient idea, a user pushing 4096×4096 generations asked for exactly this: "keyframes" for the duration of sampling, because a single linear ramp went too weak before the latent finished. This node is basically that feature request shipped.

How it works

Same MODEL → MODEL patcher as the base node, same block patch, same sigma mapping. The difference is where the scale factor comes from. Instead of computing 1/downscale_factor and ramping over a window, it parses your config string into percentage/scale pairs, sorts them, then for any point in sampling interpolates linearly between the surrounding pairs. Flip interpolate to false and it snaps to the nearest lower pair instead - a stepped curve, which is closer to how the stock deep shrink behaves, except you get as many segments as you want.

Note there is no downscale_factor input at all. The pairs are the whole story. The scale is relative, so 0.5 means half resolution and 1.0 means full.

The default config is 0 0.5 / 1 1 - half resolution at the start of sampling, smoothly back to full by the end. To reproduce the classic deep-shrink pattern of hold-then-release, give the start pair a plateau:

0 0.5
0.35 0.5
1 1

That keeps the image at half res until 35% of sampling, then ramps out. For extreme resolutions you can push the plateau later, or soften the initial factor, or stage the release in several steps. That's the whole point - the shape is yours.

The gotchas

  • The config parser is strict: every line must be exactly two whitespace-separated numbers. A stray comma, an extra token, or an empty line and the node throws. Order doesn't matter - it sorts the pairs for you.
  • There's a leftover debug print in the patch function, so every run echoes your config pairs into the ComfyUI console. Harmless, just noise.
  • Same pack-level caveats as the base node: one commit from December 2023, never updated, and it rots if ComfyUI core drifts. The 'ModelPatcher' object has no attribute 'set_model_input_block_patch_after_skip' error on old installs means update ComfyUI, not reinstall this.

Installing it

ComfyUI Manager: search GradientDeepShrink. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/kinfolk0117/ComfyUI_GradientDeepShrink

Restart, and the output MODEL feeds your KSampler like any other model patch. No extra dependencies, no downloads.

Which one should you use?

If "big image, fewer artifacts" is the whole goal and the defaults work, the base node is simpler and you'll never miss this one. The Advanced version earns its keep when you're generating way past the model's native resolution and the default curve isn't holding - or when you want the release staged rather than one smooth fade. For anyone doing SD 1.5 megapixel-plus work, it's the node from this pack I'd actually reach for.

Category_for_testing

Inputs (5)

NameTypeDefaultDescription
modelMODEL
block_numberINT31–32
downscale_after_skipBOOLEANtrue
interpolateBOOLEANtrue
configSTRING0 0.5 1 1

Outputs (1)

NameTypeDescription
MODELMODEL