Feature Extraction
Transformers
Safetensors
MLX
moss-audio-tokenizer
audio
audio-tokenizer
neural-codec
moss-tts-family
MOSS Audio Tokenizer
speech-tokenizer
mlx-audio
custom_code
Instructions to use mlx-community/MOSS-Audio-Tokenizer-Nano with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlx-community/MOSS-Audio-Tokenizer-Nano with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="mlx-community/MOSS-Audio-Tokenizer-Nano", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("mlx-community/MOSS-Audio-Tokenizer-Nano", trust_remote_code=True, dtype="auto") - MLX
How to use mlx-community/MOSS-Audio-Tokenizer-Nano with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir MOSS-Audio-Tokenizer-Nano mlx-community/MOSS-Audio-Tokenizer-Nano
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,195 +1,203 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
library_name: transformers
|
| 4 |
-
tags:
|
| 5 |
-
- audio
|
| 6 |
-
- audio-tokenizer
|
| 7 |
-
- neural-codec
|
| 8 |
-
- moss-tts-family
|
| 9 |
-
- MOSS Audio Tokenizer
|
| 10 |
-
- speech-tokenizer
|
| 11 |
-
-
|
| 12 |
-
--
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
*
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
``
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
wav =
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
```
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
-
|
| 128 |
-
- one
|
| 129 |
-
-
|
| 130 |
-
-
|
| 131 |
-
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
)
|
| 160 |
-
|
| 161 |
-
#
|
| 162 |
-
|
| 163 |
-
[
|
| 164 |
-
streaming=True,
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
)
|
| 174 |
-
|
| 175 |
-
#
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
``
|
| 194 |
-
|
| 195 |
-
``
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: transformers
|
| 4 |
+
tags:
|
| 5 |
+
- audio
|
| 6 |
+
- audio-tokenizer
|
| 7 |
+
- neural-codec
|
| 8 |
+
- moss-tts-family
|
| 9 |
+
- MOSS Audio Tokenizer
|
| 10 |
+
- speech-tokenizer
|
| 11 |
+
- mlx
|
| 12 |
+
- mlx-audio
|
| 13 |
+
base_model: OpenMOSS-Team/MOSS-Audio-Tokenizer
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# mlx-community/MOSS-Audio-Tokenizer
|
| 17 |
+
|
| 18 |
+
This model was converted to MLX format from [`OpenMOSS-Team/MOSS-Audio-Tokenizer`](https://huggingface.co/OpenMOSS-Team/MOSS-Audio-Tokenizer) using mlx-audio version **0.4.0**.
|
| 19 |
+
|
| 20 |
+
Refer to the [original model card](https://huggingface.co/OpenMOSS-Team/MOSS-Audio-Tokenizer) for more details on the model.
|
| 21 |
+
|
| 22 |
+
# MossAudioTokenizer
|
| 23 |
+
|
| 24 |
+
This is the code for MOSS-Audio-Tokenizer presented in [MOSS-Audio-Tokenizer: Scaling Audio Tokenizers for Future Audio Foundation Models](https://arxiv.org/abs/2602.10934).
|
| 25 |
+
|
| 26 |
+
**MOSSAudioTokenizer** is a unified discrete audio tokenizer based on the **Cat** (**C**ausal **A**udio **T**okenizer with **T**ransformer) architecture. Scaling to 1.6 billion parameters, it functions as a unified discrete interface, delivering both lossless-quality reconstruction and high-level semantic alignment.
|
| 27 |
+
|
| 28 |
+
**Key Features:**
|
| 29 |
+
|
| 30 |
+
* **Extreme Compression & Variable Bitrate**: It compresses 48kHz stereo audio into a remarkably low frame rate of 12.5Hz. Utilizing a 32-layer Residual LFQ quantizer stack, it supports high-fidelity reconstruction across a wide range of bitrates.
|
| 31 |
+
* **Pure Transformer Architecture**: The model features a "CNN-free" homogeneous architecture built entirely from Causal Transformer blocks. With 1.6B combined parameters (Encoder + Decoder), it ensures exceptional scalability and supports low-latency streaming inference.
|
| 32 |
+
* **Large-Scale General Audio Training**: Trained on 3 million hours of diverse audio data, the model excels at encoding and reconstructing all audio domains, including speech, sound effects, and music.
|
| 33 |
+
* **Unified Semantic-Acoustic Representation**: While achieving state-of-the-art reconstruction quality, Cat produces discrete tokens that are "semantic-rich," making them ideal for downstream tasks like speech understanding (ASR) and generation (TTS).
|
| 34 |
+
* **Fully Trained From Scratch**: Cat does not rely on any pretrained encoders (such as HuBERT or Whisper) or distillation from teacher models. All representations are learned autonomously from raw data.
|
| 35 |
+
* **End-to-End Joint Optimization**: All components—including the encoder, quantizer, decoder, discriminator, and a decoder-only LLM for semantic alignment—are optimized jointly in a single unified training pipeline.
|
| 36 |
+
|
| 37 |
+
**Summary:**
|
| 38 |
+
By combining a simple, scalable architecture with massive-scale data, the Cat architecture overcomes the bottlenecks of traditional audio tokenizers. It provides a robust, high-fidelity, and semantically grounded interface for the next generation of native audio foundation models.
|
| 39 |
+
|
| 40 |
+
This repository contains a lightweight remote-code implementation that mirrors the current 🤗 Transformers
|
| 41 |
+
`transformers.models.moss_audio_tokenizer` module. It is intended to be uploaded to a Hugging Face Hub model repository
|
| 42 |
+
and loaded with `trust_remote_code=True` when needed.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
### Quickstart
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
import torch
|
| 51 |
+
from transformers import AutoModel
|
| 52 |
+
import torchaudio
|
| 53 |
+
|
| 54 |
+
repo_id = "OpenMOSS-Team/MOSS-Audio-Tokenizer"
|
| 55 |
+
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
|
| 56 |
+
|
| 57 |
+
wav, sr = torchaudio.load('demo/demo_gt.wav')
|
| 58 |
+
if sr != model.sampling_rate:
|
| 59 |
+
wav = torchaudio.functional.resample(wav, sr, model.sampling_rate)
|
| 60 |
+
if wav.shape[0] == 1:
|
| 61 |
+
wav = wav.repeat(model.config.number_channels, 1)
|
| 62 |
+
else:
|
| 63 |
+
wav = wav[: model.config.number_channels]
|
| 64 |
+
wav = wav.unsqueeze(0)
|
| 65 |
+
enc = model.encode(wav, return_dict=True)
|
| 66 |
+
print(f"enc.audio_codes.shape: {enc.audio_codes.shape}")
|
| 67 |
+
dec = model.decode(enc.audio_codes, return_dict=True)
|
| 68 |
+
print(f"dec.audio.shape: {dec.audio.shape}")
|
| 69 |
+
wav = dec.audio.squeeze(0)
|
| 70 |
+
torchaudio.save("demo/demo_rec.wav", wav, sample_rate=model.sampling_rate)
|
| 71 |
+
|
| 72 |
+
# Decode using only the first 8 layers of the RVQ
|
| 73 |
+
dec_rvq8 = model.decode(enc.audio_codes[:8], return_dict=True)
|
| 74 |
+
wav_rvq8 = dec_rvq8.audio.squeeze(0)
|
| 75 |
+
torchaudio.save("demo/demo_rec_rvq8.wav", wav_rvq8, sample_rate=model.sampling_rate)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### Attention Backend And Compute Dtype
|
| 79 |
+
|
| 80 |
+
`config.attention_implementation` controls whether transformer layers prefer `sdpa` or `flash_attention_2`.
|
| 81 |
+
`config.compute_dtype` controls the non-quantizer autocast dtype and supports `fp32`, `bf16`, and `fp16`.
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
model.set_attention_implementation("flash_attention_2")
|
| 85 |
+
model.set_compute_dtype("fp16")
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
The quantizer always runs in fp32.
|
| 89 |
+
|
| 90 |
+
### Streaming
|
| 91 |
+
|
| 92 |
+
`MossAudioTokenizerModel.encode`, `decode`, `batch_encode`, and `batch_decode` all support streaming through a
|
| 93 |
+
`chunk_duration` argument.
|
| 94 |
+
|
| 95 |
+
- `chunk_duration` is expressed in seconds.
|
| 96 |
+
- `chunk_duration * MossAudioTokenizerConfig.sampling_rate` must be divisible by `MossAudioTokenizerConfig.downsample_rate`.
|
| 97 |
+
- Streaming batch inference is supported.
|
| 98 |
+
- The public waveform interface expects stereo inputs shaped `(2, T)` or batched stereo inputs shaped `(B, 2, T)`.
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
import torch
|
| 102 |
+
from transformers import AutoModel
|
| 103 |
+
|
| 104 |
+
repo_id = "OpenMOSS-Team/MOSS-Audio-Tokenizer"
|
| 105 |
+
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
|
| 106 |
+
audio = torch.randn(2, 48000 * 6) # dummy stereo waveform
|
| 107 |
+
|
| 108 |
+
# 6.0s @ 48kHz = 288000 samples, divisible by downsample_rate=3840
|
| 109 |
+
enc = model.encode(audio.unsqueeze(0), return_dict=True, chunk_duration=0.08)
|
| 110 |
+
dec = model.decode(enc.audio_codes, return_dict=True, chunk_duration=0.08)
|
| 111 |
+
|
| 112 |
+
batch_enc = model.batch_encode([audio, audio[:, : 48000 * 3]], chunk_duration=0.08)
|
| 113 |
+
codes_list = [
|
| 114 |
+
batch_enc.audio_codes[:, i, : batch_enc.audio_codes_lengths[i]]
|
| 115 |
+
for i in range(batch_enc.audio_codes.shape[1])
|
| 116 |
+
]
|
| 117 |
+
batch_dec = model.batch_decode(codes_list, chunk_duration=0.08)
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
#### Continuous Batch Streaming Decode
|
| 121 |
+
|
| 122 |
+
For decoder-side continuous batching, prefer `batch_decode(..., streaming=True, ...)`.
|
| 123 |
+
|
| 124 |
+
- The first streaming call may pass `max_batch_size=...`. If it is omitted, the first batch size reserves the
|
| 125 |
+
fixed-slot decoder budget for that public stream.
|
| 126 |
+
- Same-size calls continue the existing logical rows in-order.
|
| 127 |
+
- If a later call is larger, the new rows are admitted by tail append.
|
| 128 |
+
- `finalize_indices` means "decode these rows one last time, then evict them". The indices are interpreted against the
|
| 129 |
+
pre-call logical order.
|
| 130 |
+
- After a finalize call returns, the next streaming call may use the smaller survivor batch.
|
| 131 |
+
- `reset_stream=True` discards the hidden public streaming state and starts a fresh stream.
|
| 132 |
+
|
| 133 |
+
Milestone 1 boundaries:
|
| 134 |
+
|
| 135 |
+
- decode-only continuous batching
|
| 136 |
+
- one active streaming decode state per model instance
|
| 137 |
+
- fixed-slot decoder reservation from `max_batch_size`
|
| 138 |
+
- no encode-side continuous batching
|
| 139 |
+
- no physical compaction of surviving decode slots
|
| 140 |
+
- no multi-session concurrency on one model instance
|
| 141 |
+
|
| 142 |
+
```python
|
| 143 |
+
import torch
|
| 144 |
+
from transformers import AutoModel
|
| 145 |
+
|
| 146 |
+
repo_id = "OpenMOSS-Team/MOSS-Audio-Tokenizer"
|
| 147 |
+
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True).eval()
|
| 148 |
+
num_quantizers = model.config.quantizer_kwargs["num_quantizers"]
|
| 149 |
+
|
| 150 |
+
codes_a0 = torch.randint(0, 8, (num_quantizers, 2))
|
| 151 |
+
codes_b0 = torch.randint(0, 8, (num_quantizers, 3))
|
| 152 |
+
codes_a1 = torch.randint(0, 8, (num_quantizers, 2))
|
| 153 |
+
codes_b1 = torch.randint(0, 8, (num_quantizers, 2))
|
| 154 |
+
codes_c0 = torch.randint(0, 8, (num_quantizers, 1))
|
| 155 |
+
codes_a2 = torch.randint(0, 8, (num_quantizers, 1))
|
| 156 |
+
codes_b2 = torch.randint(0, 8, (num_quantizers, 2))
|
| 157 |
+
codes_c1 = torch.randint(0, 8, (num_quantizers, 2))
|
| 158 |
+
codes_b3 = torch.randint(0, 8, (num_quantizers, 1))
|
| 159 |
+
codes_c2 = torch.randint(0, 8, (num_quantizers, 1))
|
| 160 |
+
|
| 161 |
+
# First call reserves 3 fixed decoder slots for A and B.
|
| 162 |
+
out_ab0 = model.batch_decode(
|
| 163 |
+
[codes_a0, codes_b0],
|
| 164 |
+
streaming=True,
|
| 165 |
+
max_batch_size=3,
|
| 166 |
+
reset_stream=True,
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
# Same logical rows continue in-order; C is a tail append.
|
| 170 |
+
out_abc1 = model.batch_decode(
|
| 171 |
+
[codes_a1, codes_b1, codes_c0],
|
| 172 |
+
streaming=True,
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
# Finalize A against the pre-call logical order. A still decodes in this call,
|
| 176 |
+
# then is evicted immediately afterward.
|
| 177 |
+
out_abc2 = model.batch_decode(
|
| 178 |
+
[codes_a2, codes_b2, codes_c1],
|
| 179 |
+
streaming=True,
|
| 180 |
+
finalize_indices=[0],
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
# The next call can shrink to the surviving logical rows only.
|
| 184 |
+
out_bc3 = model.batch_decode(
|
| 185 |
+
[codes_b3, codes_c2],
|
| 186 |
+
streaming=True,
|
| 187 |
+
)
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
## Repository layout
|
| 191 |
+
|
| 192 |
+
- `configuration_moss_audio_tokenizer.py`
|
| 193 |
+
- `modeling_moss_audio_tokenizer.py`
|
| 194 |
+
- `__init__.py`
|
| 195 |
+
- `config.json`
|
| 196 |
+
- model weights
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
## Citation
|
| 200 |
+
If you use this code or result in your paper, please cite our work as:
|
| 201 |
+
```tex
|
| 202 |
+
|
| 203 |
+
```
|