-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Cosmos3 Distilled support #14177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yzhautouskay
wants to merge
4
commits into
huggingface:main
Choose a base branch
from
yzhautouskay:yzhautouskay/cosmos3_distilled
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+844
−5
Open
Cosmos3 Distilled support #14177
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
abb37e7
Cosmos3 distilled support (dedicated modular pipeline + blocks)
yzhautouskay 409c2eb
Address review comments
yzhautouskay 6b5199f
Refactor unit test to use ModularPipelineTesterMixin
yzhautouskay 235d96a
Merge branch 'main' into yzhautouskay/cosmos3_distilled
yiyixuxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -989,11 +989,83 @@ videos = pipe( | |||||
| export_to_video(videos, "cosmos3_modular_transfer_edge.mp4", fps=30, macro_block_size=1) | ||||||
| ``` | ||||||
|
|
||||||
| ### Distilled (few-step) text-to-image and image-to-video | ||||||
|
|
||||||
| Few-step distilled checkpoints ship a fixed sigma schedule in | ||||||
| `scheduler.config.fixed_step_sampler_config.t_list` and bake classifier-free guidance into | ||||||
| the weights. They are served by the dedicated [`Cosmos3DistilledModularPipeline`] (blocks: | ||||||
| `Cosmos3DistilledBlocks`) — the task-based [`Cosmos3OmniPipeline`] and the base | ||||||
| [`Cosmos3OmniModularPipeline`] do not implement the distilled contract. | ||||||
|
|
||||||
| Load a distilled repo and call the pipeline **without** `num_inference_steps` or | ||||||
| `guidance_scale`; `Cosmos3DistilledSetTimestepsStep` reads the fixed step count from the | ||||||
| scheduler config and forces `guidance_scale=1.0`. Because classifier-free guidance is baked | ||||||
| into the weights, `negative_prompt` is not supported (passing one raises an error). | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| Prompts follow the same descriptive JSON structure as the non-distilled models, so short text | ||||||
| must be upsampled first — use `--mode text2image` (T2I) or `--mode image2video` (I2V) as | ||||||
| described in [Prompt upsampling](#prompt-upsampling), then pass the JSON via `json.dumps(...)`. | ||||||
|
|
||||||
| ```python | ||||||
| import json | ||||||
| import torch | ||||||
| from diffusers import Cosmos3DistilledModularPipeline | ||||||
| from diffusers.utils import export_to_video, load_image | ||||||
|
|
||||||
| # JSON-upsampled prompt (see "Prompt upsampling" above). | ||||||
| json_prompt = json.load(open("assets/example_t2i_prompt.json")) | ||||||
|
|
||||||
| repo = "nvidia/Cosmos3-Super-Text2Image-4Step" | ||||||
| pipe = Cosmos3DistilledModularPipeline.from_pretrained(repo, torch_dtype=torch.bfloat16) | ||||||
| pipe.load_components(torch_dtype=torch.bfloat16) | ||||||
| pipe.to("cuda") | ||||||
|
|
||||||
| # text-to-image (distilled) | ||||||
| videos = pipe( | ||||||
| prompt=json.dumps(json_prompt), | ||||||
| num_frames=1, | ||||||
| height=720, | ||||||
| width=1280, | ||||||
| output="videos", | ||||||
| ) | ||||||
| videos[0].save("cosmos3_distilled_t2i.jpg", format="JPEG", quality=85) | ||||||
|
|
||||||
| # image-to-video (distilled) — load the I2V repo instead | ||||||
| # JSON-upsampled prompt (see "Prompt upsampling" above); upsampled from the source prompt | ||||||
| # "The right robotic hand picks up the red sphere on the shelf." | ||||||
| json_prompt_i2v = json.load(open("assets/example_i2v_prompt.json")) | ||||||
|
|
||||||
| repo_i2v = "nvidia/Cosmos3-Super-Image2Video-4Step" | ||||||
| pipe = Cosmos3DistilledModularPipeline.from_pretrained(repo_i2v, torch_dtype=torch.bfloat16) | ||||||
| pipe.load_components(torch_dtype=torch.bfloat16) | ||||||
| pipe.to("cuda") | ||||||
|
|
||||||
| image = load_image( | ||||||
| "https://github.com/nvidia-cosmos/cosmos-dependencies/raw/refs/heads/assets/cosmos3/inputs/vision/robot_153.jpg" | ||||||
| ) | ||||||
| videos = pipe( | ||||||
| prompt=json.dumps(json_prompt_i2v), | ||||||
| image=image, | ||||||
| num_frames=189, | ||||||
| height=720, | ||||||
| width=1280, | ||||||
| output="videos", | ||||||
| ) | ||||||
| export_to_video(videos, "cosmos3_distilled_i2v.mp4", fps=24, macro_block_size=1) | ||||||
| ``` | ||||||
|
|
||||||
| [[autodoc]] Cosmos3OmniModularPipeline | ||||||
|
|
||||||
| - all | ||||||
| - __call__ | ||||||
|
|
||||||
| ## Cosmos3DistilledModularPipeline | ||||||
|
|
||||||
| [[autodoc]] Cosmos3DistilledModularPipeline | ||||||
|
|
||||||
| - all | ||||||
| - __call__ | ||||||
|
|
||||||
| ## CosmosActionCondition | ||||||
|
|
||||||
| [[autodoc]] CosmosActionCondition | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to udpate the doc here, no? now it is a pipeline config