Nodes/DistanceSampler/SamplerDistance
ComfyUI Node

SamplerDistance

The slow sampler that exists to kill body horror

By Extraltodeus·Created 2 years ago·Updated about a year ago· 44
SamplerDistance
    • SAMPLER
    resample3
    resample_end-1
    cfgpptrue

    If you've ever gotten an image back with a person whose face has fused into someone else's face, you know the failure mode this sampler is built for. DistanceSampler is a custom sampling algorithm from Extraltodeus (the same person behind the old depthmap2mask extension) that spends extra compute on the start of denoising - when the image's structure is actually being decided - so it can stop predictions from merging into each other. The pitch is honestly unusual for a sampler: it claims less body horror and merged people at 4–10 steps than DPM++ 2M manages at 20–30, and it can even sample simple subjects at CFG 1 with guidance basically off.

    The catch: it's slow, because each step runs the model several times. The README's advice is to stop fighting that and just use 7 steps with the beta or AYS scheduler instead of cranking step counts up. A quality-first, patience-required trade.

    How it works

    Think of Heun's method: take a step, check where you landed, correct the direction. DistanceSampler takes that idea and runs it ragged. At each step it makes several candidate predictions, then combines them not by simple averaging but by proximity weighting - each candidate is normalized onto a unit sphere, the pairwise distances between all candidates are measured, and the ones that agree with each other (smaller distances) get more weight. The resample input literally is "how many of these internal re-predictions to run." The heavy lifting happens early in the schedule, then it eases down to a plain Heun finish at the end, which is why the first steps feel slow and the last ones don't.

    The node's own tooltip is the honest summary: 0 all along gives Euler. 1 gives Heun. Anything starting from 2 will use the distance method. So this isn't a brand-new equation - it's a Heun-style predictor-corrector with extra correctors, fused by a distance heuristic.

    The three inputs that matter

    This is the simple version of the node, and honestly it's the one a beginner should use. It exposes exactly three things:

    • resample (default 3) - how many internal model calls per step. Higher = better but slower. -1 dynamically uses "remaining steps + 1," capped at 10, which can be very slow. Leave it at 3.
    • resample_end (default -1) - how many resamples to use at the end of the schedule. -1 means constant, i.e. keep 3 resamples every step, which is the slowest possible config. Set it to 1 to taper down to Heun like the pack's ready-made "Distance" preset does.
    • cfgpp (default true) - whether to use CFG++ sampling. CFG++ reframes guidance around the unconditional prediction rather than the conditional one, and it's designed for low guidance scales. The tooltip is blunt: when it's on, set your CFG to a fairly low value. There's a subtle catch worth knowing: normally at CFG 1 ComfyUI skips the unconditional pass entirely (it can't affect the result), but CFG++ needs that pass, so this sampler forces it to run. That's why "CFG 1" under this sampler isn't the free half-price CFG 1 you're used to.

    That's the whole input surface. The node outputs a single SAMPLER, which you wire into the sampler input of a SamplerCustomAdvanced (or SamplerCustom) node - you still pick a scheduler there yourself, beta or AYS being the pack's recommendation.

    Installing it

    Install once via ComfyUI Manager (search "DistanceSampler"), or the old-fashioned way:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Extraltodeus/DistanceSampler
    # restart ComfyUI
    

    Two nice things: there are no model downloads and no Python dependencies - it's pure Python that registers samplers when it loads. You also get extra sampler names (Distance, Distance_n, Distance_p, euler_cfg_pp_alt, heun_cfg_pp) dropped into every standard KSampler's sampler dropdown as a bonus.

    Where people get burned

    • Tensor shape errors. The README's documented compatibility issue: if you hit shape mismatches, the slerp-based combination at the end is the culprit. Uncomment the two Distance_fast lines in presets_to_add.py to switch the end to a plain weighted average - barely noticeable, per the author.
    • Expecting a speed sampler. It is not - swap it in at your usual 25 steps and it'll take forever. The point is fewer steps, not more.
    • CFG++ defaults. The node ships cfgpp on by default, so it expects a low CFG. Try it at 7 like a normal SDXL sampler and it'll look wrong - that's the setting, not the sampler.
    Categorysampling/custom_sampling/samplers

    Inputs (3)

    NameTypeDefaultDescription
    resampleINT3-1–320 all along gives Euler. 1 gives Heun. Anything starting from 2 will use the distance method. -1 will do remaining steps + 1 as the resample value. This can be pretty slow.
    resample_endINT-1-1–32How many resamples for the end. -1 means constant.
    cfgppBOOLEANtrueControls whether to use CFG++ sampling. When enabled, you should set CFG to a fairly low value.

    Outputs (1)

    NameTypeDescription
    SAMPLERSAMPLER