forked from wildminder/ComfyUI-DyPE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
92 lines (85 loc) · 3.85 KB
/
Copy path__init__.py
File metadata and controls
92 lines (85 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import torch
from comfy_api.latest import ComfyExtension, io
from .src.patch import apply_dype_to_flux
class DyPE_FLUX(io.ComfyNode):
"""
Applies DyPE (Dynamic Position Extrapolation) to a FLUX model.
This allows generating images at resolutions far beyond the model's training scale
by dynamically adjusting positional encodings and the noise schedule.
Compatible with both standard ComfyUI FLUX models and Nunchaku FLUX models.
"""
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="DyPE_FLUX",
display_name="DyPE for FLUX",
category="model_patches/unet",
description="Applies DyPE (Dynamic Position Extrapolation) to a FLUX model for ultra-high-resolution generation.",
inputs=[
io.Model.Input(
"model",
tooltip="The FLUX model to patch with DyPE.",
),
io.Int.Input(
"width",
default=1024, min=16, max=8192, step=8,
tooltip="Target image width. Must match the width of your empty latent."
),
io.Int.Input(
"height",
default=1024, min=16, max=8192, step=8,
tooltip="Target image height. Must match the height of your empty latent."
),
io.Combo.Input(
"method",
options=["yarn", "ntk", "base"],
default="yarn",
tooltip="Position encoding extrapolation method (YARN recommended).",
),
io.Boolean.Input(
"enable_dype",
default=True,
label_on="Enabled",
label_off="Disabled",
tooltip="Enable or disable Dynamic Position Extrapolation for RoPE.",
),
io.Float.Input(
"dype_exponent",
default=2.0, min=0.0, max=4.0, step=0.1,
optional=True,
tooltip="Controls DyPE strength over time (λt). 2.0=Exponential (best for 4K+), 1.0=Linear, 0.5=Sub-linear (better for ~2K)."
),
io.Float.Input(
"base_shift",
default=0.5, min=0.0, max=10.0, step=0.01,
optional=True,
tooltip="Advanced: Base shift for the noise schedule (mu). Default is 0.5."
),
io.Float.Input(
"max_shift",
default=1.15, min=0.0, max=10.0, step=0.01,
optional=True,
tooltip="Advanced: Max shift for the noise schedule (mu) at high resolutions. Default is 1.15."
),
],
outputs=[
io.Model.Output(
display_name="Patched Model",
tooltip="The FLUX model patched with DyPE.",
),
],
)
@classmethod
def execute(cls, model, width: int, height: int, method: str, enable_dype: bool, dype_exponent: float = 2.0, base_shift: float = 0.5, max_shift: float = 1.15) -> io.NodeOutput:
"""
Clones the model and applies the DyPE patch for both the noise schedule and positional embeddings.
Supports both standard FLUX models and Nunchaku-wrapped FLUX models.
"""
patched_model = apply_dype_to_flux(model, width, height, method, enable_dype, dype_exponent, base_shift, max_shift)
return io.NodeOutput(patched_model)
class DyPEExtension(ComfyExtension):
"""Registers the DyPE node."""
async def get_node_list(self) -> list[type[io.ComfyNode]]:
return [DyPE_FLUX]
async def comfy_entrypoint() -> DyPEExtension:
return DyPEExtension()