Nodes/cgem156-ComfyUI๐ŸŒ/Gradual Latent Sampler ๐ŸŒ
ComfyUI Node

Gradual Latent Sampler ๐ŸŒ

A hi-res fix baked into the sampling loop instead of bolted on after

By laksjdjfยทCreated 2 years agoยทUpdated about a month agoยท 93
Gradual Latent Sampler ๐ŸŒ
    • SAMPLER
    โ—„sampler_nameโ–พโ–บ
    โ—„eta1.00โ–บ
    โ—„s_noise1.00โ–บ
    โ—„upscale_ratio2.00โ–บ
    โ—„start_step5โ–บ
    โ—„end_step15โ–บ
    โ—„upscale_n_step3โ–บ
    โ—„unsharp_kernel_size3โ–บ
    โ—„unsharp_sigma0.50โ–บ
    โ—„unsharp_strength0.00โ–บ
    โ—„unsharp_targetโ–พโ–บ

    The usual way to get a bigger, more detailed image is the two-stage hires-fix dance: generate at base resolution, decode, upscale, re-encode, run a second pass. Gradual Latent is a different idea, originally shipped as a Kohya extension for sd-webui: instead of two separate passes, you start sampling at a smaller latent size and progressively grow it mid-sampling, within one continuous denoising run. This node is cgem156's ComfyUI port of that technique, wrapped as a drop-in SAMPLER.

    How it actually works

    Composition gets decided early in a diffusion run and fine detail gets added late - that's the whole premise hires-fix exploits, just done as two disconnected passes with a resize in between. Gradual Latent does the same trade inside one run: it starts at a reduced latent resolution (cheaper, and fine, because early steps are deciding composition, not detail), then ramps the latent size up toward your target over a defined window of steps, applying a light unsharp mask after each upscale increment to counteract the softness that latent-space upsampling introduces. By the time sampling exits the ramp window, you're at full target resolution with the model's later steps free to spend their whole budget on detail rather than also having to re-derive composition from a freshly upscaled, blurry latent the way a bolted-on hires-fix pass would.

    Because this reshapes the latent mid-trajectory, it works with ancestral-style samplers rather than every sampler in the list - that's why it takes its own eta/s_noise and a sampler_name selection rather than just wrapping whatever's already in your KSampler.

    The inputs that matter

    • sampler_name - the underlying base sampler this wraps.
    • upscale_ratio - how much bigger the latent grows by the end of the ramp, default 2.
    • start_step / end_step - the step window the upscale ramp happens across, defaults 5 and 15. Outside this window you're sampling normally, at whatever size you're currently at.
    • upscale_n_step - how many discrete increments the ramp is broken into rather than one abrupt jump, default 3.
    • eta / s_noise - standard ancestral-sampler noise controls, both default 1.
    • unsharp_kernel_size / unsharp_sigma / unsharp_strength / unsharp_target - the sharpening pass applied after each upscale step to fight the blur. unsharp_strength defaults to 0 (off) - you'll want to raise it if you notice the ramp introducing softness, since the defaults ship conservative rather than aggressive.

    Output is a single SAMPLER, wired into KSampler (Advanced) or SamplerCustom like any other sampler.

    Installing it

    ComfyUI Manager, search "cgem156-ComfyUI". Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/laksjdjf/cgem156-ComfyUI
    

    Restart ComfyUI. No model download involved - it's a sampling algorithm, not a checkpoint.

    Where this pays off, and where it doesn't

    This is squarely an SD 1.5/SDXL-era technique - it assumes the DDPM-style curved denoising trajectory those architectures use, where reshaping effort across steps is a real lever. It has no obvious footing on flow-matching architectures (Flux, Z-Image, and friends), which train on a near-straight trajectory that generally punishes aggressive schedule reshaping rather than rewarding it - don't expect this to behave sensibly there.

    Common trap: leaving unsharp_strength at 0 and then being disappointed the output looks soft compared to a normal hires-fix - that softness is the upscale ramp doing its job without the compensating sharpen you need to turn on yourself. And because start_step/end_step are absolute step indices, changing your total step count without revisiting these will shift where in the trajectory the ramp actually lands - worth rechecking any time you tune steps elsewhere in the workflow.

    Categorycgem156 ๐ŸŒ/custom_samplers

    Inputs (11)

    NameTypeDefaultDescription
    sampler_nameCOMBO4 options: euler_ancestral, dpmpp_2s_ancestral, dpmpp_2m_sde, lcm
    etaFLOAT1.000โ€“10โ€”
    s_noiseFLOAT1.000โ€“10โ€”
    upscale_ratioFLOAT2.000โ€“16โ€”
    start_stepINT50โ€“1000โ€”
    end_stepINT150โ€“1000โ€”
    upscale_n_stepINT30โ€“1000โ€”
    unsharp_kernel_sizeINT31โ€“21โ€”
    unsharp_sigmaFLOAT0.500โ€“10โ€”
    unsharp_strengthFLOAT0.000โ€“10โ€”
    unsharp_targetCOMBO2 options: x, denoised

    Outputs (1)

    NameTypeDescription
    SAMPLERSAMPLERโ€”