Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extensions_built_in/diffusion_models/krea2/krea2.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
kvheads=12,
multiplier=4,
layers=28,
patch=2,
patch_size=2,
channels=16,
txtheads=20,
txtkvheads=20,
Expand Down Expand Up @@ -182,7 +182,7 @@ def __init__(
self.is_transformer = True
self.target_lora_modules = ["SingleStreamDiT"]

self.patch_size = KREA2_MMDIT_CONFIG["patch"]
self.patch_size = KREA2_MMDIT_CONFIG["patch_size"]
self.vae_scale_factor = 8 # Qwen-Image VAE is f8
# Safety cap on prompt token length (truncation only); embeds are stored
# per-sample at natural length and padded to the batch max at the model call.
Expand Down
13 changes: 8 additions & 5 deletions extensions_built_in/diffusion_models/krea2/src/mmdit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- ``enable_gradient_checkpointing`` / ``disable_gradient_checkpointing`` and a
per-block ``torch.utils.checkpoint`` wrapper are added (gated on
``torch.is_grad_enabled()`` so eval/sampling never pays for it).
- ``patch`` renamed to ``patch_size`` (diffusers-style name, matching the
toolkit's other archs) so the generic trainer's timestep-shift setup can
discover the token patch size via ``unet.config.patch_size``.
"""

import math
Expand Down Expand Up @@ -96,7 +99,7 @@ class SingleMMDiTConfig:
heads: int
multiplier: int
layers: int
patch: int
patch_size: int
channels: int
bias: bool = False
theta: float = 1e3
Expand Down Expand Up @@ -249,10 +252,10 @@ def forward(


class LastLayer(torch.nn.Module):
def __init__(self, features: int, patch: int, channels: int):
def __init__(self, features: int, patch_size: int, channels: int):
super().__init__()
self.norm = RMSNorm(features)
self.linear = torch.nn.Linear(features, patch * patch * channels, bias=True)
self.linear = torch.nn.Linear(features, patch_size * patch_size * channels, bias=True)
self.modulation = SimpleModulation(features)

def forward(self, x: Tensor, tvec: Tensor) -> Tensor:
Expand Down Expand Up @@ -413,7 +416,7 @@ def __init__(self, config: SingleMMDiTConfig):
config.features, axes, theta=config.theta, ntk=1.0
)
self.first = nn.Linear(
config.channels * config.patch**2, config.features, bias=True
config.channels * config.patch_size**2, config.features, bias=True
)

self.blocks = nn.ModuleList(
Expand Down Expand Up @@ -447,7 +450,7 @@ def __init__(self, config: SingleMMDiTConfig):
nn.GELU(approximate="tanh"),
nn.Linear(config.features, config.features),
)
self.last = LastLayer(config.features, config.patch, config.channels)
self.last = LastLayer(config.features, config.patch_size, config.channels)

self.tproj = nn.Sequential(
nn.GELU(approximate="tanh"), nn.Linear(config.features, config.features * 6)
Expand Down
2 changes: 1 addition & 1 deletion extensions_built_in/diffusion_models/krea2/src/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def predict_velocity(
the velocity ``noise - clean`` reshaped back to ``(B, C, h, w)``. No time
flip / negation: Krea's convention matches toolkit's.
"""
patch = model.config.patch
patch = model.config.patch_size
b, c, h, w = latents.shape

if ref_kv_cache is not None and not isolate_refs:
Expand Down