ComfyUI Node
MD: Apply TPG (Token Perturbation)
A ComfyUI node in MD_Nodes/Optimization with 10 inputs and 2 outputs.
MD: Apply TPG (Token Perturbation)
- model
- patched_model
- debug_info
◄enable_tpgtrue►
◄target_layersDown (Encoder)►
◄perturbation_strength1.00►
◄start_sigma1000.0►
◄end_sigma0.10►
◄protect_first_tokens1►
◄split_modeUncond First (Standard)►
◄seed0►
◄debug_modeOff►
CategoryMD_Nodes/Optimization
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | MODEL INPUT • Purpose: The diffusion model to patch with TPG. • Compatibility: Works with most Unet/DiT architectures (SD1.5, SDXL, FLUX). • Output: Returns a patched model ready for sampling. | |
| enable_tpg | BOOLEAN | true | ENABLE TPG • Purpose: Master switch for the effect. • Use Case: Quickly toggle for A/B testing without rewiring nodes. ⭐ Recommended: True |
| target_layers | COMBO | Down (Encoder) | TARGET LAYERS • Purpose: Select which U-Net blocks to patch. • Options: - Down (Encoder): Best FID scores (Paper recommendation) - Mid: Affects global structure/composition - Up (Decoder): Affects fine details and textures - All: Strongest effect, may be destructive ⭐ Recommended: Down (Encoder) |
| perturbation_strength | FLOAT | 1.000–1 | PERTURBATION STRENGTH • Purpose: Controls the blend between original and shuffled tokens. • Range: 0.0 (No effect) to 1.0 (Full Shuffle). • Trade-offs: Lower values are safer but less effective at guiding. ⭐ Recommended: 1.0 (Control intensity via Sigma instead) |
| start_sigma | FLOAT | 1000.00–10000 | START SIGMA • Purpose: Noise level to START applying TPG. • Note: High value (1000+) = Start immediately at beginning of generation. • Use Case: TPG is most effective at high noise levels (structural formation). ⭐ Recommended: 1000.0 (Always on at start) |
| end_sigma | FLOAT | 0.100–1000 | END SIGMA • Purpose: Noise level to STOP applying TPG. • Use Case: Stop before 0.1 to prevent damaging fine textures. • Range: 0.0 (End of gen) to 1000.0 (Start of gen). ⭐ Recommended: 0.1 - 0.5 |
| protect_first_tokens | INT | 10–16 | PROTECT TOKENS • Purpose: Prevent shuffling of initial special tokens (like [CLS]). • Range: 0-16 tokens. • Importance: Preserves global conditioning context. ⭐ Recommended: 1 (Protects [CLS]) |
| split_mode | COMBO | Uncond First (Standard) | SPLIT MODE HEURISTIC • Purpose: How the node detects the Unconditional batch. • Options: - Standard: Assumes Uncond batch comes first (ComfyUI default) - Inverted: Use if generation looks corrupted or inverted ⭐ Recommended: Uncond First (Standard) |
| seed | INT | 00–9007199254740991 | PERMUTATION SEED • Purpose: Base seed for the token shuffle generator. • Note: Actual permutation changes every step/layer deterministically. • Range: 0 to 9,007,199,254,740,991 (JS-safe limit). ⭐ Most users: Leave random or fixed for reproducibility. |
| debug_mode | COMBO | Off | DEBUG MODE • Purpose: Console feedback level. • Options: - Off: Silent (Production) - Basic: Prints active layers/sigma info - Visual: Prints ASCII map of token shuffles (WARNING: Spammy!) ⭐ Recommended: Off |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| patched_model | MODEL | — |
| debug_info | STRING | — |