File size: 3,185 Bytes
c8dc90b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
library_name: diffusers
tags:
- modular-diffusers
- diffusers
- krea2
- text-to-image
---
This is a modular diffusion pipeline built with 🧨 Diffusers' modular pipeline framework.

**Pipeline Type**: Krea2AutoBlocks

**Description**: Auto Modular pipeline for text-to-image generation using Krea 2: encode text -> core denoise (symmetric CFG) -> decode.

This pipeline uses a 3-block architecture that can be customized and extended.

## Example Usage

[TODO]

## Pipeline Architecture

This modular pipeline is composed of the following blocks:

1. **text_encoder** (`Krea2TextEncoderStep`)
   - Text encoder step that tokenizes the prompt(s) with the Krea 2 chat template, runs the Qwen3-VL text encoder, and stacks a fixed set of decoder-layer hidden states per token as the transformer's text conditioning. When `guidance_scale > 0` the negative prompt is encoded the same way for CFG.
2. **denoise** (`Krea2CoreDenoiseStep`)
   - Core denoising workflow for Krea 2 text-to-image: prepares the batch/latents/timesteps and the shared position ids, then runs the symmetric-CFG denoising loop, producing the denoised packed latents for the decoder.
3. **decode** (`Krea2DecodeStep`)
   - Step that unpacks the denoised packed latents back to the spatial grid, de-normalizes them with the VAE's per-channel statistics, and decodes them through the Qwen-Image VAE into images. 

## Model Components

1. text_encoder (`Qwen3VLModel`): The Qwen3-VL text encoder.
2. tokenizer (`AutoTokenizer`): The tokenizer paired with the text encoder.
3. transformer (`Krea2Transformer2DModel`)
4. scheduler (`FlowMatchEulerDiscreteScheduler`)
5. vae (`AutoencoderKLQwenImage`)
6. image_processor (`VaeImageProcessor`) 

## Configuration Parameters

is_distilled (default: False)

## Workflow Input Specification

<details>
<summary><strong>text2image</strong></summary>

- `prompt` (`str`): The prompt or prompts to guide image generation.

</details>


## Input/Output Specification

**Inputs:**

- `prompt` (`str`): The prompt or prompts to guide image generation.
- `negative_prompt` (`str`, *optional*): The negative prompt(s) for CFG.
- `guidance_scale` (`float`, *optional*, defaults to `4.5`): CFG scale; the negative prompt is only encoded when this is > 0.
- `max_sequence_length` (`int`, *optional*, defaults to `512`): Maximum sequence length for prompt encoding.
- `num_images_per_prompt` (`int`, *optional*, defaults to `1`): The number of images to generate per prompt.
- `latents` (`Tensor`, *optional*): Pre-generated noisy latents for image generation.
- `height` (`int`): The height in pixels of the generated image.
- `width` (`int`): The width in pixels of the generated image.
- `generator` (`Generator`, *optional*): Torch generator for deterministic generation.
- `num_inference_steps` (`int`, *optional*, defaults to `28`): The number of denoising steps.
- `sigmas` (`list`, *optional*): Custom sigma schedule (defaults to a linear ramp).
- `attention_kwargs` (`dict`, *optional*): Additional kwargs for attention processors.
- `output_type` (`str`, *optional*, defaults to `pil`): Output format: 'pil', 'np', 'pt'.

**Outputs:**

- `images` (`list`): Generated images.