Modern Apps git

← Modern-Apps.git

speech: drop ONNX Runtime

Commit
714b72126ec86ccd84570109a971afe50360a20d
Author
vayun-mathur <[email protected]>
When
2026-08-29 08:08 UTC (3 months ago)
Parents
5063779

Diff

SUPPLY_CHAIN_RISKS.md
diff --git a/SUPPLY_CHAIN_RISKS.md b/SUPPLY_CHAIN_RISKS.mdindex 1c3c4bc7ba..cfdb8d57b7 100644--- a/SUPPLY_CHAIN_RISKS.md+++ b/SUPPLY_CHAIN_RISKS.md@@ -50,20 +50,30 @@ These servers provide data/functionality that is NOT intrinsically tied to a sin  `speech` **no longer downloads anything**: -- **Speech-to-text** is `whisper-base` int8 ONNX (~77 MB) in `speech/src/main/assets/whisper-base/`, run on `onnxruntime-android` by `WhisperOnnxEngine.kt`. It replaced a 117 MB runtime download of the ncnn conversion from `data.vayunmathur.com/models/whisper-tiny/`. It was `whisper-tiny` until the swap to `base`, which roughly halves word error at the cost of about 36 MB of APK; the two exports declare identical operator sets, so the reduced ONNX Runtime build did not have to be regenerated. Upstream is **`onnx-community/whisper-base`** on HuggingFace (an ONNX Runtime dynamic quantization of `openai/whisper-base`, Apache-2.0), pinned to revision `1846881b` — a **build-host** dependency only, pinned by SHA-256 and refreshed by `scripts/speech/fetch_whisper_onnx.sh`. If it vanished, shipped builds keep transcribing. Note this moved the log-mel front end and the KV-cached decode loop into Kotlin (`WhisperFeatures.kt`, `WhisperOnnxEngine.kt`), because `onnx2ncnn` supports none of the quantized ops and the ncnn AAR expects a six-net decomposition HuggingFace does not export.+- **Speech-to-text** is `whisper-base` in `speech/src/main/assets/whisper-base/whisper_base.maml` (70.6 MiB int8), run on **`:library:ml`** by `WhisperEngine.kt`. It replaced two int8 ONNX exports totalling 76.9 MB on `onnxruntime-android`, which had replaced a 117 MB runtime download of the ncnn conversion from `data.vayunmathur.com/models/whisper-tiny/`. It was `whisper-tiny` until the swap to `base`, which roughly halves word error. Upstream is now the **fp32 checkpoint**, `openai/whisper-base` (Apache-2.0) pinned to revision `e37978b9`, a **build-host** dependency only, pinned by SHA-256 and rebuilt byte-for-byte by `scripts/ml/fetch_whisper.py`. Reading the checkpoint rather than the ONNX export is what lets `maml_convert.quantise_per_channel` quantise **per output channel** where onnxruntime quantised per tensor: measured over the encoder output, mean absolute error against fp32 is 0.029 against the export's 0.110, four times closer. The log-mel front end stays in Kotlin (`WhisperFeatures.kt`, pinned against HuggingFace by `WhisperFeaturesTest`); the KV-cached decode loop moved out of Kotlin into tested Rust (`post::whisper`). - **Text-to-speech** is **Supertonic 3** bundled in `speech/src/main/assets/supertonic/`, run on `:library:ml` - our own Vulkan compute runtime - by `SupertonicTtsService.kt`. It replaced Piper (VITS), whose voices were a **1,834 MB** runtime download across 42 SHA-256-pinned archives from `data.vayunmathur.com/models/piper/`, each needing a per-language espeak-ng dictionary generated on the build machine. One bundle of four networks now covers 31 languages and 10 voices; the `:library:downloadservice` and DataStore dependencies went with it, along with `scripts/speech/fetch_piper_model.sh`, `generate_piper_dict.py` and `generate_wordlist.py`. Reads stream out of the APK through a file descriptor, which is why `noCompress += "maml"` is load-bearing rather than an optimisation.    Two things about this one are unlike every other model here. **Its licence is use-restricted**: Supertonic 3 is **OpenRAIL**, the first such licence in this tree - everything else is Apache-2.0, MIT, ODbL or InsightFace's non-commercial research terms. And because it is bundled rather than downloaded, the restriction ships in the APK rather than being fetched by a user who went looking for it. It is a **build-host** dependency and no runtime dependency at all: upstream is **`Supertone/supertonic-3`** on HuggingFace, pinned to revision `3cadd1ee` with all four ONNX SHA-256s in `scripts/ml/fetch_supertonic.py`, which fetches it and drives both converters. The ONNX is not vendored - it is 398 MB against the 189 MiB of fp16 `.maml` it becomes, and nothing reads it at run time. The `.maml` are not committed either, for the reason `/.gitignore` gives, so `fetch_supertonic.py` is the only record of where the weights came from and the only way to rebuild them.    Two independent checks guard a bad rebuild, and they fail for different reasons: the pinned file SHA-256s catch a re-export or a truncated download, and each converter's layer-table digest in `maml_convert.EXPECTED_DIGEST` catches an export whose *structure* moved - which is what would make the hardcoded Rust forward passes read the right shapes holding the wrong numbers. Neither checks the numbers; `scripts/ml/onnx_parity.py` does, and its correlations against onnxruntime are recorded in the README beside the assets. -  The bundle is **107 MiB**, not the 198 MB the fp32 export folds to at fp16: every ungrouped `1 x 1` convolution in the sampler, the vocoder and the duration predictor is stored as int8 with one fp16 scale per output channel. That is 92% of the sampler's parameters and 87% of the vocoder's. The text encoder stays fp16 - quantising it cost more correlation than the other three combined and saved 6.6 MB of 198, so it was measured and reverted. With Whisper's 74.3 MiB, `:speech` ships 181.9 MiB of assets.+  The bundle is **107 MiB**, not the 198 MB the fp32 export folds to at fp16: every ungrouped `1 x 1` convolution in the sampler, the vocoder and the duration predictor is stored as int8 with one fp16 scale per output channel. That is 92% of the sampler's parameters and 87% of the vocoder's. The text encoder stays fp16 - quantising it cost more correlation than the other three combined and saved 6.6 MB of 198, so it was measured and reverted. With whisper-base's 71.6 MiB, `:speech` ships 179.2 MiB of assets and links no third-party inference runtime at all.    The language coverage is a deliberate regression as well as a gain: 42 languages became 31. TTS was **lost** for Chinese, Hebrew, Thai, Bengali, Telugu, Malayalam, Marathi, Urdu, Serbian, Norwegian, Catalan, Georgian, Kurdish, Luxembourgish, Nepali and Swahili, and **gained** for Estonian, Croatian, Lithuanian, Latvian and Slovenian. The dropped languages are absent from the engine's advertised voice list, so a user is never offered one that would be silent.  So a clean install both transcribes and speaks with no network at all. -`photos` **semantic search no longer needs a second app**. It previously delegated image/text embedding to the OpenAssistant app over IPC, so search only worked if OpenAssistant was installed, recent enough, and had finished a ~452 MB SigLIP2 download. It now runs **TinyCLIP-ViT-8M/16 Text-3M** int8 in-process from `photos/src/main/assets/clip/model_int8.onnx` (24 MB), with the CLIP BPE table in `clip/bpe_simple_vocab_16e6.txt`. Upstream is **`onnx-community/TinyCLIP-ViT-8M-16-Text-3M-YFCC15M-ONNX`** (MIT, an ONNX export of `wkcn/TinyCLIP-ViT-8M-16-Text-3M-YFCC15M`) — a **build-host** dependency only. The int8 export costs almost nothing in fidelity (measured cosine vs fp32: 0.998 image, 0.9995 text, same latency), because TinyCLIP is a plain ViT and quantizes cleanly. The trade-off accepted here is accuracy in absolute terms: TinyCLIP-8M scores 41.1% zero-shot ImageNet-1k against SigLIP2-base's high-70s, so single-concept queries are noticeably weaker than the IPC path it replaces.+**There is no third-party inference runtime left in the tree.** `com.microsoft.onnxruntime:onnxruntime-android` and its reduced rebuild `io.github.vayun-mathur:onnxruntime-reduced-android` are gone from `libs.versions.toml`, and with them the last of the `.so`-shaped AI dependencies that ncnn started. Both `:speech` and `:photos` were on the **reduced** build, so what actually left each APK is 10,466,856 bytes of arm64 native code - about 3.6 MiB deflated - against the 797 KB `libmodelrunner.so` that was already in both. Every model in every app now runs on `:library:ml` reading `.maml` weights.++Measured release APKs, before and after: `:photos` 59.0 MiB to **53.8 MiB**, `:speech` 188.1 MiB to **181.8 MiB**. The weights dominate both numbers and barely moved - TinyCLIP's 24,281,512-byte ONNX became a 23,734,912-byte `.maml`, whisper's two graphs' 76,894,612 bytes became 74,058,272 - so the saving is the runtime, as expected. Neither APK contains an `onnxruntime` entry or a `.onnx` asset.++The reduced build is worth remembering as a shape of dependency to avoid rather than merely as bytes saved. It was **our own rebuild** of upstream with `--include_ops_by_config` against an operator list generated from the very models it ran — so re-exporting a model meant regenerating the AAR by hand, and a model with an operator outside the configured set failed at *session creation* rather than at inference. Nothing in `.maml` has that coupling: the container carries ordered tensors and the forward pass is Rust in `nets/`.++It also came out **more accurate**, not less, because reading each model's fp32 source and quantising per output channel beats onnxruntime's per-tensor dynamic quantisation. Measured against fp32: whisper-base's encoder output is 0.029 mean absolute error against the export's 0.110, and TinyCLIP's text embedding is 0.9994 cosine against 0.9829.++`photos` **semantic search no longer needs a second app**.++`photos` **semantic search no longer needs a second app**. It previously delegated image/text embedding to the OpenAssistant app over IPC, so search only worked if OpenAssistant was installed, recent enough, and had finished a ~452 MB SigLIP2 download. It now runs **TinyCLIP-ViT-8M/16 Text-3M** in-process from `photos/src/main/assets/clip/tinyclip.maml` (22.6 MiB int8) on **`:library:ml`**, with the CLIP BPE table in `clip/bpe_simple_vocab_16e6.txt`. Upstream is **`onnx-community/TinyCLIP-ViT-8M-16-Text-3M-YFCC15M-ONNX`** (MIT, an ONNX export of `wkcn/TinyCLIP-ViT-8M-16-Text-3M-YFCC15M`) pinned to revision `9463a9c5` - a **build-host** dependency only, pinned by SHA-256 and rebuilt byte-for-byte by `scripts/ml/fetch_tinyclip.py`, with provenance in `photos/src/main/assets/clip/README.md`. Until that script existed this was the only bundled model in the tree with no pinned upstream digest and no fetch recipe. The `.maml` is converted from the repo's **fp32** `onnx/model.onnx` rather than the int8 export the app used to run: that export quantised the 49,408-row token table per *tensor* with a uint8 zero point of 226, which `conv_int8.comp` cannot represent and requantising cannot recover. Cosine against fp32 is now 0.9999 for an image and 0.9994 for a query, against the int8 export's 0.9985 and 0.9829. The trade-off accepted here is accuracy in absolute terms: TinyCLIP-8M scores 41.1% zero-shot ImageNet-1k against SigLIP2-base's high-70s, so single-concept queries are noticeably weaker than the IPC path it replaced.  `camera` and `photos` **no longer bundle two unattributable models**. Both `erdnet.{param,bin}` (portrait segmentation) and `u2netp.ncnn.{param,bin}` (subject segmentation) were added in a single commit (`72dde80df`, "make apps smaller") with no upstream URL, no license and no conversion recipe, and neither was ever listed here. They are replaced by fp16 `.maml` weights converted from **Apache-2.0** ONNX exports, run on `:library:ml` — our own Vulkan compute runtime — rather than on ncnn: @@ -152,7 +162,6 @@ Summed old per-crate locks (before workspace) = 712 total (641 excluding voxels) | `org.brotli:dec` | `0.1.2` | `extractor` | Google JVM port, low activity | `libs.versions.toml:9` | | `org.maplibre.compose:maplibre-compose` | `0.13.0` → `libmaplibre.so` native | `maps`, `weather`, `findfamily`, `photos` | Community-maintained FOSS renderer, better than Mapbox but smaller than Google Maps | `libs.versions.toml:78` | | `com.google.mediapipe:tasks-vision` | `0.10.35` (unified) | `camera` (face), vision segmentation | Native lib size; inline `0.10.14` drift resolved | `camera/build.gradle.kts:124`, `libs.versions.toml` |-| `com.microsoft.onnxruntime:onnxruntime-android` | `1.27.0` | `openassistant` (SigLIP), `speech` (whisper-base int8), `photos` (TinyCLIP int8) | MIT, Microsoft-maintained, low risk but native `.so` (~27 MB arm64, 35% of the `speech` APK). The reduced `onnxruntime-mobile` package is not usable: it lacks `ConvInteger`, which whisper's quantized Conv1d stem needs, and its last release was 1.18.0 in May 2024 | `openassistant/build.gradle.kts`, `speech/build.gradle.kts`, `photos/build.gradle.kts`, `libs.versions.toml:85` | | `net.zetetic:sqlcipher-android` | `4.18.0` | `library:room` → `passwords`, `notes` | Small company, adds ~2MB `.so`, encrypted DB. `4.18.0` is the first release with `SQLCipherDriver` (an `androidx.sqlite.SQLiteDriver`), which is what lets encrypted databases work on Room 3 at all: Room 3 removed `openHelperFactory(...)` | `library/room/build.gradle.kts`, `libs.versions.toml:117` | | `io.coil-kt:coil-compose` + `coil-svg` + `coil-video` | `2.7.0` | `photos`, `maps`, `email`, `travel`, `education`, `pdf` | <3 maintainers, but widely adopted image loader | `libs.versions.toml:50` | | `org.bouncycastle:bcprov-jdk18on` + `bcpkix-jdk18on` | `1.85` | `pdf`, `passwords`, `messages`, `e2ee-p2p` | Small org, long-lived, well-audited PQC ML-KEM/ML-DSA; resource conflicts handled in `common-conventions-app` | `libs.versions.toml:84,226` |
gradle/libs.versions.toml
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 5304af23e7..084e7bf0d2 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -106,12 +106,6 @@ quickjs = "1.0.5" # Git jgit = "6.10.1.202505221210-r" -# On-device AI-onnxruntimeAndroid = "1.27.0"-# Reduced-operator rebuild of the above, arm64-only. Version tracks upstream plus an -rN-# suffix for the operator-set revision, so a rebuild with different ops gets a new version.-onnxruntimeReduced = "1.27.0-r1"- # Crypto, security & credential storage cryptographyCore = "0.6.0" sqlcipherAndroid = "4.18.0"@@ -290,13 +284,17 @@ quickjs-kt = { module = "io.github.dokar3:quickjs-kt", version.ref = "quickjs" } # Git jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit" } -# On-device AI-onnxruntime-android = { module = "com.microsoft.onnxruntime:onnxruntime-android", version.ref = "onnxruntimeAndroid" }-# Same source as onnxruntime-android, built with --include_ops_by_config for exactly the-# operators whisper-base (speech) and TinyCLIP (photos) need: 10 MB of native code instead of-# 28 MB. Only those two apps may use it — a model with an operator outside the configured set-# fails at session creation, not at inference. openassistant stays on the full build.-onnxruntime-reduced = { module = "io.github.vayun-mathur:onnxruntime-reduced-android", version.ref = "onnxruntimeReduced" }+# On-device AI: nothing here.+#+# Every model in this tree runs on `:library:ml`, our own Vulkan compute runtime, reading `.maml`+# weights. `com.microsoft.onnxruntime:onnxruntime-android` and the reduced rebuild of it,+# `io.github.vayun-mathur:onnxruntime-reduced-android`, were the last third-party inference runtimes+# and both are gone: TinyCLIP (`photos`) and whisper-base (`speech`) were the two remaining users.+#+# The reduced build is worth remembering as a shape of dependency to avoid. It was our own rebuild of+# upstream with `--include_ops_by_config` against an operator list generated from the very models it+# ran, so re-exporting a model meant regenerating the AAR by hand or watching session creation fail.+# Nothing in `.maml` has that coupling: the container carries tensors and the forward pass is Rust.  # Crypto, security & credential storage cryptography-core = { module = "dev.whyoleg.cryptography:cryptography-core", version.ref = "cryptographyCore" }
library/ml/src/main/java/com/vayunmathur/library/ml/ClipHandle.kt
diff --git a/library/ml/src/main/java/com/vayunmathur/library/ml/ClipHandle.kt b/library/ml/src/main/java/com/vayunmathur/library/ml/ClipHandle.ktindex ef4520e0b1..2dbc76f5be 100644--- a/library/ml/src/main/java/com/vayunmathur/library/ml/ClipHandle.kt+++ b/library/ml/src/main/java/com/vayunmathur/library/ml/ClipHandle.kt@@ -20,8 +20,8 @@ import android.util.Log  *  * It replaces `onnxruntime-android` running a 24 MB int8 ONNX export of the same model, and is  * *closer* to the fp32 reference than that was — 0.9994 against 0.9829 on a text query, because the- * export quantised the 49,408-row token table per tensor with a zero point. The APK loses 10.5 MB of- * arm64 `.so`, not weights.+ * export quantised the 49,408-row token table per tensor with a zero point. The APK loses+ * 10,466,856 bytes of arm64 `.so` with the runtime, not weights.  *  * An asset must be stored **uncompressed** for this to work at all: `AssetManager.openFd` throws for  * a deflated entry. That is what `noCompress += "maml"` in `photos/build.gradle.kts` is for, and it
library/ml/src/main/java/com/vayunmathur/library/ml/WhisperHandle.kt
diff --git a/library/ml/src/main/java/com/vayunmathur/library/ml/WhisperHandle.kt b/library/ml/src/main/java/com/vayunmathur/library/ml/WhisperHandle.ktindex a72d1bb2c6..95553fa213 100644--- a/library/ml/src/main/java/com/vayunmathur/library/ml/WhisperHandle.kt+++ b/library/ml/src/main/java/com/vayunmathur/library/ml/WhisperHandle.kt@@ -18,10 +18,10 @@ import android.util.Log  * but the layer norms, the biases and the two position tables is int8, quantised per output channel  * from `openai/whisper-base`'s fp32 checkpoint.  *- * It replaces `onnxruntime-android` running two int8 ONNX exports totalling 76.9 MB, and is **four- * times closer** to the fp32 checkpoint than they were: over the encoder's output, mean absolute- * error 0.029 against their 0.110, on a tensor whose largest value is 22.8. The APK loses ~27 MB of- * arm64 `.so` with the runtime.+ * It replaces `onnxruntime-reduced-android` running two int8 ONNX exports totalling 76.9 MB, and is+ * **four times closer** to the fp32 checkpoint than they were: over the encoder's output, mean+ * absolute error 0.029 against their 0.110, on a tensor whose largest value is 22.8. The APK loses+ * 10,466,856 bytes of arm64 `.so` with the runtime — about 3.6 MiB of the packaged size.  *  * An asset must be stored **uncompressed** for this to work at all: `AssetManager.openFd` throws for  * a deflated entry. That is what `noCompress += "maml"` in `speech/build.gradle.kts` is for.
library/ml/src/main/rust/src/nets/tinyclip.rs
diff --git a/library/ml/src/main/rust/src/nets/tinyclip.rs b/library/ml/src/main/rust/src/nets/tinyclip.rsindex 9aa4437502..e02e028fdc 100644--- a/library/ml/src/main/rust/src/nets/tinyclip.rs+++ b/library/ml/src/main/rust/src/nets/tinyclip.rs@@ -8,8 +8,8 @@ //! over up to 77 tokens. 23,446,016 parameters, 22.6 MiB as int8. //! //! It replaces onnxruntime running `photos/src/main/assets/clip/model_int8.onnx`. That export was-//! also int8, so this is not a size win on the weights — the APK shrinks because-//! `onnxruntime-android`'s ~27 MB of native `.so` leaves with it. See+//! also int8, so this is not a size win on the weights — the APK shrinks because the+//! `onnxruntime-reduced-android` AAR's 10.5 MB of arm64 `.so` leaves with it. See //! `photos/src/main/assets/clip/README.md` for why the `.maml` is built from the **fp32** graph //! even though the shipped one was already quantised. //!
library/ml/src/main/rust/src/nets/whisper.rs
diff --git a/library/ml/src/main/rust/src/nets/whisper.rs b/library/ml/src/main/rust/src/nets/whisper.rsindex 12f307820b..dee26c5ff0 100644--- a/library/ml/src/main/rust/src/nets/whisper.rs+++ b/library/ml/src/main/rust/src/nets/whisper.rs@@ -9,8 +9,11 @@ //! 70.6 MiB as int8. //! //! It replaces onnxruntime running two int8 ONNX exports totalling 76.9 MB-//! (`speech/src/main/assets/whisper-base/*.onnx`), and with them the last `onnxruntime-android`-//! dependency in the tree — ~27 MB of native `.so`, which was 35% of the `:speech` APK.+//! (`speech/src/main/assets/whisper-base/*.onnx`), and with them the last third-party inference+//! runtime in the tree. `:speech` used the **reduced** `onnxruntime-reduced-android` build, so what+//! actually left is 10,466,856 bytes of arm64 `.so` — about 3.6 MiB deflated in the APK — against the+//! 797 KB `libmodelrunner.so` that was already there for Supertonic. The release APK went from+//! 188.1 MiB to a measured **181.8 MiB**; the weights are most of both numbers. //! //! It is also **four times closer** to the fp32 checkpoint than what it replaces. Over the encoder's //! `[1500, 512]` output on one deterministic window, against an fp32 reference computed from the
library/ml/src/main/rust/src/post/whisper.rs
diff --git a/library/ml/src/main/rust/src/post/whisper.rs b/library/ml/src/main/rust/src/post/whisper.rsindex 4cc59361a4..0bdbb0711f 100644--- a/library/ml/src/main/rust/src/post/whisper.rs+++ b/library/ml/src/main/rust/src/post/whisper.rs@@ -18,7 +18,7 @@ //! Dropping the last one does not fail: it changes the output from plain text to `<|0.00|>`-style //! timestamped text, because the model was trained to predict a timestamp first unless told not to. //! That is the same shape of hazard as SMaLL-100's "the target language goes on the source side",-//! and [`tests::the_prompt_is_four_tokens_ending_in_no_timestamps`] is what pins it.+//! and `tests::the_prompt_is_four_tokens_ending_in_no_timestamps` is what pins it. //! //! The reference feeds all four at once with `use_cache_branch=false`. This feeds them one at a //! time, because [`crate::nets::whisper::Mode::DecodeStep`] is one query per step — and for a
photos/src/main/assets/README.md
diff --git a/photos/src/main/assets/README.md b/photos/src/main/assets/README.mdindex 1fe63ba5fd..827d7cab86 100644--- a/photos/src/main/assets/README.md+++ b/photos/src/main/assets/README.md@@ -58,7 +58,17 @@ in `:photos` itself uses ncnn any more.  ## `clip/` -See `SUPPLY_CHAIN_RISKS.md` for the TinyCLIP int8 ONNX read by `ClipEmbedder`.+TinyCLIP-ViT-8M/16 Text-3M, read by `ClipEmbedder` through `:library:ml`. It has a README+of its own — `clip/README.md` — because it is the one asset here whose provenance had to be+written from scratch: until `scripts/ml/fetch_tinyclip.py` existed it was the only bundled+model in the tree with no pinned upstream SHA-256 and no fetch recipe. Rebuild it with that+script rather than with `fetch_and_convert.sh`.++`model_int8.onnx` and the `onnxruntime-reduced-android` AAR that ran it are both gone, which+is 10,466,856 bytes of arm64 native code out of this APK. `libmodelrunner.so` was already here+for the four models above, and there is now no third-party inference runtime in `:photos` at all.++## Keeping these current  Update: `./scripts/ml/fetch_and_convert.sh --update`, which reports the moved SHA-256 to re-pin. If the ordered layer table changed too, the converter says so
photos/src/main/assets/clip/README.md
diff --git a/photos/src/main/assets/clip/README.md b/photos/src/main/assets/clip/README.mdindex 3c1166b70c..644d3de626 100644--- a/photos/src/main/assets/clip/README.md+++ b/photos/src/main/assets/clip/README.md@@ -68,12 +68,12 @@ indexed by either alone.  The result is *smaller* than the file it replaces — 23,734,912 bytes against 24,281,512 — because the token embedding is int8 per row rather than uint8 per tensor and nothing is stored twice. The-APK shrinks by much more than that, because `onnxruntime-android`'s native `.so` leaves with it:-`onnxruntime-reduced-android-1.27.0-r1.aar` contributed **10,466,856 bytes** of arm64 `.so`-(3.43 MiB after the APK's own compression), against the 779 KB of `libmodelrunner.so` that was-already there for face detection, subject segmentation and OCR.+APK saves more than that, because the reduced `onnxruntime-reduced-android-1.27.0-r1.aar` contributed+**10,466,856 bytes** of arm64 `.so` (about 3.4 MiB deflated), against the 797 KB `libmodelrunner.so`+that was already there for face detection, subject segmentation and OCR. The measured `:photos`+release APK went from 59.0 MiB to **53.8 MiB**. -A `:photos` release APK built after the port contains **no `onnxruntime` entry at all**.+It contains **no `onnxruntime` entry and no `.onnx` asset at all**.  ## What the `.maml` holds 
photos/src/main/assets/clip/model_int8.onnx
diff --git a/photos/src/main/assets/clip/model_int8.onnx b/photos/src/main/assets/clip/model_int8.onnxdeleted file mode 100644index 9f513c2ebd..0000000000Binary files a/photos/src/main/assets/clip/model_int8.onnx and /dev/null differ
photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt b/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.ktindex 76c04c239e..b88e005dfe 100644--- a/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt+++ b/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt@@ -26,8 +26,8 @@ import kotlinx.coroutines.withContext  *  * The two towers are hardcoded forward passes in `library/ml/src/main/rust/src/nets/tinyclip.rs`,  * executed by our own Vulkan compute runtime through [ClipHandle]. That removed the last- * `onnxruntime-android` dependency from this APK — 10,466,856 bytes of arm64 `.so`, against the- * 779 KB `libmodelrunner.so` that was already here for face detection, segmentation and OCR.+ * `onnxruntime-reduced-android` dependency from this APK - 10,466,856 bytes of arm64 `.so`, against+ * the 797 KB `libmodelrunner.so` that was already here for face detection, segmentation and OCR.  *  * It is also *more* accurate than the ONNX path it replaces. Cosine against the fp32 export is  * 0.999864 for an image and 0.999394 for a query, against the int8 export's 0.998478 and 0.982881:
scripts/speech/fetch_whisper_onnx.sh
diff --git a/scripts/speech/fetch_whisper_onnx.sh b/scripts/speech/fetch_whisper_onnx.shdeleted file mode 100644index df56cf79f0..0000000000--- a/scripts/speech/fetch_whisper_onnx.sh+++ /dev/null@@ -1,107 +0,0 @@-#!/usr/bin/env bash-#-# Refresh the bundled Whisper-base int8 ONNX assets in speech/src/main/assets/whisper-base/.-#-# These are NOT downloaded at runtime - they ship inside the APK and are read straight out of-# the asset manager by WhisperOnnxEngine, so this script is a build-host tool for updating a-# vendored dependency, not a mirror-staging step.-#-# Upstream is HuggingFace onnx-community/whisper-base, which is an ONNX Runtime *dynamic*-# int8 quantization of openai/whisper-base. We consume it as-is: onnx2ncnn cannot read-# DynamicQuantizeLinear/MatMulInteger/ConvInteger, so there is no ncnn conversion path.-#-# The four files below are the whole runtime surface:-#   encoder_model_int8.onnx         audio -> 1500x512 hidden states-#   decoder_model_merged_int8.onnx  KV-cached greedy decode (use_cache_branch switches)-#   vocab.json                      id -> token, for byte-level decode (no merges: decode only)-#   generation_config.json          lang_to_id, suppress_tokens, special ids-#-# merges.txt and preprocessor_config.json are deliberately NOT vendored: we never BPE-encode-# (prompts are pure special tokens) and the feature-extractor constants are compile-time-# values in WhisperFeatures.kt, asserted against upstream by --check below.-#-#   ./scripts/speech/fetch_whisper_onnx.sh           # verify pinned hashes only-#   ./scripts/speech/fetch_whisper_onnx.sh --update  # re-download and rewrite hashes-#-set -euo pipefail--REPO="onnx-community/whisper-base"-# Pinned, as `scripts/ml/fetch_and_convert.sh` pins its models: `main` moving under us would-# change the weights without changing this script.-REVISION="1846881b6b3a3024392c1eea3ad983695bc23925"-BASE="https://huggingface.co/${REPO}/resolve/${REVISION}"-DEST="speech/src/main/assets/whisper-base"--# path-at-upstream  sha256-FILES=(-  "onnx/encoder_model_int8.onnx        ca6177401f86a2c6b4dc5f7fc02fbca680678906bd0c22f6d89f0b80f124253f"-  "onnx/decoder_model_merged_int8.onnx fa3ef9902734ce5ae6f9ef2bdb2ba9a6c4b5785b09f4f420ce036573dc9d090b"-  "vocab.json                          50d6a919f0a0601d56a04eb583c780d18553aa388254ba3158eb6a00f13e2c1a"-  "generation_config.json              f5c67e5a4f7102f8cb4d058bc95da276bbc19eeec997267c3bb0f25ef68facd1"-)--if [ ! -f settings.gradle.kts ]; then-  echo "Run this from the repo root (where settings.gradle.kts is)." >&2-  exit 1-fi--sha256() {-  if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1-  else shasum -a 256 "$1" | cut -d' ' -f1-  fi-}--update=0-[ "${1:-}" = "--update" ] && update=1--mkdir -p "$DEST"-fail=0--for entry in "${FILES[@]}"; do-  # shellcheck disable=SC2086-  set -- $entry-  remote="$1"-  want="$2"-  local_name="$(basename "$remote")"-  out="${DEST}/${local_name}"--  if [ "$update" = 1 ] || [ ! -f "$out" ]; then-    echo "Downloading ${remote}..."-    curl -fL --retry 3 "${BASE}/${remote}" -o "${out}.tmp"-    mv "${out}.tmp" "$out"-  fi--  got="$(sha256 "$out")"-  if [ "$got" = "$want" ]; then-    printf '  ok      %-34s %s\n' "$local_name" "$got"-  elif [ "$update" = 1 ]; then-    printf '  CHANGED %-34s\n            was %s\n            now %s\n' "$local_name" "$want" "$got"-    echo "            ^ update the pin for ${local_name} in this script"-    fail=1-  else-    printf '  MISMATCH %-33s\n            want %s\n            got  %s\n' "$local_name" "$want" "$got"-    fail=1-  fi-done--# The feature extractor is reimplemented in Kotlin; if upstream ever retunes these we want a-# loud failure rather than a silently wrong mel (which yields fluent nonsense, not an error).-echo-echo "Checking preprocessor_config.json against WhisperFeatures.kt constants..."-pre="$(curl -fsSL "${BASE}/preprocessor_config.json")"-for kv in '"feature_size": 80' '"hop_length": 160' '"n_fft": 400' '"sampling_rate": 16000' '"n_samples": 480000' '"nb_max_frames": 3000'; do-  if printf '%s' "$pre" | tr -d ' \n' | grep -q "$(printf '%s' "$kv" | tr -d ' ')"; then-    echo "  ok      $kv"-  else-    echo "  MISMATCH expected $kv upstream — WhisperFeatures.kt must be updated" >&2-    fail=1-  fi-done--echo-if [ "$fail" != 0 ]; then-  echo "FAILED — see above." >&2-  exit 1-fi-du -sh "$DEST"-echo "All ${#FILES[@]} assets verified."
speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnx
diff --git a/speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnx b/speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnxdeleted file mode 100644index abbe80534f..0000000000Binary files a/speech/src/main/assets/whisper-base/decoder_model_merged_int8.onnx and /dev/null differ
speech/src/main/assets/whisper-base/encoder_model_int8.onnx
diff --git a/speech/src/main/assets/whisper-base/encoder_model_int8.onnx b/speech/src/main/assets/whisper-base/encoder_model_int8.onnxdeleted file mode 100644index 2738b5f948..0000000000Binary files a/speech/src/main/assets/whisper-base/encoder_model_int8.onnx and /dev/null differ
speech/src/main/java/com/vayunmathur/speech/util/WhisperEngine.kt
diff --git a/speech/src/main/java/com/vayunmathur/speech/util/WhisperEngine.kt b/speech/src/main/java/com/vayunmathur/speech/util/WhisperEngine.ktindex 978e5df7a4..50af6fd0cc 100644--- a/speech/src/main/java/com/vayunmathur/speech/util/WhisperEngine.kt+++ b/speech/src/main/java/com/vayunmathur/speech/util/WhisperEngine.kt@@ -9,9 +9,9 @@ import org.json.JSONObject  * Speech-to-text entry point for [com.vayunmathur.speech.service.WhisperRecognitionService].  *  * A thin seam over [WhisperHandle], which runs **whisper-base** on `:library:ml`'s Vulkan compute- * runtime. It replaced `WhisperOnnxEngine` and with it the last `onnxruntime-android` dependency in- * the tree: the two int8 ONNX exports (76.9 MB) became one 70.6 MiB `.maml`, and ~27 MB of arm64- * `.so` left the APK.+ * runtime. It replaced `WhisperOnnxEngine` and with it the last third-party inference runtime in the+ * tree: the two int8 ONNX exports (76.9 MB) became one 70.6 MiB `.maml`, and the reduced+ * onnxruntime AAR's 10,466,856 bytes of arm64 `.so` left the APK with them.  *  * The port is also **four times closer** to the fp32 checkpoint than the exports were — mean absolute  * error 0.029 against 0.110 over the encoder's output — because it quantises per output channel where
speech/src/main/java/com/vayunmathur/speech/util/WhisperFeatures.kt
diff --git a/speech/src/main/java/com/vayunmathur/speech/util/WhisperFeatures.kt b/speech/src/main/java/com/vayunmathur/speech/util/WhisperFeatures.ktindex d6406c2d7e..c7d14b0a2c 100644--- a/speech/src/main/java/com/vayunmathur/speech/util/WhisperFeatures.kt+++ b/speech/src/main/java/com/vayunmathur/speech/util/WhisperFeatures.kt@@ -11,13 +11,13 @@ import kotlin.math.sin  /**  * Whisper log-mel feature extraction: 16 kHz mono PCM to the `[80, 3000]` `input_features`- * tensor the ONNX encoder expects. This replaces the `fbank` ncnn net that the old AAR path+ * tensor the encoder expects. This replaces the `fbank` ncnn net that the old AAR path  * used, and is a port of HuggingFace `WhisperFeatureExtractor` (slaney mel scale, slaney  * normalisation) verified against it to ~1e-7.  *  * A wrong mel does not throw — it produces fluent, confident nonsense — so the constants here  * are asserted against upstream `preprocessor_config.json` by- * `scripts/speech/fetch_whisper_onnx.sh`, and the output is pinned in `WhisperFeaturesTest`.+ * `scripts/ml/fetch_whisper.py`, and the output is pinned in `WhisperFeaturesTest`.  */ object WhisperFeatures { 
speech/src/test/java/com/vayunmathur/speech/util/WhisperFeaturesTest.kt
diff --git a/speech/src/test/java/com/vayunmathur/speech/util/WhisperFeaturesTest.kt b/speech/src/test/java/com/vayunmathur/speech/util/WhisperFeaturesTest.ktindex 7f92d9206d..0fdf51e1db 100644--- a/speech/src/test/java/com/vayunmathur/speech/util/WhisperFeaturesTest.kt+++ b/speech/src/test/java/com/vayunmathur/speech/util/WhisperFeaturesTest.kt@@ -13,7 +13,7 @@ import kotlin.test.assertTrue  * This is the highest-value test in the module: a wrong log-mel does not throw, it makes the  * decoder emit fluent nonsense, so nothing downstream would catch a regression here. The  * expectations were produced by running the real extractor over the closed-form signal in- * [referenceSignal] — see the generator noted in `scripts/speech/fetch_whisper_onnx.sh`.+ * [referenceSignal] — see the generator noted in `scripts/ml/fetch_whisper.py`.  *  * Tolerances are loose enough to absorb the reference being computed in float32 while this  * runs in double, and tight enough that any indexing, window, scale or transpose error fails.