mlx-meralion 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yingxu He
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: mlx-meralion
3
+ Version: 0.1.0
4
+ Summary: MLX-native inference for MERaLiON AudioLLM on Apple Silicon
5
+ Author: Yingxu He
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/YingxuH/mlx-audiollm
8
+ Project-URL: Repository, https://github.com/YingxuH/mlx-audiollm
9
+ Project-URL: Issues, https://github.com/YingxuH/mlx-audiollm/issues
10
+ Keywords: mlx,apple-silicon,speech,asr,audio,llm,meralion
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: mlx>=0.18.0
26
+ Requires-Dist: mlx-lm>=0.20.0
27
+ Requires-Dist: numpy>=1.24.0
28
+ Requires-Dist: librosa>=0.10.0
29
+ Requires-Dist: soundfile>=0.12.0
30
+ Requires-Dist: safetensors>=0.4.0
31
+ Requires-Dist: huggingface-hub>=0.20.0
32
+ Requires-Dist: tokenizers>=0.15.0
33
+ Requires-Dist: transformers>=4.46.0
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
36
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # mlx-meralion
40
+
41
+ MLX-native inference for [MERaLiON AudioLLM](https://huggingface.co/MERaLiON) on Apple Silicon.
42
+
43
+ MERaLiON is A*STAR's multimodal audio-language model for speech transcription, translation, spoken question answering, and more.
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ pip install mlx-meralion
49
+ ```
50
+
51
+ Requires macOS on Apple Silicon (M1/M2/M3/M4) and Python 3.10+.
52
+
53
+ ## Quick Start
54
+
55
+ ### Python API
56
+
57
+ ```python
58
+ from mlx_meralion import load_model, transcribe
59
+
60
+ # Load model (auto-downloads from HuggingFace on first use)
61
+ model = load_model("MERaLiON/MERaLiON-2-10B-MLX") # 10B 8-bit, recommended
62
+ # model = load_model("MERaLiON/MERaLiON-2-3B-MLX") # 3B fp16, smaller
63
+
64
+ # Transcribe speech
65
+ text = transcribe(model, "audio.wav")
66
+ print(text)
67
+
68
+ # Translate to Chinese
69
+ text = transcribe(model, "audio.wav", task="translate_zh")
70
+
71
+ # Spoken question answering
72
+ text = transcribe(model, "audio.wav", task="sqa", question="What is the speaker talking about?")
73
+
74
+ # Summarize dialogue
75
+ text = transcribe(model, "audio.wav", task="summarize")
76
+ ```
77
+
78
+ ### CLI
79
+
80
+ ```bash
81
+ # ASR (default task)
82
+ mlx-meralion --model MERaLiON/MERaLiON-2-10B-MLX --audio audio.wav --task asr
83
+
84
+ # Translation
85
+ mlx-meralion --model MERaLiON/MERaLiON-2-10B-MLX --audio audio.wav --task translate_zh
86
+
87
+ # Custom instruction
88
+ mlx-meralion --model MERaLiON/MERaLiON-2-10B-MLX --audio audio.wav --instruction "Summarize this in one sentence."
89
+ ```
90
+
91
+ ## Supported Tasks
92
+
93
+ | Task | Description |
94
+ |------|-------------|
95
+ | `asr` | Speech-to-text transcription |
96
+ | `translate_zh` | Translate to Chinese |
97
+ | `translate_id` | Translate to Indonesian |
98
+ | `translate_ms` | Translate to Malay |
99
+ | `translate_ta` | Translate to Tamil |
100
+ | `sqa` | Spoken question answering (requires `question=`) |
101
+ | `summarize` | Dialogue summarization |
102
+ | `paralinguistics` | Speaker characteristic analysis |
103
+
104
+ ## Available Models
105
+
106
+ | Model | Size | RAM | Quality | HuggingFace |
107
+ |-------|------|-----|---------|-------------|
108
+ | MERaLiON-2-10B-MLX | ~10 GB | 16+ GB | Best | [MERaLiON/MERaLiON-2-10B-MLX](https://huggingface.co/MERaLiON/MERaLiON-2-10B-MLX) |
109
+ | MERaLiON-2-3B-MLX | ~6 GB | 8+ GB | Good | [MERaLiON/MERaLiON-2-3B-MLX](https://huggingface.co/MERaLiON/MERaLiON-2-3B-MLX) |
110
+
111
+ ## Features
112
+
113
+ - **Apple Silicon native**: Runs entirely on MLX with GPU acceleration
114
+ - **N-gram blocking**: Automatically prevents repetitive output (matching HuggingFace quality)
115
+ - **Smart chunking**: Long audio split at 30s boundaries; short tails merged to prevent hallucination
116
+ - **Auto-download**: HuggingFace models are downloaded and cached automatically
117
+ - **Multiple tasks**: ASR, translation, QA, summarization, and more
118
+
119
+ ## Architecture
120
+
121
+ ```
122
+ Audio (WAV/MP3/FLAC)
123
+ -> Whisper Encoder (1280-d)
124
+ -> LayerNorm + MLP Adaptor
125
+ -> Speech embeddings merged into text sequence
126
+ -> Gemma2 Decoder -> text output
127
+ ```
128
+
129
+ ## License
130
+
131
+ MIT
@@ -0,0 +1,93 @@
1
+ # mlx-meralion
2
+
3
+ MLX-native inference for [MERaLiON AudioLLM](https://huggingface.co/MERaLiON) on Apple Silicon.
4
+
5
+ MERaLiON is A*STAR's multimodal audio-language model for speech transcription, translation, spoken question answering, and more.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install mlx-meralion
11
+ ```
12
+
13
+ Requires macOS on Apple Silicon (M1/M2/M3/M4) and Python 3.10+.
14
+
15
+ ## Quick Start
16
+
17
+ ### Python API
18
+
19
+ ```python
20
+ from mlx_meralion import load_model, transcribe
21
+
22
+ # Load model (auto-downloads from HuggingFace on first use)
23
+ model = load_model("MERaLiON/MERaLiON-2-10B-MLX") # 10B 8-bit, recommended
24
+ # model = load_model("MERaLiON/MERaLiON-2-3B-MLX") # 3B fp16, smaller
25
+
26
+ # Transcribe speech
27
+ text = transcribe(model, "audio.wav")
28
+ print(text)
29
+
30
+ # Translate to Chinese
31
+ text = transcribe(model, "audio.wav", task="translate_zh")
32
+
33
+ # Spoken question answering
34
+ text = transcribe(model, "audio.wav", task="sqa", question="What is the speaker talking about?")
35
+
36
+ # Summarize dialogue
37
+ text = transcribe(model, "audio.wav", task="summarize")
38
+ ```
39
+
40
+ ### CLI
41
+
42
+ ```bash
43
+ # ASR (default task)
44
+ mlx-meralion --model MERaLiON/MERaLiON-2-10B-MLX --audio audio.wav --task asr
45
+
46
+ # Translation
47
+ mlx-meralion --model MERaLiON/MERaLiON-2-10B-MLX --audio audio.wav --task translate_zh
48
+
49
+ # Custom instruction
50
+ mlx-meralion --model MERaLiON/MERaLiON-2-10B-MLX --audio audio.wav --instruction "Summarize this in one sentence."
51
+ ```
52
+
53
+ ## Supported Tasks
54
+
55
+ | Task | Description |
56
+ |------|-------------|
57
+ | `asr` | Speech-to-text transcription |
58
+ | `translate_zh` | Translate to Chinese |
59
+ | `translate_id` | Translate to Indonesian |
60
+ | `translate_ms` | Translate to Malay |
61
+ | `translate_ta` | Translate to Tamil |
62
+ | `sqa` | Spoken question answering (requires `question=`) |
63
+ | `summarize` | Dialogue summarization |
64
+ | `paralinguistics` | Speaker characteristic analysis |
65
+
66
+ ## Available Models
67
+
68
+ | Model | Size | RAM | Quality | HuggingFace |
69
+ |-------|------|-----|---------|-------------|
70
+ | MERaLiON-2-10B-MLX | ~10 GB | 16+ GB | Best | [MERaLiON/MERaLiON-2-10B-MLX](https://huggingface.co/MERaLiON/MERaLiON-2-10B-MLX) |
71
+ | MERaLiON-2-3B-MLX | ~6 GB | 8+ GB | Good | [MERaLiON/MERaLiON-2-3B-MLX](https://huggingface.co/MERaLiON/MERaLiON-2-3B-MLX) |
72
+
73
+ ## Features
74
+
75
+ - **Apple Silicon native**: Runs entirely on MLX with GPU acceleration
76
+ - **N-gram blocking**: Automatically prevents repetitive output (matching HuggingFace quality)
77
+ - **Smart chunking**: Long audio split at 30s boundaries; short tails merged to prevent hallucination
78
+ - **Auto-download**: HuggingFace models are downloaded and cached automatically
79
+ - **Multiple tasks**: ASR, translation, QA, summarization, and more
80
+
81
+ ## Architecture
82
+
83
+ ```
84
+ Audio (WAV/MP3/FLAC)
85
+ -> Whisper Encoder (1280-d)
86
+ -> LayerNorm + MLP Adaptor
87
+ -> Speech embeddings merged into text sequence
88
+ -> Gemma2 Decoder -> text output
89
+ ```
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,13 @@
1
+ """MLX-native inference for MERaLiON AudioLLM on Apple Silicon.
2
+
3
+ Quick start:
4
+ from mlx_meralion import load_model, transcribe
5
+
6
+ model = load_model("MERaLiON/MERaLiON-2-10B-MLX")
7
+ text = transcribe(model, "audio.wav")
8
+ """
9
+
10
+ __version__ = "0.1.0"
11
+
12
+ from .inference import load_model as load_model, transcribe as transcribe, LoadedModel as LoadedModel
13
+ from .processor import get_task_prompt as get_task_prompt
@@ -0,0 +1,115 @@
1
+ """MLP adaptor module for MERaLiON.
2
+
3
+ Bridges the Whisper encoder output (1280-d, 1500 timesteps) to the
4
+ SEA-LION/Gemma2 decoder input (hidden_size-d, 100 timesteps).
5
+
6
+ Two variants:
7
+ - MERaLiONSpeechAudioAdapter: v1 simple MLP (modeling_meralion.py)
8
+ - MERaLiONSpeechAudioAdapterLarge: v2 gated MLP (modeling_meralion2.py)
9
+ """
10
+
11
+ import mlx.core as mx
12
+ import mlx.nn as nn
13
+
14
+
15
+ class MERaLiONSpeechAudioAdapter(nn.Module):
16
+ """Audio-to-text adapter with timestep compression (v1).
17
+
18
+ Matches MERaLiONSpeechAudioAdaper from modeling_meralion.py.
19
+ Architecture: reshape -> Linear+SiLU -> Linear+SiLU+Linear -> output
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ speech_hidden_size: int = 1280,
25
+ text_hidden_size: int = 3584,
26
+ scale_factor: int = 15,
27
+ ):
28
+ super().__init__()
29
+ self.scale_factor = scale_factor
30
+ mlp_input_dim = speech_hidden_size * scale_factor
31
+
32
+ self.mlp_adapter = nn.Sequential(
33
+ nn.Linear(mlp_input_dim, speech_hidden_size),
34
+ nn.SiLU(),
35
+ )
36
+
37
+ self.speech_llm_proj = nn.Sequential(
38
+ nn.Linear(speech_hidden_size, speech_hidden_size * 4),
39
+ nn.SiLU(),
40
+ nn.Linear(speech_hidden_size * 4, text_hidden_size),
41
+ )
42
+
43
+ def __call__(self, speech_embeds: mx.array) -> mx.array:
44
+ B, T, D = speech_embeds.shape
45
+ new_T = (T // self.scale_factor) * self.scale_factor
46
+ speech_embeds = speech_embeds[:, :new_T, :]
47
+ speech_embeds = speech_embeds.reshape(
48
+ B, new_T // self.scale_factor, D * self.scale_factor
49
+ )
50
+ speech_embeds = self.mlp_adapter(speech_embeds)
51
+ speech_embeds = self.speech_llm_proj(speech_embeds)
52
+ return speech_embeds
53
+
54
+
55
+ class MERaLiONSpeechAudioAdapterLarge(nn.Module):
56
+ """Audio-to-text adapter with gated linear unit (v2 / MERaLiON-2).
57
+
58
+ Matches MERaLiON2SpeechAudioAdaperLarge from modeling_meralion2.py.
59
+ Architecture: reshape -> Linear+SiLU -> GLU(gate_proj, pool_proj) -> out_proj
60
+ """
61
+
62
+ def __init__(
63
+ self,
64
+ speech_hidden_size: int = 1280,
65
+ text_hidden_size: int = 3584,
66
+ scale_factor: int = 15,
67
+ ):
68
+ super().__init__()
69
+ self.scale_factor = scale_factor
70
+ mlp_input_dim = speech_hidden_size * scale_factor
71
+ intermediate_dim = speech_hidden_size * 5
72
+
73
+ self.mlp_adapter = nn.Sequential(
74
+ nn.Linear(mlp_input_dim, intermediate_dim),
75
+ nn.SiLU(),
76
+ )
77
+
78
+ self.gate_proj = nn.Linear(intermediate_dim, intermediate_dim)
79
+ self.pool_proj = nn.Linear(intermediate_dim, intermediate_dim)
80
+ self.act_fn = nn.SiLU()
81
+
82
+ self.out_proj = nn.Linear(intermediate_dim, text_hidden_size)
83
+
84
+ def __call__(self, speech_embeds: mx.array) -> mx.array:
85
+ B, T, D = speech_embeds.shape
86
+ new_T = (T // self.scale_factor) * self.scale_factor
87
+ speech_embeds = speech_embeds[:, :new_T, :]
88
+ speech_embeds = speech_embeds.reshape(
89
+ B, new_T // self.scale_factor, D * self.scale_factor
90
+ )
91
+
92
+ speech_embeds = self.mlp_adapter(speech_embeds)
93
+ speech_embeds = self.act_fn(self.gate_proj(speech_embeds)) * self.pool_proj(speech_embeds)
94
+ speech_embeds = self.out_proj(speech_embeds)
95
+ return speech_embeds
96
+
97
+
98
+ def create_adapter(
99
+ variant: str,
100
+ speech_hidden_size: int = 1280,
101
+ text_hidden_size: int = 3584,
102
+ scale_factor: int = 15,
103
+ ) -> nn.Module:
104
+ """Create the appropriate adapter variant.
105
+
106
+ Args:
107
+ variant: "v1" for simple MLP, "v2" or "large" for gated MLP
108
+ """
109
+ if variant in ("v2", "large", "meralion2"):
110
+ return MERaLiONSpeechAudioAdapterLarge(
111
+ speech_hidden_size, text_hidden_size, scale_factor
112
+ )
113
+ return MERaLiONSpeechAudioAdapter(
114
+ speech_hidden_size, text_hidden_size, scale_factor
115
+ )