Add detailed README with SVG diagrams and Apache 2.0 license

Includes algorithm comparison, node wiring, and parameter guide
diagrams. SVGs use <picture> tags for GitHub compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 17:15:07 +01:00
parent a79c5163a1
commit 3953d97163
6 changed files with 637 additions and 0 deletions

190
LICENSE Normal file
View File

@@ -0,0 +1,190 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to the Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by the Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding any notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2025 Hang Yang, Shuwei Shi, Changhao Nan, Jingyi Yu, Lan Xu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

172
README.md Normal file
View File

@@ -0,0 +1,172 @@
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/banner.svg">
<source media="(prefers-color-scheme: light)" srcset="assets/banner.svg">
<img alt="SMC-CFG Ctrl — Sliding Mode Control for Classifier-Free Guidance" src="assets/banner.svg" width="100%">
</picture>
A ComfyUI node implementing **SMC-CFG** (Sliding Mode Control CFG) from the paper:
> **CFG-Ctrl: A Control-Theoretic Perspective on Classifier-Free Guidance**
> Hang Yang, Shuwei Shi, Changhao Nan, Jingyi Yu, Lan Xu — *CVPR 2026*
> [[Paper]](https://github.com/hanyang-21/CFG-Ctrl) [[Original Code]](https://github.com/hanyang-21/CFG-Ctrl)
Standard CFG uses a fixed linear gain that becomes unstable at high guidance scales — causing oversaturation, artifacts, and semantic drift. This node replaces that linear controller with a **nonlinear sliding mode controller** that keeps guidance stable at any CFG scale.
---
## How It Works
The paper reframes CFG as a control problem. Standard CFG is P-control (proportional control with fixed gain). SMC-CFG adds a bounded nonlinear correction that enforces convergence along an exponential sliding surface.
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/algorithm.svg">
<source media="(prefers-color-scheme: light)" srcset="assets/algorithm.svg">
<img alt="Algorithm comparison: Standard CFG vs SMC-CFG" src="assets/algorithm.svg" width="100%">
</picture>
### The math in brief
At each denoising step *t*:
```
e_t = noise_cond - noise_uncond # guidance error signal
s_t = (e_t - e_{t-1}) + λ · e_{t-1} # sliding surface
u_sw = -K · sign(s_t) # switching control (bounded)
e_corrected = e_t + u_sw # corrected guidance
v_out = v_uncond + w · e_corrected # final guided prediction
```
The correction `u_sw` is bounded to `[-K, +K]` per element — this is what prevents the unbounded growth that plagues standard CFG. The sliding surface combines the error derivative with a decayed previous error, creating a feedback loop with Lyapunov-stable convergence.
---
## Installation
### Manual
Clone into your ComfyUI `custom_nodes` directory:
```bash
cd ComfyUI/custom_nodes
git clone https://github.com/ethanfel/ComfyUI-CFG-CTRL.git
```
Restart ComfyUI. No additional dependencies required — the node only uses PyTorch (already in ComfyUI).
---
## Usage
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/node-wiring.svg">
<source media="(prefers-color-scheme: light)" srcset="assets/node-wiring.svg">
<img alt="Node wiring diagram" src="assets/node-wiring.svg" width="100%">
</picture>
1. Add the **SMC-CFG Ctrl** node (found in `sampling/custom_sampling`)
2. Connect your model loader's `MODEL` output to the node's `model` input
3. Connect the node's `MODEL` output to your KSampler's `model` input
4. Set your KSampler's CFG scale — you can push it **higher than usual** thanks to the SMC stabilization
That's it. The node patches the model's internal CFG function. It works with **KSampler**, **KSampler Advanced**, and any sampler that respects the model's CFG configuration.
---
## Parameters
<picture>
<source media="(prefers-color-scheme: dark)" srcset="assets/parameters.svg">
<source media="(prefers-color-scheme: light)" srcset="assets/parameters.svg">
<img alt="Parameter guide" src="assets/parameters.svg" width="100%">
</picture>
### `smc_cfg_lambda` — Sliding Surface Coefficient
**Default: `5.0`** | Range: `0.0 50.0`
Controls the sliding surface equation `s_t = (e_t - e_{t-1}) + λ · e_{t-1}`. Higher values weight the previous error magnitude more heavily, making the controller more aggressive about correcting accumulated guidance drift.
| Value | Behavior |
|-------|----------|
| `0.0` | Surface uses only error derivative — very gentle |
| `1.0 5.0` | Balanced correction (recommended range) |
| `> 10.0` | Aggressive — may over-constrain the generation |
### `smc_cfg_K` — Switching Gain
**Default: `0.2`** | Range: `0.0 5.0`
Bounds the correction to `[-K, +K]` per tensor element. This is the "safety clamp" that prevents instability. Think of it as how hard the controller can push back.
| Value | Behavior |
|-------|----------|
| `0.0` | No correction — equivalent to standard CFG |
| `0.1 0.3` | Subtle stabilization (recommended) |
| `> 0.5` | Strong correction — may introduce chattering artifacts |
### `warmup_steps` — No-Guidance Warmup
**Default: `0`** | Range: `0 100`
Number of initial denoising steps where guidance is completely disabled (pure conditional prediction). The model establishes rough composition and structure before the SMC controller begins steering.
| Value | Behavior |
|-------|----------|
| `0` | SMC-CFG active from the first step |
| `2 5` | Lets structure form first — can improve diversity |
| `> 10` | Long warmup — useful for experimentation |
### Quick Start Settings
For most models, start with the defaults and only adjust if needed:
```
smc_cfg_lambda = 5.0
smc_cfg_K = 0.2
warmup_steps = 0
```
These match the paper's recommended values and work well across SD 1.5, SDXL, SD3, FLUX, and Wan models.
---
## Compatibility
- Works with any model that uses CFG (SD 1.5, SDXL, SD3, FLUX, Wan, etc.)
- Compatible with **KSampler**, **KSampler Advanced**, and custom sampling workflows
- Stacks with `sampler_post_cfg_function` nodes (e.g., RescaleCFG can be used alongside)
- **Note:** Replaces the model's CFG function — only one `sampler_cfg_function` node can be active at a time. If another node also sets a custom CFG function, the last one in the chain wins.
---
## Technical Details
### How it integrates with ComfyUI
The node uses `model.clone()` + `set_model_sampler_cfg_function()` — the standard model patching pattern. It intercepts the CFG combination step without modifying model weights, conditioning, or the sampling loop itself.
### State management
The SMC algorithm requires memory of the previous step's guidance error (`e_{t-1}`). This state is held in a closure and automatically resets when a new generation starts (detected via sigma schedule discontinuity).
### Performance
The correction adds only lightweight tensor operations (`sign`, multiply, add) per denoising step. The overhead is negligible compared to the model forward pass. However, `disable_cfg1_optimization=True` is set to ensure both conditional and unconditional predictions are always computed.
---
## Citation
If you use this in your work, please cite the original paper:
```bibtex
@article{yang2025cfg,
title={CFG-Ctrl: A Control-Theoretic Perspective on Classifier-Free Guidance},
author={Yang, Hang and Shi, Shuwei and Nan, Changhao and Yu, Jingyi and Xu, Lan},
journal={arXiv preprint arXiv:2505.18727},
year={2025}
}
```
---
## License
This ComfyUI node is released under the [Apache 2.0 License](LICENSE), matching the original CFG-Ctrl repository.

87
assets/algorithm.svg Normal file
View File

@@ -0,0 +1,87 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 880 520">
<defs>
<linearGradient id="abg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#0d1117"/>
<stop offset="100%" style="stop-color:#161b22"/>
</linearGradient>
</defs>
<rect width="880" height="520" rx="12" fill="url(#abg)"/>
<!-- Title -->
<text x="440" y="38" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="20" font-weight="700" fill="#e6edf3" text-anchor="middle">Algorithm: Standard CFG vs SMC-CFG</text>
<!-- Left: Standard CFG -->
<rect x="30" y="60" width="390" height="430" rx="10" fill="#1c2333" stroke="#30363d" stroke-width="1.5"/>
<text x="225" y="90" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="16" font-weight="600" fill="#f0883e" text-anchor="middle">Standard CFG (P-Control)</text>
<!-- Step boxes - Standard -->
<rect x="55" y="110" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="75" y="127" font-family="monospace" font-size="11" fill="#7ee787">1.</text>
<text x="95" y="127" font-family="monospace" font-size="11" fill="#c9d1d9">Compute conditional prediction</text>
<text x="95" y="145" font-family="monospace" font-size="12" font-weight="600" fill="#79c0ff">v_cond = model(x_t, t, prompt)</text>
<rect x="55" y="164" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="75" y="181" font-family="monospace" font-size="11" fill="#7ee787">2.</text>
<text x="95" y="181" font-family="monospace" font-size="11" fill="#c9d1d9">Compute unconditional prediction</text>
<text x="95" y="199" font-family="monospace" font-size="12" font-weight="600" fill="#79c0ff">v_uncond = model(x_t, t, "")</text>
<rect x="55" y="218" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="75" y="235" font-family="monospace" font-size="11" fill="#7ee787">3.</text>
<text x="95" y="235" font-family="monospace" font-size="11" fill="#c9d1d9">Guidance error (fixed gain)</text>
<text x="95" y="253" font-family="monospace" font-size="12" font-weight="600" fill="#79c0ff">e_t = v_cond - v_uncond</text>
<rect x="55" y="272" width="340" height="44" rx="6" fill="#21262d" stroke="#f85149" stroke-width="1.5"/>
<text x="75" y="289" font-family="monospace" font-size="11" fill="#7ee787">4.</text>
<text x="95" y="289" font-family="monospace" font-size="11" fill="#f85149">Linear combination (can diverge!)</text>
<text x="95" y="307" font-family="monospace" font-size="12" font-weight="600" fill="#ff7b72">v_out = v_uncond + w * e_t</text>
<!-- Problem callout -->
<rect x="55" y="340" width="340" height="70" rx="6" fill="#2d1117" stroke="#f85149" stroke-width="1"/>
<text x="75" y="362" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" font-weight="600" fill="#f85149">Problem at high CFG scales:</text>
<text x="75" y="382" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#f0883e">Unbounded linear gain causes oversaturation,</text>
<text x="75" y="398" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#f0883e">artifacts, and semantic drift</text>
<!-- Right: SMC-CFG -->
<rect x="460" y="60" width="390" height="430" rx="10" fill="#1c2333" stroke="#30363d" stroke-width="1.5"/>
<text x="655" y="90" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="16" font-weight="600" fill="#7ee787" text-anchor="middle">SMC-CFG (Sliding Mode Control)</text>
<!-- Step boxes - SMC -->
<rect x="485" y="110" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="505" y="127" font-family="monospace" font-size="11" fill="#7ee787">1.</text>
<text x="525" y="127" font-family="monospace" font-size="11" fill="#c9d1d9">Same: compute v_cond, v_uncond</text>
<text x="525" y="145" font-family="monospace" font-size="12" font-weight="600" fill="#79c0ff">e_t = v_cond - v_uncond</text>
<rect x="485" y="164" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="505" y="181" font-family="monospace" font-size="11" fill="#7ee787">2.</text>
<text x="525" y="181" font-family="monospace" font-size="11" fill="#c9d1d9">Compute sliding surface</text>
<text x="525" y="199" font-family="monospace" font-size="12" font-weight="600" fill="#d2a8ff">s_t = (e_t - e_{t-1}) + lambda * e_{t-1}</text>
<rect x="485" y="218" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="505" y="235" font-family="monospace" font-size="11" fill="#7ee787">3.</text>
<text x="525" y="235" font-family="monospace" font-size="11" fill="#c9d1d9">Nonlinear switching control</text>
<text x="525" y="253" font-family="monospace" font-size="12" font-weight="600" fill="#d2a8ff">u_sw = -K * sign(s_t)</text>
<rect x="485" y="272" width="340" height="44" rx="6" fill="#21262d" stroke="#30363d"/>
<text x="505" y="289" font-family="monospace" font-size="11" fill="#7ee787">4.</text>
<text x="525" y="289" font-family="monospace" font-size="11" fill="#c9d1d9">Bounded correction</text>
<text x="525" y="307" font-family="monospace" font-size="12" font-weight="600" fill="#d2a8ff">e_corrected = e_t + u_sw</text>
<rect x="485" y="326" width="340" height="44" rx="6" fill="#21262d" stroke="#7ee787" stroke-width="1.5"/>
<text x="505" y="343" font-family="monospace" font-size="11" fill="#7ee787">5.</text>
<text x="525" y="343" font-family="monospace" font-size="11" fill="#7ee787">Stable guided output</text>
<text x="525" y="361" font-family="monospace" font-size="12" font-weight="600" fill="#7ee787">v_out = v_uncond + w * e_corrected</text>
<!-- Solution callout -->
<rect x="485" y="394" width="340" height="70" rx="6" fill="#0d2818" stroke="#238636" stroke-width="1"/>
<text x="505" y="416" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" font-weight="600" fill="#7ee787">Correction bounded to [-K, +K]:</text>
<text x="505" y="436" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#56d364">Prevents divergence at any CFG scale.</text>
<text x="505" y="452" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#56d364">Lyapunov-stable finite-time convergence.</text>
<!-- Arrow between panels -->
<path d="M 425 275 L 455 275" stroke="#484f58" stroke-width="2" fill="none" marker-end="url(#arrowhead)"/>
<defs>
<marker id="arrowhead" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto">
<polygon points="0 0, 8 3, 0 6" fill="#484f58"/>
</marker>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 6.4 KiB

18
assets/banner.svg Normal file
View File

@@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 200">
<defs>
<linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#1a1a2e"/>
<stop offset="50%" style="stop-color:#16213e"/>
<stop offset="100%" style="stop-color:#0f3460"/>
</linearGradient>
<linearGradient id="accent" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#e94560"/>
<stop offset="100%" style="stop-color:#533483"/>
</linearGradient>
</defs>
<rect width="900" height="200" rx="12" fill="url(#bg)"/>
<rect x="0" y="185" width="900" height="15" rx="0 0 12 12" fill="url(#accent)" opacity="0.8"/>
<text x="450" y="75" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="48" font-weight="700" fill="#ffffff" text-anchor="middle">SMC-CFG Ctrl</text>
<text x="450" y="115" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="20" fill="#a0a0c0" text-anchor="middle">Sliding Mode Control for Classifier-Free Guidance</text>
<text x="450" y="150" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="15" fill="#707090" text-anchor="middle">ComfyUI Node | Based on CFG-Ctrl (CVPR 2026)</text>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

87
assets/node-wiring.svg Normal file
View File

@@ -0,0 +1,87 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 860 320">
<defs>
<linearGradient id="wbg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#0d1117"/>
<stop offset="100%" style="stop-color:#161b22"/>
</linearGradient>
</defs>
<rect width="860" height="320" rx="12" fill="url(#wbg)"/>
<text x="430" y="32" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="18" font-weight="700" fill="#e6edf3" text-anchor="middle">Node Wiring in ComfyUI</text>
<!-- Node 1: Checkpoint Loader -->
<rect x="30" y="70" width="180" height="100" rx="8" fill="#1c2333" stroke="#30363d" stroke-width="1.5"/>
<rect x="30" y="70" width="180" height="28" rx="8" fill="#2d333b"/>
<rect x="30" y="90" width="180" height="8" fill="#2d333b"/>
<text x="120" y="89" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" font-weight="600" fill="#e6edf3" text-anchor="middle">Load Checkpoint</text>
<!-- Output dot -->
<circle cx="210" cy="120" r="6" fill="#79c0ff" stroke="#1c2333" stroke-width="2"/>
<text x="120" y="120" font-family="monospace" font-size="10" fill="#8b949e" text-anchor="middle">MODEL</text>
<circle cx="210" cy="145" r="6" fill="#d2a8ff" stroke="#1c2333" stroke-width="2"/>
<text x="140" y="145" font-family="monospace" font-size="10" fill="#8b949e" text-anchor="middle">CLIP</text>
<!-- Wire: Checkpoint -> SMC-CFG Ctrl -->
<path d="M 216 120 C 260 120, 260 120, 300 120" stroke="#79c0ff" stroke-width="2.5" fill="none"/>
<!-- Node 2: SMC-CFG Ctrl (highlighted) -->
<rect x="300" y="55" width="220" height="195" rx="8" fill="#1c2333" stroke="#e94560" stroke-width="2"/>
<rect x="300" y="55" width="220" height="28" rx="8" fill="#3d1a2e"/>
<rect x="300" y="75" width="220" height="8" fill="#3d1a2e"/>
<text x="410" y="74" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" font-weight="700" fill="#ff7b72" text-anchor="middle">SMC-CFG Ctrl</text>
<!-- Input dot -->
<circle cx="300" cy="120" r="6" fill="#79c0ff" stroke="#1c2333" stroke-width="2"/>
<text x="365" y="108" font-family="monospace" font-size="10" fill="#8b949e" text-anchor="middle">model</text>
<!-- Parameters -->
<rect x="315" y="120" width="190" height="22" rx="4" fill="#21262d"/>
<text x="325" y="135" font-family="monospace" font-size="10" fill="#d2a8ff">smc_cfg_lambda</text>
<text x="490" y="135" font-family="monospace" font-size="10" fill="#7ee787" text-anchor="end">5.0</text>
<rect x="315" y="148" width="190" height="22" rx="4" fill="#21262d"/>
<text x="325" y="163" font-family="monospace" font-size="10" fill="#d2a8ff">smc_cfg_K</text>
<text x="490" y="163" font-family="monospace" font-size="10" fill="#7ee787" text-anchor="end">0.2</text>
<rect x="315" y="176" width="190" height="22" rx="4" fill="#21262d"/>
<text x="325" y="191" font-family="monospace" font-size="10" fill="#d2a8ff">warmup_steps</text>
<text x="490" y="191" font-family="monospace" font-size="10" fill="#7ee787" text-anchor="end">0</text>
<!-- Output dot -->
<circle cx="520" cy="120" r="6" fill="#79c0ff" stroke="#1c2333" stroke-width="2"/>
<text x="470" y="220" font-family="monospace" font-size="10" fill="#8b949e" text-anchor="middle">MODEL</text>
<!-- Wire: SMC-CFG -> KSampler -->
<path d="M 526 120 C 570 120, 570 120, 610 120" stroke="#79c0ff" stroke-width="2.5" fill="none"/>
<!-- Node 3: KSampler -->
<rect x="610" y="55" width="220" height="220" rx="8" fill="#1c2333" stroke="#30363d" stroke-width="1.5"/>
<rect x="610" y="55" width="220" height="28" rx="8" fill="#2d333b"/>
<rect x="610" y="75" width="220" height="8" fill="#2d333b"/>
<text x="720" y="74" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" font-weight="600" fill="#e6edf3" text-anchor="middle">KSampler</text>
<!-- Input dot -->
<circle cx="610" cy="120" r="6" fill="#79c0ff" stroke="#1c2333" stroke-width="2"/>
<text x="670" y="108" font-family="monospace" font-size="10" fill="#8b949e" text-anchor="middle">model</text>
<!-- KSampler params -->
<rect x="625" y="120" width="190" height="22" rx="4" fill="#21262d"/>
<text x="635" y="135" font-family="monospace" font-size="10" fill="#8b949e">steps</text>
<text x="800" y="135" font-family="monospace" font-size="10" fill="#7ee787" text-anchor="end">20</text>
<rect x="625" y="148" width="190" height="22" rx="4" fill="#21262d"/>
<text x="635" y="163" font-family="monospace" font-size="10" fill="#f0883e">cfg</text>
<text x="800" y="163" font-family="monospace" font-size="10" fill="#f0883e" text-anchor="end">7.5</text>
<rect x="625" y="176" width="190" height="22" rx="4" fill="#21262d"/>
<text x="635" y="191" font-family="monospace" font-size="10" fill="#8b949e">sampler</text>
<text x="800" y="191" font-family="monospace" font-size="10" fill="#7ee787" text-anchor="end">euler</text>
<rect x="625" y="204" width="190" height="22" rx="4" fill="#21262d"/>
<text x="635" y="219" font-family="monospace" font-size="10" fill="#8b949e">scheduler</text>
<text x="800" y="219" font-family="monospace" font-size="10" fill="#7ee787" text-anchor="end">normal</text>
<!-- Positive/Negative conditioning wires (from off-screen) -->
<circle cx="610" cy="145" r="6" fill="#d2a8ff" stroke="#1c2333" stroke-width="2"/>
<circle cx="610" cy="170" r="6" fill="#d2a8ff" stroke="#1c2333" stroke-width="2"/>
<!-- Legend -->
<text x="430" y="300" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#484f58" text-anchor="middle">Insert the SMC-CFG Ctrl node between your model loader and sampler. Use higher CFG scales than usual.</text>
</svg>

After

Width:  |  Height:  |  Size: 5.5 KiB

83
assets/parameters.svg Normal file
View File

@@ -0,0 +1,83 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 860 440">
<defs>
<linearGradient id="pbg" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#0d1117"/>
<stop offset="100%" style="stop-color:#161b22"/>
</linearGradient>
</defs>
<rect width="860" height="440" rx="12" fill="url(#pbg)"/>
<text x="430" y="35" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="20" font-weight="700" fill="#e6edf3" text-anchor="middle">Parameter Guide</text>
<!-- Lambda -->
<rect x="30" y="55" width="390" height="165" rx="10" fill="#1c2333" stroke="#d2a8ff" stroke-width="1.5"/>
<text x="50" y="82" font-family="monospace" font-size="15" font-weight="700" fill="#d2a8ff">smc_cfg_lambda</text>
<text x="380" y="82" font-family="monospace" font-size="13" fill="#7ee787" text-anchor="end">default: 5.0</text>
<text x="50" y="108" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">Sliding surface coefficient. Controls how aggressively the</text>
<text x="50" y="124" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">controller corrects accumulated guidance errors.</text>
<!-- Lambda scale -->
<rect x="50" y="145" width="350" height="8" rx="4" fill="#21262d"/>
<rect x="50" y="145" width="35" height="8" rx="4" fill="#56d364"/>
<rect x="85" y="145" width="140" height="8" fill="#f0883e"/>
<rect x="225" y="145" width="175" height="8" rx="0 4 4 0" fill="#f85149"/>
<text x="50" y="170" font-family="monospace" font-size="10" fill="#56d364">0</text>
<text x="155" y="170" font-family="monospace" font-size="10" fill="#f0883e" text-anchor="middle">5.0 (sweet spot)</text>
<text x="400" y="170" font-family="monospace" font-size="10" fill="#f85149" text-anchor="end">50</text>
<text x="50" y="195" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#7ee787">Low: gentle, preserves original CFG behavior</text>
<text x="50" y="210" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#f85149">High: aggressive correction, may over-constrain</text>
<!-- K -->
<rect x="440" y="55" width="390" height="165" rx="10" fill="#1c2333" stroke="#79c0ff" stroke-width="1.5"/>
<text x="460" y="82" font-family="monospace" font-size="15" font-weight="700" fill="#79c0ff">smc_cfg_K</text>
<text x="790" y="82" font-family="monospace" font-size="13" fill="#7ee787" text-anchor="end">default: 0.2</text>
<text x="460" y="108" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">Switching gain. Bounds the per-element correction</text>
<text x="460" y="124" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">magnitude to [-K, +K]. Think of it as a safety clamp.</text>
<!-- K scale -->
<rect x="460" y="145" width="350" height="8" rx="4" fill="#21262d"/>
<rect x="460" y="145" width="15" height="8" rx="4" fill="#56d364"/>
<rect x="475" y="145" width="90" height="8" fill="#f0883e"/>
<rect x="565" y="145" width="245" height="8" rx="0 4 4 0" fill="#f85149"/>
<text x="460" y="170" font-family="monospace" font-size="10" fill="#56d364">0</text>
<text x="505" y="170" font-family="monospace" font-size="10" fill="#f0883e" text-anchor="middle">0.2</text>
<text x="810" y="170" font-family="monospace" font-size="10" fill="#f85149" text-anchor="end">5.0</text>
<text x="460" y="195" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#7ee787">Low: subtle correction, smooth results</text>
<text x="460" y="210" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#f85149">High: strong correction, may cause chattering</text>
<!-- Warmup -->
<rect x="30" y="240" width="390" height="175" rx="10" fill="#1c2333" stroke="#f0883e" stroke-width="1.5"/>
<text x="50" y="267" font-family="monospace" font-size="15" font-weight="700" fill="#f0883e">warmup_steps</text>
<text x="380" y="267" font-family="monospace" font-size="13" fill="#7ee787" text-anchor="end">default: 0</text>
<text x="50" y="293" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">Initial denoising steps with NO guidance at all.</text>
<text x="50" y="309" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">Pure conditional prediction. Lets the model establish</text>
<text x="50" y="325" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="12" fill="#8b949e">rough structure before guidance corrects direction.</text>
<!-- Timeline -->
<rect x="50" y="350" width="350" height="20" rx="4" fill="#21262d"/>
<rect x="50" y="350" width="70" height="20" rx="4" fill="#2d333b" stroke="#f0883e" stroke-width="1"/>
<rect x="120" y="350" width="280" height="20" rx="0 4 4 0" fill="#0d2818" stroke="#238636" stroke-width="1"/>
<text x="85" y="364" font-family="monospace" font-size="9" fill="#f0883e" text-anchor="middle">warmup</text>
<text x="260" y="364" font-family="monospace" font-size="9" fill="#7ee787" text-anchor="middle">SMC-CFG active</text>
<text x="50" y="393" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#8b949e">Typical: 0-5 steps. Try 2-3 for more diverse compositions.</text>
<!-- CFG Scale recommendations -->
<rect x="440" y="240" width="390" height="175" rx="10" fill="#1c2333" stroke="#7ee787" stroke-width="1.5"/>
<text x="460" y="267" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="15" font-weight="700" fill="#7ee787">Recommended CFG Scales</text>
<text x="460" y="295" font-family="monospace" font-size="12" fill="#c9d1d9">Model CFG Scale</text>
<rect x="460" y="302" width="350" height="1" fill="#30363d"/>
<text x="460" y="322" font-family="monospace" font-size="12" fill="#79c0ff">SD 1.5 / SDXL 7.0 - 12.0</text>
<text x="460" y="344" font-family="monospace" font-size="12" fill="#79c0ff">SD3 / SD3.5 7.5</text>
<text x="460" y="366" font-family="monospace" font-size="12" fill="#79c0ff">FLUX.1-dev 2.0 - 3.0</text>
<text x="460" y="388" font-family="monospace" font-size="12" fill="#79c0ff">Wan 2.1/2.2 5.0</text>
<text x="460" y="408" font-family="Segoe UI, Helvetica, Arial, sans-serif" font-size="11" fill="#8b949e">SMC-CFG lets you push CFG higher than usual</text>
</svg>

After

Width:  |  Height:  |  Size: 6.2 KiB