ComfyUI-DyPE/SEGA
A ComfyUI custom node that implements DyPE (Dynamic Position Extrapolation) and SEGA (Spectral-Energy Guided Attention), enabling Diffusion Transformers (like FLUX, Qwen Image, Z-Image, Anima/Cosmos, and Krea-2) to generate ultra-high-resolution images (4K and beyond) with exceptional coherence and detail.
Report Bug
·
Request Feature
About The Project
DyPE is a training-free method that allows pre-trained DiT models to generate images at resolutions far beyond their training data, with no additional sampling cost.
It works by taking advantage of the spectral progression inherent to the diffusion process. By dynamically adjusting the model's positional encodings at each step, DyPE matches their frequency spectrum with the current stage of the generative process—focusing on low-frequency structures early on and resolving high-frequency details in later steps. This prevents the repeating artifacts and structural degradation typically seen when pushing models beyond their native resolution.
A simple, single-node integration to patch your model for high-resolution generation.
This node provides a seamless, "plug-and-play" integration of DyPE into your workflow.
✨ Key Features:
- Multi-Architecture Support: Supports FLUX (Standard), Nunchaku (Quantized Flux), Qwen Image, Z-Image (Lumina 2), Anima/Cosmos, and Krea-2.
- High-Resolution Generation: Push models to 4096x4096 and beyond.
- Single-Node Integration: Simply place the
DyPE for FLUXnode after your model loader to patch the model. No complex workflow changes required. - Full Compatibility: Works seamlessly with your existing ComfyUI workflows, samplers, schedulers, and other optimization nodes.
- Fine-Grained Control: Exposes key DyPE hyperparameters, allowing you to tune the algorithm's strength and behavior for optimal results at different target resolutions.
- Zero Inference Overhead: DyPE's adjustments happen on-the-fly with negligible performance impact.
Example output
SEGA Node
SEGA (Spectral-Energy Guided Attention) — content-aware per-dimension RoPE mscale from the latent's FFT spectrum. Use as an alternative to DyPE for FLUX/Qwen. For Anima, use DyPE vision_yarn instead.
Usage
- Add the SEGA node after your model loader
- Set width/height to match your latent
- Use
method: sega(default) ormethod: ntk(NTK only, no spectral) - Tune
mscale_alpha(amplitude) andspread_min/spread_max(spectral gate range)
Parameters
| Parameter | Default | Description |
|---|---|---|
method | sega | sega = NTK + spectral mscale, ntk = NTK only |
mscale_alpha | 0.15 | Spectral redistribution amplitude |
mscale_beta | 1.5 | tanh sharpness |
mscale_min | 1.0 | Floor for per-frequency mscale |
spread_min | 0.0 | Min spectral spread (early steps) |
spread_max | 1.0 | Max spectral spread (late steps) |
spread_alpha | 1.5 | Spread schedule non-linearity |
base_mscale_formula | power_res | power_res: s^κ, log_res: 1+κ·ln(s) |
base_mscale_coefficient | 0.08 | κ (paper default) |
Note: SEGA uses NTK as its base extrapolation. It refines NTK with per-dimension spectral mscale. If NTK doesn't work for your model (e.g. Anima), SEGA won't either — use DyPE
vision_yarninstead.
Getting Started
The easiest way to install is via ComfyUI Manager. Search for ComfyUI-DyPE and click "Install".
Alternatively, to install manually:
-
Clone the Repository:
Navigate to your
ComfyUI/custom_nodes/directory and clone this repository:git clone https://github.com/wildminder/ComfyUI-DyPE.git -
Start/Restart ComfyUI: Launch ComfyUI. No further dependency installation is required.
🛠️ Usage
Using the node is straightforward and designed for minimal workflow disruption.
- Load Your Model: Use your preferred loader (e.g.,
Load Checkpointfor Flux,Nunchaku Flux DiT Loader,ZImageloader, or the Anima/Krea-2 UNET loaders). - Add the DyPE Node: Add the
DyPE for FLUXnode to your graph (found undermodel_patches/unet). - Connect the Model: Connect the
MODELoutput from your loader to themodelinput of the DyPE node. - Set Resolution: Set the
widthandheighton the DyPE node to match the resolution of yourEmpty Latent Image. - Connect to KSampler: Use the
MODELoutput from the DyPE node as the input for yourKSampler. - Generate! That's it. Your workflow is now DyPE-enabled.
[!NOTE] This node specifically patches the diffusion model (UNet) positional embeddings. It does not modify the CLIP or VAE models.
Node Inputs
1. Model Configuration
model_type:auto: Attempts to automatically detect the model architecture. Recommended.flux: Forces Standard Flux logic.nunchaku: Forces Nunchaku (Quantized Flux) logic.qwen: Forces Qwen Image logic (also used for Krea-2, which shares the Qwen architecture).zimage: Forces Z-Image (Lumina 2) logic.anima: Forces Anima/Cosmos logic.
base_resolution: The native resolution the model was trained on.- Flux / Z-Image:
1024 - Qwen / Krea-2:
1328(Recommended setting for Qwen-family models) - Anima/Cosmos:
1920(nativemax_imgis 240 latent = 1920px; auto-detected from the model)
- Flux / Z-Image:
2. Method Selection
method:vision_yarn: A novel variant designed specifically for aspect-ratio robustness. It decouples structure from texture: low frequencies (shapes) are scaled to fit your canvas aspect ratio, while high frequencies (details) are scaled uniformly. It uses a dynamic attention schedule to ensure sharpness.yarn: The standard YaRN method. Good general performance but can struggle with extreme aspect ratios.ntk: Neural Tangent Kernel scaling. Very stable but tends to be softer/blurrier at high resolutions.pi: Position Interpolation. Scales positions uniformly (pos / s^κ(t)) with a time-dependent exponent. Preserves local structure well; a good alternative whenntkover-smooths.base: No positional interpolation (standard behavior).
Scaling Options
yarn_alt_scaling(Only affectsyarnmethod):- Anisotropic (High-Res): Scales Height and Width independently. Can cause geometric stretching if the aspect ratio differs significantly from the training data.
- Isotropic (Stable Default): Scales both dimensions based on the largest axis. .
- Note:
vision_yarnautomatically handles this balance internally, so this switch is ignored whenvision_yarnis selected.
[!TIP] Z-Image (Lumina 2) Specifics:
- Z-Image models use a very low RoPE base frequency (
theta=256).- Geometric Stretching: To prevent vertical stretching, the node automatically enforces Isotropic Scaling for Z-Image, regardless of user settings.
- Method Choice: recommend
vision_yarnorntk. Standardyarnmay produce artifacts.
[!TIP] Anima/Cosmos Specifics:
- The native patch grid and per-axis NTK factors are read from the model, so DyPE only extrapolates beyond the native 1920px training resolution.
- Method Choice:
vision_yarnis recommended. Other methods may produce speckle noise at ultra-high resolutions (>2K).
3. Dynamic Control
enable_dype: Enables or disables the dynamic, time-aware component of DyPE.- Enabled (True): Both the noise schedule and RoPE will be dynamically adjusted throughout sampling. This is the full DyPE algorithm.
- Disabled (False): The node will only apply the dynamic noise schedule shift. The RoPE will use static extrapolation.
dype_scale: (λs) Controls the "magnitude" of the DyPE modulation. Default is2.0.dype_exponent: (λt) Controls the "strength" of the dynamic effect over time.2.0: Recommended for 4K+ resolutions. Aggressive schedule that transitions quickly to clean up artifacts.1.0: Good starting point for ~2K-3K resolutions.0.5: Gentler schedule for resolutions just above native.
4. Advanced Noise Scheduling
base_shift/max_shift: These parameters control the Noise Schedule Shift (mu). In this implementation,max_shift(Default 1.15) acts as the target shift for any resolution larger than the base.
Changelog
v2.5.0
- SEGA Node: Added SEGA (Spectral-Energy Guided Attention) — a new node that computes per-RoPE-dimension mscale from the latent's Fourier spectrum at each denoising step. Content-aware attention sharpening for FLUX/Qwen. Uses NTK as base extrapolation with per-dim spectral refinement.
- 5D Latent Support: SEGA wrapper handles both 4D
(B,C,H,W)and 5D(B,C,T,H,W)latents for video models. - Native Patch Grid: SEGA reads Anima's native
max_img_h/patch_spatialfor correct scale computation.
v2.4.0
- Anima/Cosmos Support: Added support for Anima/Cosmos models. Reads the model's native per-axis NTK factors and patch grid (
max_img_h/w,patch_spatial) so DyPE only extrapolates beyond native resolution. Recommended method:vision_yarn. - Krea-2 Support: Added support for Krea-2 (Qwen-family architecture, auto-detected).
- State Pollution Fix: Patch parameters are now cached on the
ModelPatcherto avoid re-patching and state leakage across runs. - Example Workflows: Added Anima and Krea-2 example workflows.
v2.3.0
- Z-Image Overhaul: Fixed geometric stretching artifacts
- Method Fixes
v2.2.0
- Z-Image Support: Added experimental support for Z-Image (Lumina 2) architecture.
v2.1.0
- New Architecture Support: Added support for Qwen Image and Nunchaku (Quantized Flux) models.
- Modular Architecture: Refactored codebase into a modular adapter pattern (
src/models/) to ensure stability and easier updates for future models. - UI Updates: Added
model_typeselector for explicit model definition.
v2.0.0
- Vision-YaRN: Introduced the
vision_yarnmethod for decoupled aspect-ratio handling. - Dynamic Attention: Implemented quadratic decay schedule for
mscaleto balance sharpness and artifacts. - Start Sigma: Added
dype_start_sigmacontrol.
v1.0.0
- Initial Release: Core DyPE implementation for Standard Flux models.
- Basic Modes: Support for
yarn(Isotropic/Anisotropic) andntk.
❗ Important Notes & Best Practices
[!IMPORTANT] Limitations at Extreme Resolutions (4K) While DyPE significantly extends the capabilities of DiT models, generating perfectly clean 4096x4096 images is still a limitation of the base model itself. Even with DyPE, you are pushing a model trained on ~1 megapixel to generate 16 megapixels. You may still encounter minor artifacts at these extreme scales.
[!TIP] Dealing with Speckle Noise At extreme resolutions (4K+), you may notice high-frequency "speckle" noise in focused areas (e.g., hair, eyes). This is a side effect of scaling the model's attention mechanism beyond its training limits.
How to fix:
- Increase
dype_exponent: Try raising this to3.0or4.0or any other higher values.- Use LoRAs: Smoothing or "Detailer" LoRAs can help suppress high-frequency artifacts.
[!TIP] Experimentation is Required There is no single "magic setting" that works for every prompt and every resolution. To achieve the best results:
- Test different Methods: Start with
vision_yarn, but tryyarnif you encounter issues.- Adjust
dype_exponent: This is your main knob for balancing sharpness vs. artifacts.
Acknowledgments
- Noam Issachar, Guy Yariv, and the co-authors for their groundbreaking research and for open-sourcing the DyPE project.
- The ComfyUI team for creating such a powerful and extensible platform for diffusion model research and creativity.