mstar.model.cosmos3.components.sound_tokenizer#

Cosmos3 AVAE sound tokenizer (decoder-only), ported from the diffusers-format sound_tokenizer/ checkpoint component that ships with the Cosmos3 models.

The checkpoint is an Oobleck-style 1D decoder (Snake activations, weight-normed convs) that turns joint-denoised sound latents [B, C=64, T] into a waveform [B, channels=2, T * hop_size] at 48 kHz. The safetensors decoder.* keys use the classic weight_g/weight_v weight-norm naming, which this module reproduces one-to-one so loading is a plain name-matching stream with a completeness check (same design as the transformer loader).

Classes

Cosmos3SoundTokenizer(config)

Decoder-only AVAE for Cosmos3 sound latents.

OobleckDecoder(channels, input_channels, ...)

Latent [B, C_latent, T] -> waveform [B, audio_channels, T * prod(strides)].

OobleckDecoderBlock(input_dim, output_dim[, ...])

Upsampling block: snake -> transposed conv (stride upsample) -> 3 residual units.

OobleckResidualUnit([dimension, dilation])

Dilated residual unit (snake -> conv k7 -> snake -> conv k1).

Snake1d(hidden_dim[, logscale])

1D Snake activation (x + 1/b * sin^2(a x)) with log-scale parameters.

class mstar.model.cosmos3.components.sound_tokenizer.Cosmos3SoundTokenizer(config)[source]#

Bases: Module

Decoder-only AVAE for Cosmos3 sound latents.

Built from the checkpoint’s sound_tokenizer/config.json (Oobleck decoder geometry, sample rate, channel count, hop size) and loaded strictly from sound_tokenizer/diffusion_pytorch_model.safetensors — every decoder parameter must be filled, so a layout drift surfaces as a load error rather than silently wrong audio.

Parameters:

config (dict[str, Any])

CONFIG_NAME = 'config.json'#
WEIGHTS_NAME = 'diffusion_pytorch_model.safetensors'#
decode(latents)[source]#

Sound latents [B, C, T] or [C, T] -> waveform in [-1, 1] ([B, audio_channels, T * hop_size], squeezed for unbatched input).

Parameters:

latents (Tensor)

Return type:

Tensor

classmethod from_pretrained(checkpoint_dir, device='cpu', dtype=torch.bfloat16)[source]#
Parameters:
Return type:

Cosmos3SoundTokenizer

get_audio_num_samples(num_latent_frames)[source]#
Parameters:

num_latent_frames (int)

Return type:

int

get_latent_num_frames(num_audio_samples)[source]#
Parameters:

num_audio_samples (int)

Return type:

int

class mstar.model.cosmos3.components.sound_tokenizer.OobleckDecoder(channels, input_channels, audio_channels, upsampling_ratios, channel_multiples)[source]#

Bases: Module

Latent [B, C_latent, T] -> waveform [B, audio_channels, T * prod(strides)].

Parameters:
  • channels (int)

  • input_channels (int)

  • audio_channels (int)

  • upsampling_ratios (list[int])

  • channel_multiples (list[int])

forward(hidden_state)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

hidden_state (Tensor)

Return type:

Tensor

class mstar.model.cosmos3.components.sound_tokenizer.OobleckDecoderBlock(input_dim, output_dim, stride=1, output_padding=0)[source]#

Bases: Module

Upsampling block: snake -> transposed conv (stride upsample) -> 3 residual units.

Parameters:
  • input_dim (int)

  • output_dim (int)

  • stride (int)

  • output_padding (int)

forward(hidden_state)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

hidden_state (Tensor)

Return type:

Tensor

class mstar.model.cosmos3.components.sound_tokenizer.OobleckResidualUnit(dimension=16, dilation=1)[source]#

Bases: Module

Dilated residual unit (snake -> conv k7 -> snake -> conv k1).

Parameters:
  • dimension (int)

  • dilation (int)

forward(hidden_state)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

hidden_state (Tensor)

Return type:

Tensor

class mstar.model.cosmos3.components.sound_tokenizer.Snake1d(hidden_dim, logscale=True)[source]#

Bases: Module

1D Snake activation (x + 1/b * sin^2(a x)) with log-scale parameters.

Parameters:
forward(hidden_states)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

hidden_states (Tensor)

Return type:

Tensor