Nodes/ComfyUI-Apt_Preset/UC_Ksampler_refine
ComfyUI Node

UC_Ksampler_refine

Upscale and re-sample in one node, at the denoise that actually helps

By cardenluo·Created 2 years ago·Updated about 15 hours ago· 334
UC_Ksampler_refine
  • context
  • image
  • context
  • image
model_nameRealESRGAN_x2.pth
upscale_output_scale1.00
seed0
denoise0.30
tile_sizeNone:不分块
sample_parametersfalse
steps8
cfg1.00
samplereuler
schedulersimple

Hi-res fix in ComfyUI is normally four nodes and a decision: upscale the image or the latent, then re-sample at a denoise low enough not to invent a new picture. UC_Ksampler_refine folds the sequence into one node off a context - pixel upscale, optional resample, decode - which makes the fiddly part (the denoise value) the main thing you're thinking about instead of the wiring.

It sits under Apt_Preset/unit_context, and it's the "special function sampler" the pack's README means when it talks about "secondary sampling repair and refine enlargement in one step".

What it does, in order

One: it pulls model, VAE, CLIP, conditioning, latent and any images out of the incoming context, and errors clearly if the context is missing the pieces - UC_Ksampler_refine context is missing: model, vae is a message you'll meet. Two: it loads model_name from your upscale_models folder and runs it over the image, which comes from the image socket, or from images already in the context, or from decoding the context's latent as a last resort. Three: it resamples to upscale_output_scale if you've asked for a size other than the upscaler's native output, rounded to multiples of 8. Four: it encodes the result back to latent and runs a real sampler pass at your denoise. Five: decode, and return the image plus an updated context.

The upscaling happens in pixel space and the polish happens in latent space, which is why this is better than latent upscaling alone: an ESRGAN-family model contributes actual resolution structure, then a short denoise pass cleans up the resampling artifacts and re-establishes texture. Keep the denoise low and it's a cleanup; push it up and it's a re-generation of your picture with a suggestion from the original.

Inputs worth setting

  • model_name - any file in ComfyUI/models/upscale_models. RealESRGAN x2 is the source default, and a 2x model is usually the right pick because you're going to add a coefficient on top.
  • upscale_output_scale - the tooltip states the maths exactly: final magnification = model factor × this coefficient. Range 0.1–10, so a 2x model at 2.0 gives you 4x total.
  • denoise - 0.3 by default and 0.3 is right. This is the dial that decides whether you refined an image or replaced it.
  • tile_size - latent tiling for the refine pass, 12 presets from no tiling to 极限省显存:8 | 64 (extreme VRAM saving: 8 tiles, 64px). Tiling is the difference between "4x" and "4x that fits on your card"; the cost is seams if you tile aggressively at a high denoise.
  • sample_parameters - the inheritance toggle. Off, the refine pass uses the steps/cfg/sampler/scheduler from the context. On, it uses the four optional widgets on this node. Same trap as everywhere else in this pack: with it off, changing the steps box does nothing.
  • image - optional. Wire it if you want to refine something other than what's in the context.

Outputs: context (with the refined latent and image written back, so you can chain another pass) and image.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset
cd ComfyUI-Apt_Preset
pip install -r requirements.txt

Restart, then search Apt_Preset in Manager or browse to Apt_Preset/unit_context. You need an upscaler model in models/upscale_models - the pack doesn't ship one, and the node's dropdown is empty until you put something there.

Where it goes wrong

The classic failure is memory, and it's arithmetic, not configuration. The refine pass sees the upscaled resolution, so a 1024px render with a 2x model at 2.0 coefficient is a 4096px sampling pass. If it OOMs, fix the scale before you touch anything else - then tile, then consider a smaller model.

Second: the default CFG comes from whatever's in the context unless you flip sample_parameters. Contexts built for distilled models carry CFG 1, which is correct for those and produces a flat, dead refine on an SDXL checkpoint. If your refined result looks washed out rather than noisy, check the cfg you're actually sampling at.

Third, expectations. At denoise 0.3 this adds the detail implied by your upscaler and cleans edges; it does not invent new texture. For a genuinely soft source, the honest answer is a heavier second pass or a generative upscaler built for damage repair - that's a different tool with a different price.

CategoryApt_Preset/unit_context

Inputs (12)

NameTypeDefaultDescription
contextRUN_CONTEXT
model_nameCOMBORealESRGAN_x2.pth0 options:
upscale_output_scaleFLOAT1.000.1–10最终放大倍数 = 模型倍数X系数
seedINT00–18446744073709550000
denoiseFLOAT0.300–1
tile_sizeCOMBONone:不分块按分块数量和重叠像素进行 latent 分块采样。
sample_parametersBOOLEANfalse继承context时使用上游采样参数;自定义时使用下方四项参数
imageoptIMAGE
stepsoptINT80–10000
cfgoptFLOAT1.000–100
sampleroptCOMBOeuler45 options: None, euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, +39
scheduleroptCOMBOsimple10 options: None, simple, sgm_uniform, karras, exponential, ddim_uniform, +4

Outputs (2)

NameTypeDescription
contextRUN_CONTEXT
imageIMAGE