YiYiXu HF Staff yzhautouskay commited on
Commit
80d669d
·
1 Parent(s): ff1ae7e

Add tiny Cosmos3 distilled modular pipeline fixture (#1)

Browse files

- Add tiny Cosmos3 distilled modular pipeline fixture (2059b596353c32d2da7560ad8bcf18ced291ff89)


Co-authored-by: Yuliya Zhautouskaya <yzhautouskay@users.noreply.huggingface.co>

.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
+ text_tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: diffusers
3
+ tags:
4
+ - modular-diffusers
5
+ - diffusers
6
+ - cosmos3-omni
7
+ - text-to-image
8
+ ---
9
+ This is a modular diffusion pipeline built with 🧨 Diffusers' modular pipeline framework.
10
+
11
+ **Pipeline Type**: Cosmos3DistilledBlocks
12
+
13
+ **Description**: Modular pipeline blocks for distilled (few-step) Cosmos3 generation modes.
14
+
15
+ This pipeline uses a 4-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** (`Cosmos3DistilledTextEncoderStep`)
26
+ - Prepares distilled prompt token IDs. Classifier-free guidance is baked into the weights, so `negative_prompt` is not exposed and the unconditional branch is derived from an empty prompt.
27
+ 2. **vae_encoder** (`Cosmos3DistilledAutoVaeEncoderStep`)
28
+ - Auto VAE conditioning block for distilled Cosmos3.
29
+ 3. **denoise** (`Cosmos3DistilledVisionCoreDenoiseStep`)
30
+ - Runs the text-and-vision distilled Cosmos3 denoising workflow.
31
+ 4. **decode** (`Cosmos3VideoDecodeStep`)
32
+ - Decodes denoised vision latents into video outputs.
33
+
34
+ ## Model Components
35
+
36
+ 1. text_tokenizer (`AutoTokenizer`)
37
+ 2. vae (`AutoencoderKLWan`)
38
+ 3. video_processor (`VideoProcessor`)
39
+ 4. transformer (`Cosmos3OmniTransformer`)
40
+ 5. scheduler (`FlowMatchEulerDiscreteScheduler`)
41
+
42
+ ## Configuration Parameters
43
+
44
+ is_distilled (default: True)
45
+ distilled_sigmas (default: None)
46
+
47
+ ## Workflow Input Specification
48
+
49
+ <details>
50
+ <summary><strong>text2image</strong></summary>
51
+
52
+ - `prompt` (`str`): The text prompt that guides Cosmos3 generation.
53
+ - `num_frames` (`int`, *optional*): Number of frames to generate.
54
+
55
+ </details>
56
+
57
+ <details>
58
+ <summary><strong>text2video</strong></summary>
59
+
60
+ - `prompt` (`str`): The text prompt that guides Cosmos3 generation.
61
+
62
+ </details>
63
+
64
+ <details>
65
+ <summary><strong>image2video</strong></summary>
66
+
67
+ - `prompt` (`str`): The text prompt that guides Cosmos3 generation.
68
+ - `image` (`None`, *optional*): Reference image for image-to-video conditioning.
69
+
70
+ </details>
71
+
72
+ <details>
73
+ <summary><strong>video2video</strong></summary>
74
+
75
+ - `prompt` (`str`): The text prompt that guides Cosmos3 generation.
76
+ - `video` (`None`, *optional*): Reference video for video-to-video conditioning.
77
+
78
+ </details>
79
+
80
+
81
+ ## Input/Output Specification
82
+
83
+ **Inputs:**
84
+
85
+ - `prompt` (`str`): The text prompt that guides Cosmos3 generation.
86
+ - `num_frames` (`int`, *optional*): Number of frames to generate.
87
+ - `height` (`int`, *optional*): Height of the generated video or image in pixels.
88
+ - `width` (`int`, *optional*): Width of the generated video or image in pixels.
89
+ - `fps` (`float`, *optional*, defaults to `24.0`): Frame rate of the generated video.
90
+ - `use_system_prompt` (`bool`, *optional*, defaults to `True`): Whether to prepend the Cosmos3 system prompt.
91
+ - `add_resolution_template` (`bool`, *optional*, defaults to `True`): Whether to add resolution metadata to the prompt.
92
+ - `add_duration_template` (`bool`, *optional*, defaults to `True`): Whether to add duration metadata to the prompt.
93
+ - `video` (`None`, *optional*): Reference video for video-to-video conditioning.
94
+ - `condition_frame_indexes_vision` (`tuple | list`, *optional*, defaults to `(0, 1)`): Latent-frame indexes to preserve from the conditioning video.
95
+ - `condition_video_keep` (`str`, *optional*, defaults to `first`): Which end of a longer conditioning video to use: `first` or `last`.
96
+ - `image` (`None`, *optional*): Reference image for image-to-video conditioning.
97
+ - `x0_tokens_vision` (`Tensor`, *optional*): Vision latents encoded from the conditioning image or video.
98
+ - `vision_condition_frames` (`list`, *optional*): Latent-frame indexes fixed by visual conditioning.
99
+ - `latents` (`Tensor`, *optional*): Pre-generated noisy vision latents.
100
+ - `generator` (`Generator`, *optional*): Torch generator for deterministic generation.
101
+ - `num_inference_steps` (`int`, *optional*): The number of denoising steps.
102
+ - `guidance_scale` (`float`, *optional*): Unused for distilled checkpoints; classifier-free guidance is baked into the weights and the scale is forced to 1.0. Passing a value other than 1.0 raises an error.
103
+ - `**denoiser_input_fields` (`None`, *optional*): conditional model inputs for the denoiser: e.g. prompt_embeds, negative_prompt_embeds, etc.
104
+ - `output_type` (`str`, *optional*, defaults to `pil`): Output format: 'pil', 'np', 'pt'.
105
+
106
+ **Outputs:**
107
+
108
+ - `videos` (`list`): The generated videos.
modular_model_index.json ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_blocks_class_name": "Cosmos3DistilledBlocks",
3
+ "_class_name": "Cosmos3DistilledModularPipeline",
4
+ "_diffusers_version": "0.40.0.dev0",
5
+ "default_use_system_prompt": true,
6
+ "distilled_sigmas": [
7
+ 1.0,
8
+ 0.9375,
9
+ 0.8333333333333334,
10
+ 0.625
11
+ ],
12
+ "enable_safety_checker": true,
13
+ "is_distilled": true,
14
+ "scheduler": [
15
+ "diffusers",
16
+ "FlowMatchEulerDiscreteScheduler",
17
+ {
18
+ "pretrained_model_name_or_path": "hf-internal-testing/tiny-cosmos3-distilled-modular-pipe",
19
+ "revision": null,
20
+ "subfolder": "scheduler",
21
+ "type_hint": [
22
+ "diffusers",
23
+ "FlowMatchEulerDiscreteScheduler"
24
+ ],
25
+ "variant": null
26
+ }
27
+ ],
28
+ "text_tokenizer": [
29
+ "transformers",
30
+ "Qwen2Tokenizer",
31
+ {
32
+ "pretrained_model_name_or_path": "hf-internal-testing/tiny-cosmos3-distilled-modular-pipe",
33
+ "revision": null,
34
+ "subfolder": "text_tokenizer",
35
+ "type_hint": [
36
+ "transformers",
37
+ "Qwen2Tokenizer"
38
+ ],
39
+ "variant": null
40
+ }
41
+ ],
42
+ "transformer": [
43
+ "diffusers",
44
+ "Cosmos3OmniTransformer",
45
+ {
46
+ "pretrained_model_name_or_path": "hf-internal-testing/tiny-cosmos3-distilled-modular-pipe",
47
+ "revision": null,
48
+ "subfolder": "transformer",
49
+ "type_hint": [
50
+ "diffusers",
51
+ "Cosmos3OmniTransformer"
52
+ ],
53
+ "variant": null
54
+ }
55
+ ],
56
+ "use_native_flow_schedule": false,
57
+ "vae": [
58
+ "diffusers",
59
+ "AutoencoderKLWan",
60
+ {
61
+ "pretrained_model_name_or_path": "hf-internal-testing/tiny-cosmos3-distilled-modular-pipe",
62
+ "revision": null,
63
+ "subfolder": "vae",
64
+ "type_hint": [
65
+ "diffusers",
66
+ "AutoencoderKLWan"
67
+ ],
68
+ "variant": null
69
+ }
70
+ ]
71
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "FlowMatchEulerDiscreteScheduler",
3
+ "_diffusers_version": "0.40.0.dev0",
4
+ "base_image_seq_len": 256,
5
+ "base_shift": 0.5,
6
+ "fixed_step_sampler_config": {
7
+ "sample_type": "sde",
8
+ "t_list": [
9
+ 1.0,
10
+ 0.9375,
11
+ 0.8333333333333334,
12
+ 0.625
13
+ ]
14
+ },
15
+ "invert_sigmas": false,
16
+ "max_image_seq_len": 4096,
17
+ "max_shift": 1.15,
18
+ "num_train_timesteps": 1000,
19
+ "shift": 1.0,
20
+ "shift_terminal": null,
21
+ "stochastic_sampling": true,
22
+ "time_shift_type": "exponential",
23
+ "use_beta_sigmas": false,
24
+ "use_dynamic_shifting": false,
25
+ "use_exponential_sigmas": false,
26
+ "use_karras_sigmas": false
27
+ }
text_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 %}
text_tokenizer/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5f2d9ad82d8cc36efa0b551da76a9a1e8c821cbf1aecc41f99c283a325c9069
3
+ size 11420641
text_tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "is_local": true,
9
+ "local_files_only": false,
10
+ "model_max_length": 32768,
11
+ "pad_token": "<|endoftext|>",
12
+ "padding_side": "left",
13
+ "processor_class": "Qwen2VLProcessor",
14
+ "split_special_tokens": false,
15
+ "tokenizer_class": "Qwen2Tokenizer",
16
+ "unk_token": null,
17
+ "variant": null
18
+ }
transformer/config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "Cosmos3OmniTransformer",
3
+ "_diffusers_version": "0.40.0.dev0",
4
+ "_name_or_path": "/root/.cache/huggingface/hub/models--hf-internal-testing--tiny-cosmos3-modular-pipe/snapshots/9b0268fcede397cca83377c4a41c8f3efd2702fd/transformer",
5
+ "action_dim": 10,
6
+ "action_gen": true,
7
+ "attention_bias": false,
8
+ "attention_dropout": 0.0,
9
+ "backbone_type": "cosmos3_qwen3vl",
10
+ "base_fps": 24,
11
+ "enable_fps_modulation": true,
12
+ "head_dim": 6,
13
+ "hidden_act": "silu",
14
+ "hidden_size": 6,
15
+ "intermediate_size": 12,
16
+ "latent_channel": 4,
17
+ "latent_patch_size": 2,
18
+ "num_attention_heads": 1,
19
+ "num_embodiment_domains": 32,
20
+ "num_hidden_layers": 1,
21
+ "num_key_value_heads": 1,
22
+ "patch_latent_dim": 16,
23
+ "qk_norm_for_text": true,
24
+ "rms_norm_eps": 1e-06,
25
+ "rope_axes_dim": [
26
+ 1,
27
+ 1,
28
+ 1
29
+ ],
30
+ "rope_scaling": {
31
+ "mrope_section": [
32
+ 1,
33
+ 1,
34
+ 1
35
+ ]
36
+ },
37
+ "rope_theta": 5000000.0,
38
+ "sound_dim": 4,
39
+ "sound_gen": true,
40
+ "sound_latent_fps": 5.0,
41
+ "temporal_compression_factor": 4,
42
+ "timestep_scale": 0.001,
43
+ "unified_3d_mrope_reset_spatial_ids": true,
44
+ "unified_3d_mrope_temporal_modality_margin": 15000,
45
+ "vocab_size": 151657
46
+ }
transformer/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:382866740d429a75e2ca32857f115ab8d5ce3bc430ff0e4d0191c9afb6a7f1ce
3
+ size 7311624
vae/config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKLWan",
3
+ "_diffusers_version": "0.40.0.dev0",
4
+ "_name_or_path": "/root/.cache/huggingface/hub/models--hf-internal-testing--tiny-cosmos3-modular-pipe/snapshots/9b0268fcede397cca83377c4a41c8f3efd2702fd/vae",
5
+ "attn_scales": [],
6
+ "base_dim": 8,
7
+ "decoder_base_dim": 8,
8
+ "dim_mult": [
9
+ 1,
10
+ 1
11
+ ],
12
+ "dropout": 0.0,
13
+ "in_channels": 3,
14
+ "is_residual": false,
15
+ "latents_mean": [
16
+ 0.0,
17
+ 0.0,
18
+ 0.0,
19
+ 0.0
20
+ ],
21
+ "latents_std": [
22
+ 1.0,
23
+ 1.0,
24
+ 1.0,
25
+ 1.0
26
+ ],
27
+ "num_res_blocks": 1,
28
+ "out_channels": 3,
29
+ "patch_size": null,
30
+ "scale_factor_spatial": 8,
31
+ "scale_factor_temporal": 4,
32
+ "temperal_downsample": [
33
+ false
34
+ ],
35
+ "z_dim": 4
36
+ }
vae/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9baafae0091064db9eeeb21d2bdd7645cb4c97bc590d5eabba4780bf50237560
3
+ size 167348