Add Krea 2 (K2) text-to-image pipeline and transformer by yiyixuxu · Pull Request #14045 · huggingface/diffusers · GitHub
Skip to content
Merged
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: 4 additions & 0 deletions docs/source/en/_toctree.yml
19 changes: 19 additions & 0 deletions docs/source/en/api/models/krea2_transformer2d.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--Copyright 2026 Krea AI and The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

# Krea2Transformer2DModel

The single-stream MMDiT flow-matching transformer used by [Krea 2](https://github.com/krea-ai/krea-2).

## Krea2Transformer2DModel

[[autodoc]] Krea2Transformer2DModel
61 changes: 61 additions & 0 deletions docs/source/en/api/pipelines/krea2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--Copyright 2026 Krea AI and The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

# Krea 2

Krea 2 (K2) is a flow-matching text-to-image model built around a single-stream MMDiT with grouped-query attention. A
Qwen3-VL text encoder provides the conditioning: instead of the last hidden state, hidden states from twelve decoder
layers are tapped per token and fused inside the transformer by a small text-fusion stage. Images are decoded with the
Qwen-Image VAE.

Two checkpoints are released, sharing the same architecture but with different recommended sampler settings:

- **Base (midtrain)** — use the full sampler with classifier-free guidance: `num_inference_steps=28`,
`guidance_scale=4.5`.
- **TDM (distilled)** — distilled for few-step sampling, run with `num_inference_steps=8` and guidance disabled
(`guidance_scale=0.0`).

`guidance_scale` follows the Krea 2 convention: the velocity is computed as `cond + guidance_scale * (cond - uncond)`
and guidance is enabled whenever `guidance_scale > 0` (this equals the usual CFG formulation with scale
`1 + guidance_scale`).

## Text-to-image

```python
import torch
from diffusers import Krea2Pipeline

# Load from a local directory produced by the Krea 2 conversion (no hub repo yet).
pipe = Krea2Pipeline.from_pretrained("path/to/krea2-diffusers", torch_dtype=torch.bfloat16)
pipe.to("cuda")

prompt = "a fox in the snow"
image = pipe(
prompt,
height=1024,
width=1024,
num_inference_steps=28,
guidance_scale=4.5,
generator=torch.Generator("cuda").manual_seed(0),
).images[0]
image.save("krea2.png")
```

## Krea2Pipeline

[[autodoc]] Krea2Pipeline
- all
- __call__

## Krea2PipelineOutput

[[autodoc]] pipelines.krea2.pipeline_output.Krea2PipelineOutput
4 changes: 4 additions & 0 deletions src/diffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
"JoyImageEditTransformer3DModel",
"Kandinsky3UNet",
"Kandinsky5Transformer3DModel",
"Krea2Transformer2DModel",
"LatteTransformer3DModel",
"LongCatAudioDiTTransformer",
"LongCatAudioDiTVae",
Expand Down Expand Up @@ -646,6 +647,7 @@
"KandinskyV22Pipeline",
"KandinskyV22PriorEmb2EmbPipeline",
"KandinskyV22PriorPipeline",
"Krea2Pipeline",
"LatentConsistencyModelImg2ImgPipeline",
"LatentConsistencyModelPipeline",
"LattePipeline",
Expand Down Expand Up @@ -1137,6 +1139,7 @@
JoyImageEditTransformer3DModel,
Kandinsky3UNet,
Kandinsky5Transformer3DModel,
Krea2Transformer2DModel,
LatteTransformer3DModel,
LongCatAudioDiTTransformer,
LongCatAudioDiTVae,
Expand Down Expand Up @@ -1481,6 +1484,7 @@
KandinskyV22Pipeline,
KandinskyV22PriorEmb2EmbPipeline,
KandinskyV22PriorPipeline,
Krea2Pipeline,
LatentConsistencyModelImg2ImgPipeline,
LatentConsistencyModelPipeline,
LattePipeline,
Expand Down
2 changes: 2 additions & 0 deletions src/diffusers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
_import_structure["transformers.transformer_ideogram4"] = ["Ideogram4Transformer2DModel"]
_import_structure["transformers.transformer_joyimage"] = ["JoyImageEditTransformer3DModel"]
_import_structure["transformers.transformer_kandinsky"] = ["Kandinsky5Transformer3DModel"]
_import_structure["transformers.transformer_krea2"] = ["Krea2Transformer2DModel"]
_import_structure["transformers.transformer_longcat_audio_dit"] = ["LongCatAudioDiTTransformer"]
_import_structure["transformers.transformer_longcat_image"] = ["LongCatImageTransformer2DModel"]
_import_structure["transformers.transformer_ltx"] = ["LTXVideoTransformer3DModel"]
Expand Down Expand Up @@ -255,6 +256,7 @@
Ideogram4Transformer2DModel,
JoyImageEditTransformer3DModel,
Kandinsky5Transformer3DModel,
Krea2Transformer2DModel,
LatteTransformer3DModel,
LongCatAudioDiTTransformer,
LongCatImageTransformer2DModel,
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/models/transformers/__init__.py
Loading
Loading