Automatic Speech Recognition
MLX
ONNX
Safetensors
asr
speech-recognition
robust-asr
quantized
int4
4bit
mixed-precision
dwq
on-device
apple-silicon
qwen3
qwen3-asr
mega-asr
Instructions to use Reza2kn/mega-asr-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Reza2kn/mega-asr-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir mega-asr-mlx Reza2kn/mega-asr-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
Update README: mixed-precision (8/4) at 92.2% recommended
Browse files
README.md
CHANGED
|
@@ -16,8 +16,8 @@ tags:
|
|
| 16 |
- quantized
|
| 17 |
- int4
|
| 18 |
- 4bit
|
|
|
|
| 19 |
- dwq
|
| 20 |
-
- distillation-aware-quantization
|
| 21 |
- on-device
|
| 22 |
- apple-silicon
|
| 23 |
- qwen3
|
|
@@ -28,23 +28,23 @@ base_model: zhifeixie/Mega-ASR
|
|
| 28 |
base_model_relation: quantized
|
| 29 |
---
|
| 30 |
|
| 31 |
-
# Mega-ASR β MLX 4-bit
|
| 32 |
|
| 33 |
-
MLX
|
| 34 |
the 1.7B-parameter robust multilingual ASR foundation model built on Qwen3-ASR-1.7B.
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
## What's in this repo
|
| 41 |
|
| 42 |
| File | Size | Role |
|
| 43 |
| --- | ---: | --- |
|
| 44 |
-
| `mlx/llm-
|
| 45 |
-
| `mlx/llm-dwq4/
|
| 46 |
-
| `onnx/audio_encoder_fp32.onnx` |
|
| 47 |
-
| `tokenizer/*` | β | Original Qwen3-ASR tokenizer (with audio special tokens
|
| 48 |
| `examples/*.wav` | ~3 MB | 8 noisy benchmark clips from Voices-in-the-Wild-Bench |
|
| 49 |
| `inference.py` | β | End-to-end ASR pipeline: ONNX encoder + MLX LLM |
|
| 50 |
|
|
@@ -53,17 +53,38 @@ logits on a calibration corpus, recovering most of the post-training drift.
|
|
| 53 |
8-clip [Voices-in-the-Wild-Bench](https://github.com/xzf-thu/Voices-in-the-Wild-Bench)
|
| 54 |
agreement (1 β WER), prompt forced to `language English`:
|
| 55 |
|
| 56 |
-
| Variant | Encoder |
|
| 57 |
-
| --- | --- | --- | ---: | ---: |
|
| 58 |
-
| PT bf16 (original) | fp16 | fp16 | 95.1% | 7.5 GB |
|
| 59 |
-
| ONNX recommended (GPTQ) | INT8 ONNX | INT4 GPTQ | 92.7% | 2.3 GB |
|
| 60 |
-
| **MLX
|
| 61 |
-
| MLX 4-bit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
## Inference
|
| 69 |
|
|
@@ -72,13 +93,13 @@ pip install mlx mlx-lm onnxruntime soundfile transformers librosa numpy
|
|
| 72 |
git clone https://huggingface.co/Reza2kn/mega-asr-mlx
|
| 73 |
cd mega-asr-mlx
|
| 74 |
python inference.py --encoder-path onnx/audio_encoder_fp32.onnx \
|
| 75 |
-
--mlx-llm-path mlx/llm-
|
| 76 |
--examples-dir examples
|
| 77 |
```
|
| 78 |
|
| 79 |
-
|
| 80 |
1. mel features (Whisper preprocessor) β ONNX audio encoder (onnxruntime CPU) β audio embeddings (1, F, 2048)
|
| 81 |
-
2. tokenize the Qwen3-ASR chat prompt with `audio_pad_id=151676`, expand the single
|
| 82 |
3. embed all tokens via `model.model.embed_tokens` (MLX), scatter audio embeddings at the audio_pad positions
|
| 83 |
4. greedy decode via MLX with `input_embeddings`
|
| 84 |
|
|
@@ -87,24 +108,27 @@ The pipeline runs:
|
|
| 87 |
- LLM extracted from `zhifeixie/Mega-ASR/Qwen3-ASR-1.7B/` by stripping the
|
| 88 |
`thinker.model.` prefix from layer weights and dropping the tied `lm_head`
|
| 89 |
(relies on `tie_word_embeddings=True`).
|
| 90 |
-
-
|
| 91 |
-
|
| 92 |
-
-
|
| 93 |
-
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
- Audio encoder ONNX is reused unchanged from
|
| 97 |
[Reza2kn/mega-asr-onnx](https://huggingface.co/Reza2kn/mega-asr-onnx).
|
| 98 |
|
| 99 |
## Performance
|
| 100 |
|
| 101 |
-
| Hardware | Cold load | Warm (3-
|
| 102 |
| --- | ---: | ---: |
|
| 103 |
-
| M-series Mac (MLX) | ~3 s | ~1.5 s (LLM @ ~
|
|
|
|
| 104 |
|
| 105 |
## Credits
|
| 106 |
|
| 107 |
- Original model: [zhifeixie/Mega-ASR](https://huggingface.co/zhifeixie/Mega-ASR) (1.7B params, Apache-2.0)
|
| 108 |
-
- MLX port + DWQ: this repo
|
| 109 |
- Benchmark: [Voices-in-the-Wild-Bench](https://github.com/xzf-thu/Voices-in-the-Wild-Bench)
|
| 110 |
- DWQ tool: [`mlx_lm.quant.dwq`](https://github.com/ml-explore/mlx-lm) (Apple Inc.)
|
|
|
|
| 16 |
- quantized
|
| 17 |
- int4
|
| 18 |
- 4bit
|
| 19 |
+
- mixed-precision
|
| 20 |
- dwq
|
|
|
|
| 21 |
- on-device
|
| 22 |
- apple-silicon
|
| 23 |
- qwen3
|
|
|
|
| 28 |
base_model_relation: quantized
|
| 29 |
---
|
| 30 |
|
| 31 |
+
# Mega-ASR β MLX 4-bit
|
| 32 |
|
| 33 |
+
MLX deployment of [zhifeixie/Mega-ASR](https://huggingface.co/zhifeixie/Mega-ASR),
|
| 34 |
the 1.7B-parameter robust multilingual ASR foundation model built on Qwen3-ASR-1.7B.
|
| 35 |
|
| 36 |
+
Two LLM variants ship in this repo. The **recommended** one is the mixed-precision
|
| 37 |
+
build β 8-bit attention + 4-bit MLP layers β which closes the quality gap to ONNX
|
| 38 |
+
GPTQ at the smallest viable size.
|
| 39 |
|
| 40 |
## What's in this repo
|
| 41 |
|
| 42 |
| File | Size | Role |
|
| 43 |
| --- | ---: | --- |
|
| 44 |
+
| `mlx/llm-mixed8_4/` | **1.5 GB** | **Recommended** Qwen3 LLM, 8-bit attention + 4-bit MLP (5.0 bpw avg) |
|
| 45 |
+
| `mlx/llm-dwq4/` | 923 MB | 4-bit DWQ-distilled (smallest, slight quality drop) |
|
| 46 |
+
| `onnx/audio_encoder_fp32.onnx` | 1.27 GB | 24-layer Whisper-style audio encoder (ONNX fp32, run via onnxruntime). MLX port is on the roadmap. |
|
| 47 |
+
| `tokenizer/*` | β | Original Qwen3-ASR tokenizer (with audio special tokens `<\|audio_pad\|>` etc.) |
|
| 48 |
| `examples/*.wav` | ~3 MB | 8 noisy benchmark clips from Voices-in-the-Wild-Bench |
|
| 49 |
| `inference.py` | β | End-to-end ASR pipeline: ONNX encoder + MLX LLM |
|
| 50 |
|
|
|
|
| 53 |
8-clip [Voices-in-the-Wild-Bench](https://github.com/xzf-thu/Voices-in-the-Wild-Bench)
|
| 54 |
agreement (1 β WER), prompt forced to `language English`:
|
| 55 |
|
| 56 |
+
| Variant | Encoder | LLM | Bpw | Agreement | Total size |
|
| 57 |
+
| --- | --- | --- | ---: | ---: | ---: |
|
| 58 |
+
| PT bf16 (original) | fp16 | fp16 | 16 | 95.1% | 7.5 GB |
|
| 59 |
+
| ONNX recommended (GPTQ) | INT8 ONNX | INT4 GPTQ | ~4.5 | 92.7% | 2.3 GB |
|
| 60 |
+
| **MLX recommended (mixed)** | **fp32 ONNX** | **MLX 8/4 mixed** | **5.0** | **92.2%** | **~2.8 GB** |
|
| 61 |
+
| MLX 4-bit DWQ | fp32 ONNX | MLX 4-bit DWQ | 4.5 | 89.9% | ~2.2 GB |
|
| 62 |
+
| MLX 4-bit (no DWQ) | fp32 ONNX | MLX 4-bit | 4.5 | 89.1% | ~2.2 GB |
|
| 63 |
+
|
| 64 |
+
The mixed variant gets all 6 "easy" samples perfect and improves the 2 hard
|
| 65 |
+
samples (`echo`, `recording`) β only the audio-quality-limited tail remains.
|
| 66 |
+
|
| 67 |
+
### Why mixed precision
|
| 68 |
|
| 69 |
+
Pure 4-bit MLX hits a quality wall around 89% because mlx-lm's affine
|
| 70 |
+
quantization is naive groupwise (no calibration, no GPTQ-style error
|
| 71 |
+
redistribution). Attention layers are the most quality-sensitive in Qwen3 β
|
| 72 |
+
keeping them at 8-bit while dropping MLP layers to 4-bit recovers all the
|
| 73 |
+
4-bit quality loss at only ~12% more weight memory than uniform 8-bit.
|
| 74 |
+
|
| 75 |
+
| Variant | Attention | MLP | Bpw | Agreement |
|
| 76 |
+
| --- | --- | --- | ---: | ---: |
|
| 77 |
+
| pure 4-bit | 4-bit | 4-bit | 4.5 | 89.1% |
|
| 78 |
+
| **mixed 8/4** | **8-bit** | **4-bit** | **5.0** | **92.2%** |
|
| 79 |
+
| mixed 8/6 | 8-bit | 6-bit | 6.5 | 91.4% |
|
| 80 |
+
| 6-bit | 6-bit | 6-bit | 6.5 | 90.7% |
|
| 81 |
+
| 8-bit | 8-bit | 8-bit | 8.5 | 92.2% |
|
| 82 |
+
|
| 83 |
+
The mixed 8/4 build is Pareto-optimal β same quality as full 8-bit at ~60%
|
| 84 |
+
of its size, and 2.3 percentage points higher agreement than DWQ-distilled
|
| 85 |
+
4-bit. DWQ on plain-text data couldn't bridge the gap because Mega-ASR's
|
| 86 |
+
inference distribution (scattered audio embeddings into a text prompt) is
|
| 87 |
+
out-of-distribution for the bf16 teacher's plain-text calibration corpus.
|
| 88 |
|
| 89 |
## Inference
|
| 90 |
|
|
|
|
| 93 |
git clone https://huggingface.co/Reza2kn/mega-asr-mlx
|
| 94 |
cd mega-asr-mlx
|
| 95 |
python inference.py --encoder-path onnx/audio_encoder_fp32.onnx \
|
| 96 |
+
--mlx-llm-path mlx/llm-mixed8_4 \
|
| 97 |
--examples-dir examples
|
| 98 |
```
|
| 99 |
|
| 100 |
+
Pipeline:
|
| 101 |
1. mel features (Whisper preprocessor) β ONNX audio encoder (onnxruntime CPU) β audio embeddings (1, F, 2048)
|
| 102 |
+
2. tokenize the Qwen3-ASR chat prompt with `audio_pad_id=151676`, expand the single placeholder to F copies
|
| 103 |
3. embed all tokens via `model.model.embed_tokens` (MLX), scatter audio embeddings at the audio_pad positions
|
| 104 |
4. greedy decode via MLX with `input_embeddings`
|
| 105 |
|
|
|
|
| 108 |
- LLM extracted from `zhifeixie/Mega-ASR/Qwen3-ASR-1.7B/` by stripping the
|
| 109 |
`thinker.model.` prefix from layer weights and dropping the tied `lm_head`
|
| 110 |
(relies on `tie_word_embeddings=True`).
|
| 111 |
+
- **Mixed-precision quant** via `mlx_lm.utils.quantize_model` with a
|
| 112 |
+
per-layer `quant_predicate`:
|
| 113 |
+
- q_proj / k_proj / v_proj / o_proj β 8-bit
|
| 114 |
+
- gate_proj / up_proj / down_proj β 4-bit
|
| 115 |
+
- group_size=64, mode=affine
|
| 116 |
+
- **DWQ variant** via `mlx_lm.quant.dwq --bits 4 --group-size 64
|
| 117 |
+
--num-samples 64 --max-seq-length 256 --learning-rate 1e-6`. 64 distillation
|
| 118 |
+
steps on tulu-3-sft-mixture reduced KL loss from ~0.18 to ~0.14.
|
| 119 |
- Audio encoder ONNX is reused unchanged from
|
| 120 |
[Reza2kn/mega-asr-onnx](https://huggingface.co/Reza2kn/mega-asr-onnx).
|
| 121 |
|
| 122 |
## Performance
|
| 123 |
|
| 124 |
+
| Hardware | Cold load | Warm (3-4 s audio) |
|
| 125 |
| --- | ---: | ---: |
|
| 126 |
+
| M-series Mac (MLX, mixed8_4) | ~3 s | ~1.5 s (LLM @ ~50 tps) |
|
| 127 |
+
| M-series Mac (MLX, dwq4) | ~3 s | ~1.5 s (LLM @ ~60 tps) |
|
| 128 |
|
| 129 |
## Credits
|
| 130 |
|
| 131 |
- Original model: [zhifeixie/Mega-ASR](https://huggingface.co/zhifeixie/Mega-ASR) (1.7B params, Apache-2.0)
|
| 132 |
+
- MLX port + mixed-precision + DWQ: this repo
|
| 133 |
- Benchmark: [Voices-in-the-Wild-Bench](https://github.com/xzf-thu/Voices-in-the-Wild-Bench)
|
| 134 |
- DWQ tool: [`mlx_lm.quant.dwq`](https://github.com/ml-explore/mlx-lm) (Apple Inc.)
|