ComfyUI Extension: ComfyUI-CFG-Ctrl
Run ComfyUI workflows without the setup
No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.
A ComfyUI custom node implementing CFG-Ctrl / SMC-CFG as a GUIDER.
README
ComfyUI-CFG-Ctrl (SMC-CFG)
Implements CFG-Ctrl / SMC-CFG (Sliding Mode Control CFG) as a ComfyUI GUIDER.
References:
- Paper: "CFG-Ctrl: Control-Based Classifier-Free Diffusion Guidance"
- Official repo: hanyang-21/CFG-Ctrl
Install
Place this folder into:
ComfyUI/custom_nodes/ComfyUI-CFG-Ctrl/
Restart ComfyUI.
How to use
This node outputs a GUIDER. Use it with ComfyUI custom sampling nodes that accept GUIDER input
(for example SamplerCustom / SamplerCustomAdvanced).
Steps:
- Create your model + conditioning (positive/negative) as usual.
- Add
CFG-Ctrl / SMC-CFG Guiderand connect model/positive/negative. - Feed the
GUIDERinto your custom sampler node.
Implementation notes
- The guider prefers a
sampler_cfg_functionhook so it can compute the final guided denoised tensor directly. This avoids the extra numeric round trip of encoding the corrected guidance back intocondand letting ComfyUI subtractuncondagain. - If another node has already installed a
sampler_cfg_function, this node falls back to asampler_pre_cfg_functionso it does not clobber the existing hook. - Logical step counting is based on sigma changes, not raw model-call count. This makes warmup and step windows track the denoising schedule more closely across different samplers.
active_start_percent/active_end_percentare converted throughmodel_sampling.percent_to_sigma(...)when available, so you can gate the controller by denoising progress in a sampler-independent way.
Parameters
-
cfg: Standard CFG scale. -
smc_lambda: Sliding-surface shaping. The paper reports values around6for its selected settings. -
smc_k: Switching gain. This is strongly model-dependent in the paper and examples. The node default (0.3) is a generic starter value, not a claimed paper-optimal default for every model. -
no_cfg_warmup_steps: FirstNlogical sampling steps output the pure conditional prediction directly. This is not "unconditional"; it is simply conditional-only warmup with no CFG mixing. -
active_start_step/active_end_step: Optional logical-step window. Logical steps are tracked from sigma changes, so this is more stable than raw denoiser call counts. -
active_start_percent/active_end_percent: Optional denoising-progress window in[0, 1]. This is usually the more portable way to gate the controller across samplers and schedules. -
switch_mode:sign: paper / official repo behaviorsat/tanh: smooth boundary-layer variants to reduce chatteringvector_norm: normalized vector controller per batch item
-
boundary_epsilon: Used bysat,tanh, andvector_norm. -
epsilon_mode:absolute: fixed epsilonrelative: epsilon scales with mean|s|per batch item instead of one global batch-wide scalar
-
apply_only_if_cfg_gt_1: Optional compatibility toggle. Off by default so the node does not silently disable itself atcfg <= 1. -
reset_on_shape_change: Resets controller memory if latent shape or device changes mid-run. -
detach_prev: Stores the previous corrected guidance as a detached tensor.
Practical defaults (starting points)
- Generic default:
lambda=6.0,k=0.3,switch_mode=sign - FLUX-like flow models often tolerate higher
k - If you see chattering or overshoot, try
tanhorsatwithboundary_epsilonaround1e-3 .. 1e-2 - If you want sampler-independent activation windows, prefer
active_start_percent/active_end_percent
Run ComfyUI workflows without the setup
No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.