dg845 commited on
Commit
c8dc90b
·
verified ·
1 Parent(s): 5410c49

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: diffusers
3
+ tags:
4
+ - modular-diffusers
5
+ - diffusers
6
+ - krea2
7
+ - text-to-image
8
+ ---
9
+ This is a modular diffusion pipeline built with 🧨 Diffusers' modular pipeline framework.
10
+
11
+ **Pipeline Type**: Krea2AutoBlocks
12
+
13
+ **Description**: Auto Modular pipeline for text-to-image generation using Krea 2: encode text -> core denoise (symmetric CFG) -> decode.
14
+
15
+ This pipeline uses a 3-block architecture that can be customized and extended.
16
+
17
+ ## Example Usage
18
+
19
+ [TODO]
20
+
21
+ ## Pipeline Architecture
22
+
23
+ This modular pipeline is composed of the following blocks:
24
+
25
+ 1. **text_encoder** (`Krea2TextEncoderStep`)
26
+ - 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.
27
+ 2. **denoise** (`Krea2CoreDenoiseStep`)
28
+ - 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.
29
+ 3. **decode** (`Krea2DecodeStep`)
30
+ - 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.
31
+
32
+ ## Model Components
33
+
34
+ 1. text_encoder (`Qwen3VLModel`): The Qwen3-VL text encoder.
35
+ 2. tokenizer (`AutoTokenizer`): The tokenizer paired with the text encoder.
36
+ 3. transformer (`Krea2Transformer2DModel`)
37
+ 4. scheduler (`FlowMatchEulerDiscreteScheduler`)
38
+ 5. vae (`AutoencoderKLQwenImage`)
39
+ 6. image_processor (`VaeImageProcessor`)
40
+
41
+ ## Configuration Parameters
42
+
43
+ is_distilled (default: False)
44
+
45
+ ## Workflow Input Specification
46
+
47
+ <details>
48
+ <summary><strong>text2image</strong></summary>
49
+
50
+ - `prompt` (`str`): The prompt or prompts to guide image generation.
51
+
52
+ </details>
53
+
54
+
55
+ ## Input/Output Specification
56
+
57
+ **Inputs:**
58
+
59
+ - `prompt` (`str`): The prompt or prompts to guide image generation.
60
+ - `negative_prompt` (`str`, *optional*): The negative prompt(s) for CFG.
61
+ - `guidance_scale` (`float`, *optional*, defaults to `4.5`): CFG scale; the negative prompt is only encoded when this is > 0.
62
+ - `max_sequence_length` (`int`, *optional*, defaults to `512`): Maximum sequence length for prompt encoding.
63
+ - `num_images_per_prompt` (`int`, *optional*, defaults to `1`): The number of images to generate per prompt.
64
+ - `latents` (`Tensor`, *optional*): Pre-generated noisy latents for image generation.
65
+ - `height` (`int`): The height in pixels of the generated image.
66
+ - `width` (`int`): The width in pixels of the generated image.
67
+ - `generator` (`Generator`, *optional*): Torch generator for deterministic generation.
68
+ - `num_inference_steps` (`int`, *optional*, defaults to `28`): The number of denoising steps.
69
+ - `sigmas` (`list`, *optional*): Custom sigma schedule (defaults to a linear ramp).
70
+ - `attention_kwargs` (`dict`, *optional*): Additional kwargs for attention processors.
71
+ - `output_type` (`str`, *optional*, defaults to `pil`): Output format: 'pil', 'np', 'pt'.
72
+
73
+ **Outputs:**
74
+
75
+ - `images` (`list`): Generated images.
modular_model_index.json ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_blocks_class_name": "Krea2AutoBlocks",
3
+ "_class_name": "Krea2ModularPipeline",
4
+ "_diffusers_version": "0.39.0.dev0",
5
+ "is_distilled": false,
6
+ "scheduler": [
7
+ "diffusers",
8
+ "FlowMatchEulerDiscreteScheduler",
9
+ {
10
+ "pretrained_model_name_or_path": "CedricPerauer/tiny-krea2-modular-pipe",
11
+ "revision": null,
12
+ "subfolder": "scheduler",
13
+ "type_hint": [
14
+ "diffusers",
15
+ "FlowMatchEulerDiscreteScheduler"
16
+ ],
17
+ "variant": null
18
+ }
19
+ ],
20
+ "text_encoder": [
21
+ "transformers",
22
+ "Qwen3VLModel",
23
+ {
24
+ "pretrained_model_name_or_path": "CedricPerauer/tiny-krea2-modular-pipe",
25
+ "revision": null,
26
+ "subfolder": "text_encoder",
27
+ "type_hint": [
28
+ "transformers",
29
+ "Qwen3VLModel"
30
+ ],
31
+ "variant": null
32
+ }
33
+ ],
34
+ "tokenizer": [
35
+ "transformers",
36
+ "Qwen2Tokenizer",
37
+ {
38
+ "pretrained_model_name_or_path": "CedricPerauer/tiny-krea2-modular-pipe",
39
+ "revision": null,
40
+ "subfolder": "tokenizer",
41
+ "type_hint": [
42
+ "transformers",
43
+ "Qwen2Tokenizer"
44
+ ],
45
+ "variant": null
46
+ }
47
+ ],
48
+ "transformer": [
49
+ "diffusers",
50
+ "Krea2Transformer2DModel",
51
+ {
52
+ "pretrained_model_name_or_path": "CedricPerauer/tiny-krea2-modular-pipe",
53
+ "revision": null,
54
+ "subfolder": "transformer",
55
+ "type_hint": [
56
+ "diffusers",
57
+ "Krea2Transformer2DModel"
58
+ ],
59
+ "variant": null
60
+ }
61
+ ],
62
+ "vae": [
63
+ "diffusers",
64
+ "AutoencoderKLQwenImage",
65
+ {
66
+ "pretrained_model_name_or_path": "CedricPerauer/tiny-krea2-modular-pipe",
67
+ "revision": null,
68
+ "subfolder": "vae",
69
+ "type_hint": [
70
+ "diffusers",
71
+ "AutoencoderKLQwenImage"
72
+ ],
73
+ "variant": null
74
+ }
75
+ ]
76
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FlowMatchEulerDiscreteScheduler",
3
+ "_diffusers_version": "0.39.0.dev0",
4
+ "base_image_seq_len": 256,
5
+ "base_shift": 0.5,
6
+ "invert_sigmas": false,
7
+ "max_image_seq_len": 6400,
8
+ "max_shift": 1.15,
9
+ "num_train_timesteps": 1000,
10
+ "shift": 1.0,
11
+ "shift_terminal": null,
12
+ "stochastic_sampling": false,
13
+ "time_shift_type": "exponential",
14
+ "use_beta_sigmas": false,
15
+ "use_dynamic_shifting": true,
16
+ "use_exponential_sigmas": false,
17
+ "use_karras_sigmas": false
18
+ }
text_encoder/config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3VLModel"
4
+ ],
5
+ "dtype": "float32",
6
+ "image_token_id": 151655,
7
+ "model_type": "qwen3_vl",
8
+ "text_config": {
9
+ "attention_bias": false,
10
+ "attention_dropout": 0.0,
11
+ "head_dim": 8,
12
+ "hidden_act": "silu",
13
+ "hidden_size": 16,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 16,
16
+ "max_position_embeddings": 128000,
17
+ "model_type": "qwen3_vl_text",
18
+ "num_attention_heads": 2,
19
+ "num_hidden_layers": 36,
20
+ "num_key_value_heads": 2,
21
+ "pad_token_id": null,
22
+ "rms_norm_eps": 1e-06,
23
+ "rope_parameters": {
24
+ "rope_theta": 500000.0,
25
+ "rope_type": "default"
26
+ },
27
+ "use_cache": true,
28
+ "vocab_size": 151936
29
+ },
30
+ "tie_word_embeddings": false,
31
+ "transformers_version": "5.12.1",
32
+ "video_token_id": 151656,
33
+ "vision_config": {
34
+ "deepstack_visual_indexes": [
35
+ 8,
36
+ 16,
37
+ 24
38
+ ],
39
+ "depth": 2,
40
+ "hidden_act": "gelu_pytorch_tanh",
41
+ "hidden_size": 16,
42
+ "in_channels": 3,
43
+ "initializer_range": 0.02,
44
+ "intermediate_size": 16,
45
+ "model_type": "qwen3_vl_vision",
46
+ "num_heads": 2,
47
+ "num_position_embeddings": 2304,
48
+ "out_hidden_size": 16,
49
+ "patch_size": 16,
50
+ "spatial_merge_size": 2,
51
+ "temporal_patch_size": 2
52
+ },
53
+ "vision_end_token_id": 151653,
54
+ "vision_start_token_id": 151652,
55
+ "vocab_size": 152064
56
+ }
text_encoder/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1c4589ff68c9c9b316c25a680f345990c3b65f3ebba045f5f7ec2b8bd24656a
3
+ size 10383856
tokenizer/chat_template.jinja ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system
2
+ You are a helpful assistant.<|im_end|>
3
+ {% endif %}<|im_start|>{{ message['role'] }}
4
+ {% if message['content'] is string %}{{ message['content'] }}<|im_end|>
5
+ {% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>
6
+ {% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant
7
+ {% endif %}
tokenizer/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:312c03cb421e18f41c20c3e35f3302479a3a8f8b1f06779fd900326a0d32c22f
3
+ size 11420534
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "local_files_only": false,
25
+ "max_length": null,
26
+ "model_max_length": 32768,
27
+ "pad_to_multiple_of": null,
28
+ "pad_token": "<|endoftext|>",
29
+ "pad_token_type_id": 0,
30
+ "padding_side": "left",
31
+ "processor_class": "Qwen2VLProcessor",
32
+ "split_special_tokens": false,
33
+ "tokenizer_class": "Qwen2Tokenizer",
34
+ "unk_token": null
35
+ }
transformer/config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "Krea2Transformer2DModel",
3
+ "_diffusers_version": "0.39.0.dev0",
4
+ "attention_head_dim": 8,
5
+ "axes_dims_rope": [
6
+ 4,
7
+ 2,
8
+ 2
9
+ ],
10
+ "in_channels": 16,
11
+ "intermediate_size": 32,
12
+ "norm_eps": 1e-05,
13
+ "num_attention_heads": 4,
14
+ "num_key_value_heads": 2,
15
+ "num_layers": 2,
16
+ "num_layerwise_text_blocks": 1,
17
+ "num_refiner_text_blocks": 1,
18
+ "num_text_layers": 12,
19
+ "rope_theta": 1000.0,
20
+ "text_hidden_dim": 16,
21
+ "text_intermediate_size": 16,
22
+ "text_num_attention_heads": 2,
23
+ "text_num_key_value_heads": 1,
24
+ "timestep_embed_dim": 8
25
+ }
transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea582bcdc2017d7955e81b8d799fa2a1824cdb80fa0019e4fa701398e0658795
3
+ size 122872
vae/config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKLQwenImage",
3
+ "_diffusers_version": "0.39.0.dev0",
4
+ "attn_scales": [],
5
+ "base_dim": 24,
6
+ "dim_mult": [
7
+ 1,
8
+ 2,
9
+ 4
10
+ ],
11
+ "dropout": 0.0,
12
+ "input_channels": 3,
13
+ "latents_mean": [
14
+ 0.0,
15
+ 0.0,
16
+ 0.0,
17
+ 0.0
18
+ ],
19
+ "latents_std": [
20
+ 1.0,
21
+ 1.0,
22
+ 1.0,
23
+ 1.0
24
+ ],
25
+ "num_res_blocks": 1,
26
+ "temperal_downsample": [
27
+ false,
28
+ true
29
+ ],
30
+ "z_dim": 4
31
+ }
vae/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d82f6ac6ca2e5767a17a5efc504e0470705b3b3318bab132dd218ff0ff342d29
3
+ size 16230492