Yoursmiling mlboydaisuke commited on
Commit
beb49ee
·
1 Parent(s): 3008d1a

Fix i8 variant: keep encoder float32 (quantized encoder was broken) (#2)

Browse files

- Fix i8 variant: keep encoder float32 (quantized encoder was broken) (435b7e671b41230124c010ee318e10b70a4c9457)


Co-authored-by: Majima <mlboydaisuke@users.noreply.huggingface.co>

Files changed (2) hide show
  1. README.md +28 -17
  2. moonshine_tiny_5s_i8.tflite +2 -2
README.md CHANGED
@@ -20,9 +20,9 @@ tags:
20
  It transcribes English speech and is designed for fast on-device inference.
21
 
22
  This repository packages the model for [LiteRT](https://ai.google.dev/edge/litert):
23
- a float32 model, a dynamic-range int8 model, and ahead-of-time compiled
24
- variants for a range of MediaTek and Qualcomm SoCs so the model can run on the
25
- device NPU.
26
 
27
  ## Model description
28
 
@@ -49,7 +49,7 @@ transcription loop:
49
  | File | Description |
50
  |---|---|
51
  | `moonshine_tiny_5s_f32.tflite` | float32 model (109 MB) |
52
- | `moonshine_tiny_5s_i8.tflite` | dynamic-range int8 model (29 MB) |
53
  | `moonshine_tiny_5s_f32_MediaTek_*.tflite` | float32 AOT-compiled for MediaTek NPUs (per SoC) |
54
  | `moonshine_tiny_5s_f32_Qualcomm_*.tflite` | float32 AOT-compiled for Qualcomm NPUs (per SoC) |
55
 
@@ -175,6 +175,12 @@ if __name__ == "__main__":
175
  python transcribe.py --wav sample.wav
176
  ```
177
 
 
 
 
 
 
 
178
  ## Performance
179
 
180
  Measured on one 5 s window of continuous speech (11 output tokens), CPU
@@ -186,30 +192,35 @@ with the CPU accelerator at default threading:
186
  | Device | Variant | Encode | Decode | Window total | RTF |
187
  |---|---|---|---|---|---|
188
  | iPhone 17 Pro | f32 | 10.9 ms | 70.2 ms | 81.2 ms | 0.016 |
189
- | iPhone 17 Pro | i8 | 16.3 ms | 67.5 ms | 84.1 ms | 0.017 |
190
  | Apple M4 Max (macOS) | f32 | 8.1 ms | 79.4 ms | 87.5 ms | 0.017 |
191
- | Apple M4 Max (macOS) | i8 | 8.8 ms | 76.7 ms | 85.5 ms | 0.017 |
192
  | Raspberry Pi 5 | f32 | 50.7 ms | 444.7 ms | 495.3 ms | 0.099 |
193
- | Raspberry Pi 5 | i8 | 33.4 ms | 269.4 ms | 303.1 ms | 0.061 |
194
 
195
  RTF = processing time / audio duration (lower is better; below 1.0 is faster
196
  than real time). Decode dominates and scales with the number of emitted
197
  tokens, so dense speech takes proportionally longer than sparse speech. The
198
- i8 model runs about 1.6x faster than f32 on the Pi 5's Cortex-A76; on Apple
199
- silicon (M4 Max, iPhone 17 Pro) the two are equally fast. The f32 greedy
200
- decode is deterministic across platforms: the same window produces
201
- bit-identical token sequences on all three devices.
 
 
 
202
 
203
  ### Accuracy note
204
 
205
  In a 12-clip spot check (LibriSpeech dev-clean samples plus two
206
  public-domain clips), the f32 model transcribes clips of up to 5 s at
207
- near-reference quality. The i8 variant currently shows significant
208
- transcription degradation on the same clips, which isolates to its quantized
209
- encoder (an f32 encoder with the i8 decoder matches full-f32 output almost
210
- exactly). Until a recalibrated i8 encoder is published, the f32 model or
211
- the f32 encoder combined with the i8 decoder is recommended where
212
- transcription quality matters.
 
 
213
 
214
  For the source model's quality, the
215
  [Moonshine paper](https://arxiv.org/abs/2410.15608) reports that Moonshine
 
20
  It transcribes English speech and is designed for fast on-device inference.
21
 
22
  This repository packages the model for [LiteRT](https://ai.google.dev/edge/litert):
23
+ a float32 model, an int8 model (dynamic-range-quantized decoder with a
24
+ float32 encoder), and ahead-of-time compiled variants for a range of MediaTek
25
+ and Qualcomm SoCs so the model can run on the device NPU.
26
 
27
  ## Model description
28
 
 
49
  | File | Description |
50
  |---|---|
51
  | `moonshine_tiny_5s_f32.tflite` | float32 model (109 MB) |
52
+ | `moonshine_tiny_5s_i8.tflite` | int8 model (52 MB): float32 encoder + dynamic-range int8 decoder |
53
  | `moonshine_tiny_5s_f32_MediaTek_*.tflite` | float32 AOT-compiled for MediaTek NPUs (per SoC) |
54
  | `moonshine_tiny_5s_f32_Qualcomm_*.tflite` | float32 AOT-compiled for Qualcomm NPUs (per SoC) |
55
 
 
175
  python transcribe.py --wav sample.wav
176
  ```
177
 
178
+ ### Android sample app
179
+
180
+ For an on-device Android demo that runs Moonshine (and other ASR models) with
181
+ hardware acceleration, see the LiteRT
182
+ [speech recognition sample](https://github.com/google-ai-edge/litert-samples/tree/main/samples/litert/speech_recognition).
183
+
184
  ## Performance
185
 
186
  Measured on one 5 s window of continuous speech (11 output tokens), CPU
 
192
  | Device | Variant | Encode | Decode | Window total | RTF |
193
  |---|---|---|---|---|---|
194
  | iPhone 17 Pro | f32 | 10.9 ms | 70.2 ms | 81.2 ms | 0.016 |
195
+ | iPhone 17 Pro | i8 | 10.7 ms | 69.3 ms | 80.0 ms | 0.016 |
196
  | Apple M4 Max (macOS) | f32 | 8.1 ms | 79.4 ms | 87.5 ms | 0.017 |
197
+ | Apple M4 Max (macOS) | i8 | 7.4 ms | 72.6 ms | 80.0 ms | 0.016 |
198
  | Raspberry Pi 5 | f32 | 50.7 ms | 444.7 ms | 495.3 ms | 0.099 |
199
+ | Raspberry Pi 5 | i8 | 50.3 ms | 267.4 ms | 317.7 ms | 0.064 |
200
 
201
  RTF = processing time / audio duration (lower is better; below 1.0 is faster
202
  than real time). Decode dominates and scales with the number of emitted
203
  tokens, so dense speech takes proportionally longer than sparse speech. The
204
+ i8 model's int8 decoder makes it about 1.6x faster than f32 on the Pi 5's
205
+ Cortex-A76; on Apple silicon (M4 Max, iPhone 17 Pro) the two are equally
206
+ fast. The greedy decode is deterministic across platforms: the same window
207
+ produces bit-identical f32 token sequences on all three devices, the i8
208
+ model reproduces the f32 token sequence exactly on the dense test window on
209
+ both Apple devices, and its transcripts are identical between the M4 Max
210
+ and the Pi 5 on all 12 test clips.
211
 
212
  ### Accuracy note
213
 
214
  In a 12-clip spot check (LibriSpeech dev-clean samples plus two
215
  public-domain clips), the f32 model transcribes clips of up to 5 s at
216
+ near-reference quality, and the i8 model matches it: the same overall word
217
+ error rate on the 12-clip harness (within chunking noise), word-level
218
+ divergence from the f32 transcripts of 2.5%, and encoder output that is
219
+ bit-identical to f32 because the encoder is not quantized. The encoder is kept in float32
220
+ deliberately — the convolutional audio frontend on the raw waveform does not
221
+ survive dynamic-range quantization (an earlier fully-quantized i8 upload
222
+ degraded badly for exactly this reason) — while the decoder, which dominates
223
+ latency, carries the int8 weights.
224
 
225
  For the source model's quality, the
226
  [Moonshine paper](https://arxiv.org/abs/2410.15608) reports that Moonshine
moonshine_tiny_5s_i8.tflite CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f45441f5710d745afdc376d0c60abe223e3daf1ad10b5327170dd40cc5fdfb3b
3
- size 29135952
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97abdeea122d579229091659c24c59d988c6419d453a200f6471241a53b9a9b9
3
+ size 51936896