Skip to content

Commit 28f3b18

Browse files
authored
feat(diffusers): add cosmos (#1196)
* add cosmos, models, pipelines, tests * fix cosmos and related fast tests * add slow test, fix init * cosmos t2w t5 use fp32 * tmply pass the checkers * add safety checker ms adaption, draft * enable safety checkers in cosmos, add docs * autopep8 * fix code review * support graph mode, fix test * fix typo * fix docs
1 parent a1f9ff6 commit 28f3b18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+7701
-6
lines changed

docs/diffusers/_toctree.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@
204204
title: CogView3PlusTransformer2DModel
205205
- local: api/models/cogview4_transformer2d
206206
title: CogView4Transformer2DModel
207+
- local: api/models/cosmos_transformer3d
208+
title: CosmosTransformer3DModel
207209
- local: api/models/dit_transformer2d
208210
title: DiTTransformer2DModel
209211
- local: api/models/easyanimate_transformer3d
@@ -266,6 +268,8 @@
266268
title: AutoencoderKLAllegro
267269
- local: api/models/autoencoderkl_cogvideox
268270
title: AutoencoderKLCogVideoX
271+
- local: api/models/autoencoderkl_cosmos
272+
title: AutoencoderKLCosmos
269273
- local: api/models/autoencoder_kl_hunyuan_video
270274
title: AutoencoderKLHunyuanVideo
271275
- local: api/models/autoencoderkl_ltx_video
@@ -340,6 +344,8 @@
340344
title: ControlNet-XS with Stable Diffusion XL
341345
- local: api/pipelines/controlnet_union
342346
title: ControlNetUnion
347+
- local: api/pipelines/cosmos
348+
title: Cosmos
343349
- local: api/pipelines/dance_diffusion
344350
title: Dance Diffusion
345351
- local: api/pipelines/ddim
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- Copyright 2025 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License. -->
11+
12+
# AutoencoderKLCosmos
13+
14+
[Cosmos Tokenizers](https://github.com/NVIDIA/Cosmos-Tokenizer).
15+
16+
Supported models:
17+
- [nvidia/Cosmos-1.0-Tokenizer-CV8x8x8](https://huggingface.co/nvidia/Cosmos-1.0-Tokenizer-CV8x8x8)
18+
19+
The model can be loaded with the following code snippet.
20+
21+
```python
22+
from mindone.diffusers import AutoencoderKLCosmos
23+
24+
vae = AutoencoderKLCosmos.from_pretrained("nvidia/Cosmos-1.0-Tokenizer-CV8x8x8", subfolder="vae")
25+
```
26+
27+
::: mindone.diffusers.models.autoencoders.autoencoder_kl_cosmos.AutoencoderKLCosmos
28+
29+
::: mindone.diffusers.models.autoencoders.autoencoder_kl.AutoencoderKLOutput
30+
31+
::: mindone.diffusers.models.autoencoders.vae.DecoderOutput
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- Copyright 2025 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License. -->
11+
12+
# CosmosTransformer3DModel
13+
14+
A Diffusion Transformer model for 3D video-like data was introduced in [Cosmos World Foundation Model Platform for Physical AI](https://huggingface.co/papers/2501.03575) by NVIDIA.
15+
16+
The model can be loaded with the following code snippet.
17+
18+
```python
19+
import mindspore
20+
from mindone.diffusers import CosmosTransformer3DModel
21+
22+
transformer = CosmosTransformer3DModel.from_pretrained("nvidia/Cosmos-1.0-Diffusion-7B-Text2World", subfolder="transformer", mindspore_dtype=mindspore.bfloat16)
23+
```
24+
25+
::: mindone.diffusers.CosmosTransformer3DModel
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!-- Copyright 2025 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License. -->
14+
15+
# Cosmos
16+
17+
[Cosmos World Foundation Model Platform for Physical AI](https://huggingface.co/papers/2501.03575) by NVIDIA.
18+
19+
*Physical AI needs to be trained digitally first. It needs a digital twin of itself, the policy model, and a digital twin of the world, the world model. In this paper, we present the Cosmos World Foundation Model Platform to help developers build customized world models for their Physical AI setups. We position a world foundation model as a general-purpose world model that can be fine-tuned into customized world models for downstream applications. Our platform covers a video curation pipeline, pre-trained world foundation models, examples of post-training of pre-trained world foundation models, and video tokenizers. To help Physical AI builders solve the most critical problems of our society, we make our platform open-source and our models open-weight with permissive licenses available via https://github.com/NVIDIA/Cosmos.*
20+
21+
<Tip>
22+
23+
Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines.
24+
25+
26+
```python
27+
import mindspore
28+
from mindone.diffusers import Cosmos2TextToImagePipeline, CosmosTransformer3DModel
29+
30+
model_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
31+
pipe = Cosmos2TextToImagePipeline.from_pretrained(model_id, mindspore_dtype=mindspore.bfloat16)
32+
33+
prompt = "A close-up shot captures a vibrant yellow scrubber vigorously working on a grimy plate, its bristles moving in circular motions to lift stubborn grease and food residue. The dish, once covered in remnants of a hearty meal, gradually reveals its original glossy surface. Suds form and bubble around the scrubber, creating a satisfying visual of cleanliness in progress. The sound of scrubbing fills the air, accompanied by the gentle clinking of the dish against the sink. As the scrubber continues its task, the dish transforms, gleaming under the bright kitchen lights, symbolizing the triumph of cleanliness over mess."
34+
negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."
35+
36+
output = pipe(
37+
prompt=prompt, negative_prompt=negative_prompt
38+
)[0][0]
39+
output.save("output.png")
40+
```
41+
42+
::: mindone.diffusers.CosmosTextToWorldPipeline
43+
44+
::: mindone.diffusers.CosmosVideoToWorldPipeline
45+
46+
::: mindone.diffusers.Cosmos2TextToImagePipeline
47+
48+
::: mindone.diffusers.Cosmos2VideoToWorldPipeline
49+
50+
::: mindone.diffusers.pipelines.cosmos.pipeline_output.CosmosPipelineOutput
51+
52+
::: mindone.diffusers.pipelines.cosmos.pipeline_output.CosmosImagePipelineOutput

mindone/diffusers/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"AutoencoderKL",
2525
"AutoencoderKLAllegro",
2626
"AutoencoderKLCogVideoX",
27+
"AutoencoderKLCosmos",
2728
"AutoencoderKLHunyuanVideo",
2829
"AutoencoderKLLTXVideo",
2930
"AutoencoderKLMagvit",
@@ -41,6 +42,7 @@
4142
"ControlNetModel",
4243
"ControlNetUnionModel",
4344
"ControlNetXSAdapter",
45+
"CosmosTransformer3DModel",
4446
"DiTTransformer2DModel",
4547
"EasyAnimateTransformer3DModel",
4648
"FluxControlNetModel",
@@ -128,6 +130,10 @@
128130
"CogView4ControlPipeline",
129131
"CogView4Pipeline",
130132
"ConsisIDPipeline",
133+
"CosmosTextToWorldPipeline",
134+
"CosmosVideoToWorldPipeline",
135+
"Cosmos2TextToImagePipeline",
136+
"Cosmos2VideoToWorldPipeline",
131137
"ConsistencyModelPipeline",
132138
"DanceDiffusionPipeline",
133139
"DDIMPipeline",
@@ -353,6 +359,7 @@
353359
AutoencoderKL,
354360
AutoencoderKLAllegro,
355361
AutoencoderKLCogVideoX,
362+
AutoencoderKLCosmos,
356363
AutoencoderKLHunyuanVideo,
357364
AutoencoderKLLTXVideo,
358365
AutoencoderKLMagvit,
@@ -370,6 +377,7 @@
370377
ControlNetModel,
371378
ControlNetUnionModel,
372379
ControlNetXSAdapter,
380+
CosmosTransformer3DModel,
373381
DiTTransformer2DModel,
374382
EasyAnimateTransformer3DModel,
375383
FluxControlNetModel,
@@ -458,6 +466,10 @@
458466
CogView4Pipeline,
459467
ConsisIDPipeline,
460468
ConsistencyModelPipeline,
469+
Cosmos2TextToImagePipeline,
470+
Cosmos2VideoToWorldPipeline,
471+
CosmosTextToWorldPipeline,
472+
CosmosVideoToWorldPipeline,
461473
DDIMPipeline,
462474
DDPMPipeline,
463475
DiffusionPipeline,

mindone/diffusers/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"autoencoders.autoencoder_kl": ["AutoencoderKL"],
2828
"autoencoders.autoencoder_kl_allegro": ["AutoencoderKLAllegro"],
2929
"autoencoders.autoencoder_kl_cogvideox": ["AutoencoderKLCogVideoX"],
30+
"autoencoders.autoencoder_kl_cosmos": ["AutoencoderKLCosmos"],
3031
"autoencoders.autoencoder_kl_hunyuan_video": ["AutoencoderKLHunyuanVideo"],
3132
"autoencoders.autoencoder_kl_ltx": ["AutoencoderKLLTXVideo"],
3233
"autoencoders.autoencoder_kl_magvit": ["AutoencoderKLMagvit"],
@@ -69,6 +70,7 @@
6970
"transformers.transformer_allegro": ["AllegroTransformer3DModel"],
7071
"transformers.transformer_cogview3plus": ["CogView3PlusTransformer2DModel"],
7172
"transformers.transformer_cogview4": ["CogView4Transformer2DModel"],
73+
"transformers.transformer_cosmos": ["CosmosTransformer3DModel"],
7274
"transformers.transformer_easyanimate": ["EasyAnimateTransformer3DModel"],
7375
"transformers.transformer_flux": ["FluxTransformer2DModel"],
7476
"transformers.transformer_hunyuan_video": ["HunyuanVideoTransformer3DModel"],
@@ -101,6 +103,7 @@
101103
AutoencoderKL,
102104
AutoencoderKLAllegro,
103105
AutoencoderKLCogVideoX,
106+
AutoencoderKLCosmos,
104107
AutoencoderKLHunyuanVideo,
105108
AutoencoderKLLTXVideo,
106109
AutoencoderKLMagvit,
@@ -137,6 +140,7 @@
137140
CogView3PlusTransformer2DModel,
138141
CogView4Transformer2DModel,
139142
ConsisIDTransformer3DModel,
143+
CosmosTransformer3DModel,
140144
DiTTransformer2DModel,
141145
DualTransformer2DModel,
142146
EasyAnimateTransformer3DModel,

mindone/diffusers/models/autoencoders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .autoencoder_kl import AutoencoderKL
66
from .autoencoder_kl_allegro import AutoencoderKLAllegro
77
from .autoencoder_kl_cogvideox import AutoencoderKLCogVideoX
8+
from .autoencoder_kl_cosmos import AutoencoderKLCosmos
89
from .autoencoder_kl_hunyuan_video import AutoencoderKLHunyuanVideo
910
from .autoencoder_kl_ltx import AutoencoderKLLTXVideo
1011
from .autoencoder_kl_magvit import AutoencoderKLMagvit

0 commit comments

Comments
 (0)