Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Sound Encoder to Cosmos3#13911

Merged
dg845 merged 10 commits into
huggingface:mainfrom
MaciejBalaNV:cosmos3_sound_encoder
Jun 17, 2026
Merged

Add Sound Encoder to Cosmos3#13911
dg845 merged 10 commits into
huggingface:mainfrom
MaciejBalaNV:cosmos3_sound_encoder

Conversation

@MaciejBalaNV

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes # (issue)

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 models tests size/L PR with diff > 200 LOC labels Jun 10, 2026
Comment on lines +617 to +626
def _disable_encoder(self):
self.encoder = None
self._encoder_available = False
self.register_to_config(encoder_enabled=False)

def _fix_state_dict_keys_on_load(self, state_dict: OrderedDict) -> None:
super()._fix_state_dict_keys_on_load(state_dict)
if self.encoder is not None and not any(key.startswith("encoder.") for key in state_dict):
self._disable_encoder()

@yiyixuxu yiyixuxu Jun 10, 2026

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.

why do we need these two methods?

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.

It's an extra safety net for checkpoints that do not have the encoder weights. We will update the main checkpoint to have encoder weights, but I think it's still fine to keep this method in case of e.g. cached local checkpoints. We don't want them to break if people don't need the encoder weights.

@yiyixuxu yiyixuxu requested a review from dg845 June 10, 2026 20:37
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated

@dg845 dg845 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 for the PR! Left an initial design review :).

@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.

Comment thread src/diffusers/models/autoencoders/autoencoder_cosmos3_audio.py Outdated
Comment thread tests/models/autoencoders/test_models_autoencoder_cosmos3_audio.py Outdated

@dg845 dg845 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 for the changes! Left some follow up comments.

Signed-off-by: Maciej Bala <[email protected]>
Signed-off-by: Maciej Bala <[email protected]>
Signed-off-by: Maciej Bala <[email protected]>
@MaciejBalaNV MaciejBalaNV marked this pull request as ready for review June 15, 2026 14:34
@dg845

dg845 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

@bot /style

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Style bot fixed some files and pushed the changes.

Comment on lines +626 to +629
) -> Cosmos3AudioDecoderOutput | tuple[torch.Tensor]:
"""Encode then decode a waveform; ``sample_posterior=False`` (default) decodes the distribution mode (mean),
whereas the upstream Cosmos3 AVAE always samples — pass ``sample_posterior=True`` for reference-equivalent
behavior."""

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 update the Cosmos3AVAEAudioTokenizer.forward docstring to document the arguments and return values? This should fix the failure in this CI run.

@dg845 dg845 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 for your work on this PR! Left one comment about fixing a CI failure.

Signed-off-by: Maciej Bala <[email protected]>
@MaciejBalaNV

Copy link
Copy Markdown
Contributor Author

Fixed CI. I think the PR is ready to be merged now. The checkpoints on HF should be updated today or tomorrow with encoder weights, but the current encoder-less checkpoints also work, as long as we don't call the encode method.

@dg845 dg845 merged commit 212a98d into huggingface:main Jun 17, 2026
15 checks passed
DN6 pushed a commit that referenced this pull request Jul 1, 2026
* Initial version of sound encoder

Signed-off-by: Maciej Bala <[email protected]>

* Answered review comments

Signed-off-by: Maciej Bala <[email protected]>

* Reshaped encoder Snake1d

Signed-off-by: Maciej Bala <[email protected]>

* Updated test

Signed-off-by: Maciej Bala <[email protected]>

* Fixed test

Signed-off-by: Maciej Bala <[email protected]>

* Apply style fixes

* Added docstring

Signed-off-by: Maciej Bala <[email protected]>

---------

Signed-off-by: Maciej Bala <[email protected]>
Co-authored-by: dg845 <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants