Skip to content

Cosmos3 edge support#14181

Open
atharvajoshi10 wants to merge 8 commits into
huggingface:mainfrom
atharvajoshi10:cosmos3-edge-support
Open

Cosmos3 edge support#14181
atharvajoshi10 wants to merge 8 commits into
huggingface:mainfrom
atharvajoshi10:cosmos3-edge-support

Conversation

@atharvajoshi10

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds support for Cosmos 3 Edge Generator

@github-actions

Copy link
Copy Markdown
Contributor

Hi @atharvajoshi10, 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.

@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

Comment thread scripts/convert_cosmos3_to_diffusers.py
Comment thread src/diffusers/models/transformers/transformer_cosmos3.py Outdated
Comment thread src/diffusers/models/transformers/transformer_cosmos3.py Outdated
Comment thread src/diffusers/models/transformers/transformer_cosmos3.py Outdated
Comment thread src/diffusers/models/transformers/transformer_cosmos3.py Outdated
@yiyixuxu yiyixuxu added the no-issue-needed for PRs that do not require link to an issue label Jul 14, 2026
@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

Copy link
Copy Markdown
Collaborator

@atharvajoshi10 can you look into the test failing? I think the repo was removed

Comment thread tests/pipelines/cosmos/test_cosmos3.py Outdated
Comment thread src/diffusers/models/transformers/transformer_cosmos3.py Outdated
Comment thread tests/pipelines/cosmos/test_cosmos3.py
Comment thread tests/models/transformers/test_models_transformer_cosmos3.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.

my bad I completely forgot review the tests on last PR so I reviewed the entire file, left some comments on tests added from previous PR as well

assert state.get("uncond_packed_static") is None


def test_cosmos3_text_step_uses_pipeline_system_prompt_and_safety_configs(monkeypatch):

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 just move this test to the ModularPipelineTesterMixin?
if you want to best the behavior of use_system_prompt you can do something like this

text_encoder_block = Cosmos3TextEncoderStep()
text_pipe = text_encoder_block.init_pipeline(self.pretrained_model_name_or_path)
text_pipe.load_components()
text_pipe.disable_safety_checker()
assert text_pipe.config_default_use_system_prompt == True

ids1 = text_pipe(prompt=..., output="cond_input_ids") 
ids2 = text_pipe(prompt = , use_system_prompt=True, output="cond_input_ids") 
ids3 = text_pipe(prompt = , use_system_prompt=False, output="cond_input_ids")

text_pipe.update_components(
          default_use_system_prompt=default_use_system_prompt,
      )
assert text_pipe.config_default_use_system_prompt == False

ids4= text_pipe(prompt=... output="cond_input_ids")
ids5 = text_pipe(prompt = , use_system_prompt=True, output="cond_input_ids") 
ids6 = text_pipe(prompt = , use_system_prompt=False, output="cond_input_ids")

# compare
assert list(ids1) == list(ids2) == list(ids5) # ids with system prompt
assert list(ids3) == list(ids4) == list(ids6) # ids without system prompt
assert len(ids1) > len(id3) # system prompt adds tokens

assert state.get("cond_input_ids").shape == (1, 1)


def test_cosmos3_native_flow_schedule_uses_edge_sigma_grid(monkeypatch):

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.

similarly, can we move this test to TestCosmos3OmniModularPipelineFast as well?

  def test_set_timesteps_native_flow_schedule(self):
      timesteps_pipe = Cosmos3SetTimestepsStep().init_pipeline(self.pretrained_model_name_or_path)
      timesteps_pipe.load_components()
      assert timesteps_pipe.config.use_native_flow_schedule is False
  
      timesteps_default = timesteps_pipe(num_inference_steps=4, output="timesteps")

      timesteps_pipe.update_components(
          scheduler=UniPCMultistepScheduler(num_train_timesteps=100, use_flow_sigmas=True),
          use_native_flow_schedule=True,
      )
      timesteps_native = timesteps_pipe(num_inference_steps=4, output="timesteps")
  
      expected_sigmas = ...
      torch.testing.assert_close(
          timesteps_pipe.scheduler.sigmas[:-1], expected_sigmas
      )
      assert timesteps_native.tolist() == [99, 74, 49, 24] 
      assert not torch.equal(timesteps_native, timesteps_default)

pipe(**inputs, output=self.output_name)


def test_cosmos3_pack_steps_do_not_require_vae():

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 mixin too?
you can create your packing block easier

pack_block = Cosmos3VisionPackSequenceStep()
pack_pipe = pack_block.init_pipeline(self.pretrained_model_name_or_path)
pack_pipe.load_components()

assert action_segment["action_mrope_ids"].shape == (3, 4)


def test_cosmos3_denoise_input_steps_assemble_modality_segments():

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 to the mixin too
and use the correct API to run them, i.e. pipeline blocks are not meant to be executed, even though you can if you directly pass it a state; the API to run a block is to turn it into a pipeline and then you can pass input directly, it is more meaningful to test the execution API

 blocks = SequentialPipelineBlocks.from_blocks_dict(
      {
          "vision": Cosmos3VisionDenoiseInputStep(),
          "sound": Cosmos3SoundDenoiseInputStep(),
          "action": Cosmos3ActionDenoiseInputStep(),
      }
  )
  pipe = blocks.init_pipeline()  # no repo needed — these blocks declare no components
  
  state = pipe(
      cond_text_segment=cond_text_segment,
      uncond_text_segment=uncond_text_segment,
      ...  # all eight segments, passed as normal call kwargs
  )

  torch.testing.assert_close(state.get("cond_position_ids"), torch.cat([...], dim=1))
  assert state.get("cond_sequence_length") == 6

assert state.get("timesteps").tolist() == [0, 1, 2, 3]


def test_cosmos3_modular_model_index_takes_precedence(tmp_path):

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.

this is testing loading behavior of base pipeline, can you remove it?
we can add a test to our base test to test it

@@ -338,9 +394,22 @@


def test_cosmos3_model_index_fallback_resolves_modular_pipeline(tmp_path):

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 remove this too?

state.set("num_frames", 5)
state.set("height", 32)
state.set("width", 32)
_, state = vae_encoder(pipe, state)

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 here, can you use you turn the block into pipeline to run?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models modular-pipelines no-issue-needed for PRs that do not require link to an issue pipelines size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants