Skip to content

Cosmos3 Distilled support - #14177

Merged
yiyixuxu merged 10 commits into
huggingface:mainfrom
yzhautouskay:yzhautouskay/cosmos3_distilled
Jul 17, 2026
Merged

Cosmos3 Distilled support#14177
yiyixuxu merged 10 commits into
huggingface:mainfrom
yzhautouskay:yzhautouskay/cosmos3_distilled

Conversation

@yzhautouskay

@yzhautouskay yzhautouskay commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Cosmos3 distilled (few-step) support

Adds inference support for the distilled few-step Cosmos3 checkpoints through the
modular pipeline (Cosmos3OmniModularPipeline).

Checkpoints supported

  • nvidia/Cosmos3-Super-Text2Image-4Step (distilled T2I)
  • nvidia/Cosmos3-Super-Image2Video-4Step (distilled I2V)

Both ship a FlowMatchEulerDiscreteScheduler with a fixed sigma schedule
(scheduler.config.fixed_step_sampler_config.t_list) and bake classifier-free
guidance into the weights. They are only supported via the modular pipeline; the
task-based Cosmos3OmniPipeline does not implement the distilled contract.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions github-actions Bot added size/L PR with diff > 200 LOC documentation Improvements or additions to documentation modular-pipelines and removed size/L PR with diff > 200 LOC labels Jul 13, 2026

@yiyixuxu yiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!
i left some comments

Comment thread src/diffusers/modular_pipelines/cosmos/before_denoise.py
Comment thread src/diffusers/modular_pipelines/cosmos/modular_pipeline.py Outdated
Comment thread src/diffusers/modular_pipelines/cosmos/modular_pipeline.py Outdated
Comment thread src/diffusers/modular_pipelines/cosmos/modular_pipeline.py Outdated
Comment thread src/diffusers/modular_pipelines/cosmos/denoise.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Hi @yzhautouskay, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

@yzhautouskay

Copy link
Copy Markdown
Contributor Author

thanks @yiyixuxu! I've refactored it to have separate Cosmos3DistilledModularPipeline

@yiyixuxu

Copy link
Copy Markdown
Collaborator

@yzhautouskay can you resolve the conflict?

@yzhautouskay
yzhautouskay force-pushed the yzhautouskay/cosmos3_distilled branch from 177ee1e to 3ac7ec0 Compare July 15, 2026 09:43
@yzhautouskay
yzhautouskay force-pushed the yzhautouskay/cosmos3_distilled branch from 3ac7ec0 to abb37e7 Compare July 15, 2026 09:48

@yiyixuxu yiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I left some comments

Comment thread docs/source/en/api/pipelines/cosmos3.md Outdated
Comment thread src/diffusers/modular_pipelines/modular_pipeline.py Outdated
Comment thread src/diffusers/modular_pipelines/cosmos/before_denoise.py Outdated
Comment thread src/diffusers/modular_pipelines/cosmos/before_denoise.py Outdated
Comment thread src/diffusers/modular_pipelines/cosmos/encoders.py Outdated
]


def _fake_distilled_components(t_list=(1.0, 0.75, 0.5, 0.25)):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, distilled tests now use ModularPipelineTesterMixin. For now tiny fixture lives under my personal account at yzhautouskay/tiny-cosmos3-distilled-modular-pipe
Could you create hf-internal-testing/tiny-cosmos3-distilled-modular-pipe and copy it over ? I'll then flip the TINY_DISTILLED_REPO constant in the test (and pretrained_model_name_or_path will need to be changed for components in modular_model_index.json)

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yiyixuxu yiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I left some final comments on tests & docs, we can merge after these are addressed

Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated
vae_encoder.select_block(image=object(), video=object())


def test_cosmos3_distilled_set_timesteps_declares_distilled_configs():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this test to the TestCosmos3DistilledModularPipelineFast too
Also, it'd be more meaningful to test the final pipeline's config

pipe = self.pipeline_class()
assert pipe.config.is_distilled is True
assert pipe.config.distilled_sigmas is None  

Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated
Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated
Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated
Cosmos3DistilledTextEncoderStep._check_inputs(SimpleNamespace(prompt=["a robot", "another"]))


def test_cosmos3_distilled_set_timesteps_rejects_step_count_override():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment https://github.com/huggingface/diffusers/pull/14177/changes#r3598260664
I think it's more meaningful to test all the behavior on final pipeline (not individual steps)

  def test_rejects_num_inference_steps_override(self):
      pipe = self.get_pipeline()
      inputs = self.get_dummy_inputs()
      inputs["num_inference_steps"] = 10
      
      with pytest.raises(..."):
          pipe(**inputs, output=self.output_name)

Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated
Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated
Comment thread docs/source/en/api/pipelines/cosmos3.md Outdated
Comment thread docs/source/en/api/pipelines/cosmos3.md Outdated

# TODO: move this fixture to `hf-internal-testing/tiny-cosmos3-distilled-modular-pipe` and update the
# repo name here. Hosted on a personal account for now so the PR can be tested.
TINY_DISTILLED_REPO = "yzhautouskay/tiny-cosmos3-distilled-modular-pipe"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tests/modular_pipelines/cosmos/test_modular_pipeline_cosmos3_distilled.py Outdated

@yiyixuxu yiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@yiyixuxu
yiyixuxu merged commit 8eac6ad into huggingface:main Jul 17, 2026
19 checks passed
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 28, 2026
… checkpoint

Register nvidia/Cosmos3-Super-Image2Video-4Step and add the one algorithmic
piece distilled I2V needs: the stochastic FlowMatchEuler step re-noises every
position each step, so the clean conditioning frame is re-anchored after every
scheduler step via the denoise post_step_fn hook (matching the diffusers
distilled loop, PR huggingface/diffusers#14177). Base UniPC sampling is
unchanged: deterministic steps never move a zero-velocity frame.

This lifts the temporary rejection of image-conditioned requests on distilled
checkpoints, which was added to hold the line until per-step re-anchoring
landed.

Also raise on enable_audio=True when the checkpoint ships no audio tower
(weight-presence guard, not workflow policy), make the final conditioning
re-injection in-place instead of cloning the full latent tensor, and accept
the I2V-4Step transformer config shape (sound_dim null, no action fields).
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 28, 2026
Smoke: run the documented example invocation (deterministic PIL conditioning
image, omni-default 720p x 189 shape) and assert a non-empty MP4.

Quality gate: unlike the existing TRT-LLM self-goldens, the golden video is
produced by the reference implementation (diffusers Cosmos3 distilled modular
pipeline, huggingface/diffusers#14177, with its per-step SDE noise made
generator-seeded), so the gate checks the denoising trajectory against the
reference rather than regression against a past TRT-LLM run. Full provenance
(diffusers commit, RNG patch, corrected modular index, generation parameters)
is recorded in cosmos3_i2v_4step_lpips_golden_video.json. Threshold 0.10 =
0.0563 measured at golden creation plus headroom for the ~0.04 cross-host
kernel drift documented in the harness; validated at 0.0588 on B200.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 28, 2026
… checkpoint

Register nvidia/Cosmos3-Super-Image2Video-4Step and add the one algorithmic
piece distilled I2V needs: the stochastic FlowMatchEuler step re-noises every
position each step, so the clean conditioning frame is re-anchored after every
scheduler step via the denoise post_step_fn hook (matching the diffusers
distilled loop, PR huggingface/diffusers#14177). Base UniPC sampling is
unchanged: deterministic steps never move a zero-velocity frame.

This lifts the temporary rejection of image-conditioned requests on distilled
checkpoints, which was added to hold the line until per-step re-anchoring
landed.

Also raise on enable_audio=True when the checkpoint ships no audio tower
(weight-presence guard, not workflow policy), make the final conditioning
re-injection in-place instead of cloning the full latent tensor, and accept
the I2V-4Step transformer config shape (sound_dim null, no action fields).

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 28, 2026
Smoke: run the documented example invocation (deterministic PIL conditioning
image, omni-default 720p x 189 shape) and assert a non-empty MP4.

Quality gate: unlike the existing TRT-LLM self-goldens, the golden video is
produced by the reference implementation (diffusers Cosmos3 distilled modular
pipeline, huggingface/diffusers#14177, with its per-step SDE noise made
generator-seeded), so the gate checks the denoising trajectory against the
reference rather than regression against a past TRT-LLM run. Full provenance
(diffusers commit, RNG patch, corrected modular index, generation parameters)
is recorded in cosmos3_i2v_4step_lpips_golden_video.json. Threshold 0.10 =
0.0563 measured at golden creation plus headroom for the ~0.04 cross-host
kernel drift documented in the harness; validated at 0.0588 on B200.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 28, 2026
… checkpoint

Register nvidia/Cosmos3-Super-Image2Video-4Step and add the one algorithmic
piece distilled I2V needs: the stochastic FlowMatchEuler step re-noises every
position each step, so the clean conditioning frame is re-anchored after every
scheduler step via the denoise post_step_fn hook (matching the diffusers
distilled loop, PR huggingface/diffusers#14177). Base UniPC sampling is
unchanged: deterministic steps never move a zero-velocity frame.

This lifts the temporary rejection of image-conditioned requests on distilled
checkpoints, which was added to hold the line until per-step re-anchoring
landed.

Also raise on enable_audio=True when the checkpoint ships no audio tower
(weight-presence guard, not workflow policy), make the final conditioning
re-injection in-place instead of cloning the full latent tensor, and accept
the I2V-4Step transformer config shape (sound_dim null, no action fields).

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 28, 2026
Smoke: run the documented example invocation (deterministic PIL conditioning
image, omni-default 720p x 189 shape) and assert a non-empty MP4.

Quality gate: unlike the existing TRT-LLM self-goldens, the golden video is
produced by the reference implementation (diffusers Cosmos3 distilled modular
pipeline, huggingface/diffusers#14177, with its per-step SDE noise made
generator-seeded), so the gate checks the denoising trajectory against the
reference rather than regression against a past TRT-LLM run. Full provenance
(diffusers commit, RNG patch, corrected modular index, generation parameters)
is recorded in cosmos3_i2v_4step_lpips_golden_video.json. Threshold 0.10 =
0.0563 measured at golden creation plus headroom for the ~0.04 cross-host
kernel drift documented in the harness; validated at 0.0588 on B200.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 30, 2026
… checkpoint

Register nvidia/Cosmos3-Super-Image2Video-4Step and add the one algorithmic
piece distilled I2V needs: the stochastic FlowMatchEuler step re-noises every
position each step, so the clean conditioning frame is re-anchored after every
scheduler step via the denoise post_step_fn hook (matching the diffusers
distilled loop, PR huggingface/diffusers#14177). Base UniPC sampling is
unchanged: deterministic steps never move a zero-velocity frame.

This lifts the temporary rejection of image-conditioned requests on distilled
checkpoints, which was added to hold the line until per-step re-anchoring
landed.

Also raise on enable_audio=True when the checkpoint ships no audio tower
(weight-presence guard, not workflow policy), make the final conditioning
re-injection in-place instead of cloning the full latent tensor, and accept
the I2V-4Step transformer config shape (sound_dim null, no action fields).

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 30, 2026
Smoke: run the documented example invocation (deterministic PIL conditioning
image, omni-default 720p x 189 shape) and assert a non-empty MP4.

Quality gate: unlike the existing TRT-LLM self-goldens, the golden video is
produced by the reference implementation (diffusers Cosmos3 distilled modular
pipeline, huggingface/diffusers#14177, with its per-step SDE noise made
generator-seeded), so the gate checks the denoising trajectory against the
reference rather than regression against a past TRT-LLM run. Full provenance
(diffusers commit, RNG patch, corrected modular index, generation parameters)
is recorded in cosmos3_i2v_4step_lpips_golden_video.json. Threshold 0.10 =
0.0563 measured at golden creation plus headroom for the ~0.04 cross-host
kernel drift documented in the harness; validated at 0.0588 on B200.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 30, 2026
… checkpoint

Register nvidia/Cosmos3-Super-Image2Video-4Step and add the one algorithmic
piece distilled I2V needs: the stochastic FlowMatchEuler step re-noises every
position each step, so the clean conditioning frame is re-anchored after every
scheduler step via the denoise post_step_fn hook (matching the diffusers
distilled loop, PR huggingface/diffusers#14177). Base UniPC sampling is
unchanged: deterministic steps never move a zero-velocity frame.

This lifts the temporary rejection of image-conditioned requests on distilled
checkpoints, which was added to hold the line until per-step re-anchoring
landed.

Also raise on enable_audio=True when the checkpoint ships no audio tower
(weight-presence guard, not workflow policy), make the final conditioning
re-injection in-place instead of cloning the full latent tensor, and accept
the I2V-4Step transformer config shape (sound_dim null, no action fields).

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
ishovkun added a commit to ishovkun/TensorRT-LLM that referenced this pull request Jul 30, 2026
Smoke: run the documented example invocation (deterministic PIL conditioning
image, omni-default 720p x 189 shape) and assert a non-empty MP4.

Quality gate: unlike the existing TRT-LLM self-goldens, the golden video is
produced by the reference implementation (diffusers Cosmos3 distilled modular
pipeline, huggingface/diffusers#14177, with its per-step SDE noise made
generator-seeded), so the gate checks the denoising trajectory against the
reference rather than regression against a past TRT-LLM run. Full provenance
(diffusers commit, RNG patch, corrected modular index, generation parameters)
is recorded in cosmos3_i2v_4step_lpips_golden_video.json. Threshold 0.10 =
0.0563 measured at golden creation plus headroom for the ~0.04 cross-host
kernel drift documented in the harness; validated at 0.0588 on B200.

Signed-off-by: Igor Shovkun <ishovkun@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation modular-pipelines size/L PR with diff > 200 LOC tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants