Skip to content

feat: Support Krea2 - #14589

Merged
comfyanonymous merged 6 commits into
Comfy-Org:masterfrom
kijai:krea2
Jun 22, 2026
Merged

feat: Support Krea2#14589
comfyanonymous merged 6 commits into
Comfy-Org:masterfrom
kijai:krea2

Conversation

@kijai

@kijai kijai commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Add Krea2 model support

Adds support for the Krea2 image model.

  • New modelcomfy/ldm/krea2/model.py: SingleStreamDiT transformer (single-stream blocks, text-fusion transformer, SwiGLU MLP, separate Q/K/V/O attention).
  • Wiring — registered in model_base.py, model_detection.py, supported_models.py, and sd.py; new CLIP type in text_encoders/krea2.py.
  • LoRA supportlora.py maps diffusers-format LoRA keys (transformer.*, lycoris) onto Krea2's original weight names so diffusers-trained LoRAs apply directly.

alexisrolland
alexisrolland previously approved these changes Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6fb02882-18cd-439b-b679-90d7069c867f

📥 Commits

Reviewing files that changed from the base of the PR and between fd52520 and 2f0e884.

📒 Files selected for processing (2)
  • comfy/sd.py
  • comfy/text_encoders/krea2.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • comfy/sd.py

📝 Walkthrough

Walkthrough

This PR adds full support for the Krea 2 (K2) single-stream MMDiT diffusion model. A new comfy/ldm/krea2/model.py implements the SingleStreamDiT transformer, including RMSNorm primitives, a SwiGLU MLP, sigmoid-gated attention with RoPE, modulation components, a TextFusionTransformer, and a LastLayer head. A new comfy/text_encoders/krea2.py implements a Qwen3-VL-4B-backed text encoder that taps 12 hidden-state layers and flattens them into a fused conditioning tensor. Model detection via weight-shape inference, a Krea2 BaseModel subclass, a Krea2 supported-model class, CLIPType.KREA2, text-encoder loader wiring in sd.py, a krea2_to_diffusers checkpoint parameter mapping utility, LoRA key remapping in lora.py, and a "krea2" entry in the CLIPLoader node type list are all added.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Support Krea2' directly and clearly summarizes the main objective of the PR—adding support for the Krea2 image model.
Description check ✅ Passed The description is well-related to the changeset, providing context about the new Krea2 model architecture, its integration points, and LoRA support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
comfy/model_base.py (1)

2286-2291: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Use CONDCrossAttn for c_crossattn to keep mixed-length prompt batching efficient.

Wrapping cross_attn with CONDRegular can disable cross-attention concat for differing token lengths and force extra UNet passes.

🔧 Proposed fix
     def extra_conds(self, **kwargs):
         out = super().extra_conds(**kwargs)
         cross_attn = kwargs.get("cross_attn", None)
         if cross_attn is not None:
-            out['c_crossattn'] = comfy.conds.CONDRegular(cross_attn)
+            out['c_crossattn'] = comfy.conds.CONDCrossAttn(cross_attn)
         return out

As per path instructions, comfy/** reviews should guard hot-path performance regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@comfy/model_base.py` around lines 2286 - 2291, In the extra_conds method,
change the wrapper type for the c_crossattn assignment from CONDRegular to
CONDCrossAttn when wrapping the cross_attn parameter. The line that currently
reads out['c_crossattn'] = comfy.conds.CONDRegular(cross_attn) should use
CONDCrossAttn instead to maintain efficient mixed-length prompt batching and
avoid unnecessary UNet passes.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@comfy/model_detection.py`:
- Around line 837-850: The Krea2 detection block is not inferring txtheads and
txtkvheads configuration values, leaving them to default in SingleStreamDiT
which causes shape mismatches for non-default checkpoints. Add two new lines to
the dit_config dictionary to infer txtheads and txtkvheads by extracting and
processing the attention weights from the txtfusion blocks (similar to how heads
and kvheads are already being extracted from blocks.0.attn.wq.weight and
blocks.0.attn.wk.weight). Use the same head_dim value and reference the
corresponding txtfusion attention weight keys in the state_dict to divide by
head_dim, ensuring the configuration matches the actual model structure.

In `@comfy/sd.py`:
- Around line 1603-1605: The elif block handling CLIPType.KREA2 (lines
1603-1605) is incorrectly placed in the QWEN3_4B branch, but Krea2 is only
compatible with Qwen3-VL models. Remove the entire elif clause that checks for
CLIPType.KREA2 and sets clip_target.clip and clip_target.tokenizer with the
krea2 text encoder, as this functionality should only be present in the
QWEN3VL_* branch where it is properly supported.

---

Nitpick comments:
In `@comfy/model_base.py`:
- Around line 2286-2291: In the extra_conds method, change the wrapper type for
the c_crossattn assignment from CONDRegular to CONDCrossAttn when wrapping the
cross_attn parameter. The line that currently reads out['c_crossattn'] =
comfy.conds.CONDRegular(cross_attn) should use CONDCrossAttn instead to maintain
efficient mixed-length prompt batching and avoid unnecessary UNet passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cf1c7b46-2428-4682-b356-db4e2869e196

📥 Commits

Reviewing files that changed from the base of the PR and between 6978a46 and c2a9572.

📒 Files selected for processing (8)
  • comfy/ldm/krea2/model.py
  • comfy/lora.py
  • comfy/model_base.py
  • comfy/model_detection.py
  • comfy/sd.py
  • comfy/supported_models.py
  • comfy/text_encoders/krea2.py
  • nodes.py

Comment thread comfy/model_detection.py
Comment thread comfy/sd.py Outdated
kijai added 2 commits June 23, 2026 00:08
works but poorly, rather not allow
@comfyanonymous
comfyanonymous merged commit 2a61015 into Comfy-Org:master Jun 22, 2026
14 checks passed
@Heliumrich

Copy link
Copy Markdown

@kijai Did you look at this ? https://www.reddit.com/r/StableDiffusion/comments/1ud2nyq/comment/ot8mwm6/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

It seems there's a slight issue with this implementation
Thank you for your rapid work !

@alexisrolland

Copy link
Copy Markdown
Member

@kijai Did you look at this ? https://www.reddit.com/r/StableDiffusion/comments/1ud2nyq/comment/ot8mwm6/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

It seems there's a slight issue with this implementation Thank you for your rapid work !

The implementation is fine, the warning is a small easter egg from the model creators. go figure it out before the official release tomorrow ;)

@zwukong

zwukong commented Jun 24, 2026

Copy link
Copy Markdown

style-reference system seems missing

Our style-reference system builds on the base model. It allows users to generate images from text while using one or more reference images to guide the output style. We designed the system to support (1) smooth semantic mixing of multiple styles, (2) continuous control over the strength of each style reference, and (3) state-of-the-art adherence to complex styles.

@kijai

kijai commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

style-reference system seems missing

Our style-reference system builds on the base model. It allows users to generate images from text while using one or more reference images to guide the output style. We designed the system to support (1) smooth semantic mixing of multiple styles, (2) continuous control over the strength of each style reference, and (3) state-of-the-art adherence to complex styles.

They did not release this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants