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
Add README
Browse files
README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- zh
|
| 6 |
+
- ja
|
| 7 |
+
- ko
|
| 8 |
+
- multilingual
|
| 9 |
+
library_name: mlx
|
| 10 |
+
tags:
|
| 11 |
+
- mlx
|
| 12 |
+
- automatic-speech-recognition
|
| 13 |
+
- asr
|
| 14 |
+
- speech-recognition
|
| 15 |
+
- robust-asr
|
| 16 |
+
- quantized
|
| 17 |
+
- int4
|
| 18 |
+
- 4bit
|
| 19 |
+
- dwq
|
| 20 |
+
- distillation-aware-quantization
|
| 21 |
+
- on-device
|
| 22 |
+
- apple-silicon
|
| 23 |
+
- qwen3
|
| 24 |
+
- qwen3-asr
|
| 25 |
+
- mega-asr
|
| 26 |
+
pipeline_tag: automatic-speech-recognition
|
| 27 |
+
base_model: zhifeixie/Mega-ASR
|
| 28 |
+
base_model_relation: quantized
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
# Mega-ASR β MLX 4-bit DWQ
|
| 32 |
+
|
| 33 |
+
MLX 4-bit (DWQ-distilled) 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 |
+
Quantized via [`mlx_lm.quant.dwq`](https://github.com/ml-explore/mlx-lm) (Distillation-aware
|
| 37 |
+
Weight Quantization) β the 4-bit weights are fine-tuned to match the bf16 teacher's
|
| 38 |
+
logits on a calibration corpus, recovering most of the post-training drift.
|
| 39 |
+
|
| 40 |
+
## What's in this repo
|
| 41 |
+
|
| 42 |
+
| File | Size | Role |
|
| 43 |
+
| --- | ---: | --- |
|
| 44 |
+
| `mlx/llm-dwq4/model.safetensors` | **923 MB** | Qwen3 1.7B LLM, MLX 4-bit DWQ, group_size=64 (4.5 bits/weight) |
|
| 45 |
+
| `mlx/llm-dwq4/{config,tokenizer*}.json` | β | mlx-lm load metadata + LLM tokenizer |
|
| 46 |
+
| `onnx/audio_encoder_fp32.onnx` | **1.27 GB** | 24-layer Whisper-style audio encoder (ONNX fp32, run via onnxruntime). MLX port is planned. |
|
| 47 |
+
| `tokenizer/*` | β | Original Qwen3-ASR tokenizer (with audio special tokens). Required because the LLM-only tokenizer drops `<\|audio_pad\|>`, `<\|audio_start\|>`, 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 |
+
|
| 51 |
+
## Quality (bench)
|
| 52 |
+
|
| 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 | Decoder | Agreement | Total size |
|
| 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 4-bit DWQ (this repo)** | **fp32 ONNX** | **MLX 4-bit DWQ** | **89.9%** | **~2.2 GB** |
|
| 61 |
+
| MLX 4-bit (no DWQ) | fp32 ONNX | MLX 4-bit | 89.1% | ~2.2 GB |
|
| 62 |
+
|
| 63 |
+
DWQ recovers +0.8% over straight mlx-lm 4-bit quantization. Audio encoder is
|
| 64 |
+
still ONNX fp32 because the `qwen3_asr_audio_encoder` architecture (custom
|
| 65 |
+
chunked Whisper-style with Conv2d front-end) isn't natively supported by
|
| 66 |
+
mlx-lm or mlx-whisper yet β porting it to pure MLX is on the roadmap.
|
| 67 |
+
|
| 68 |
+
## Inference
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
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-dwq4 \
|
| 76 |
+
--examples-dir examples
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
The pipeline runs:
|
| 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 pad placeholder to F copies
|
| 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 |
+
|
| 85 |
+
## Conversion details
|
| 86 |
+
|
| 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 |
+
- `mlx_lm.convert --hf-path <extracted> -q --q-bits 4 --q-group-size 64` β
|
| 91 |
+
base MLX 4-bit (4.501 bits/weight).
|
| 92 |
+
- `mlx_lm.quant.dwq --model <bf16-teacher> --bits 4 --group-size 64
|
| 93 |
+
--num-samples 64 --max-seq-length 256 --learning-rate 1e-6` β
|
| 94 |
+
DWQ-distilled weights. 64 steps of distillation on tulu-3-sft-mixture
|
| 95 |
+
reduced validation KL loss from ~0.18 to ~0.14.
|
| 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-4s audio) |
|
| 102 |
+
| --- | ---: | ---: |
|
| 103 |
+
| M-series Mac (MLX) | ~3 s | ~1.5 s (LLM @ ~60 tps) |
|
| 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.)
|