Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / library / ml / AGENTS.md

AGENTS.md3.1 KiBRenderedCodeRaw
1# AGENTS.md — library/ml/ (':library:ml')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `library/ml/` + allowed shared modules. Do not root-scan.
4
5- Gradle: :library:ml / dir: library/ml/
6- Package roots present: (on-device inference runtimes — one package + Rust/native bridges)
7- Entry files: per-model `*Handle` (no MainActivity/Route — library)
8- Deps: (none — ONNX/LiteRT/ExecuTorch/Vulkan sessions live here)
9- Metadata: metadata_data/library-ml.md (absent — libraries have none by design)
10- Rust: yes / screenshotTest: no
11
12## Overview
13**Purpose:** All on-device inference — session wrappers for every runtime (ONNX, LiteRT, ExecuTorch, Vulkan compute) plus per-model handles: Whisper (speech), NLLB (translate), Gemma (assistant), Maia (chess), CLIP/faces/segmentation (photos/camera), Supertonic (TTS), OCR post. No vendor SDKs.
14**How to use:** Pick the runtime session (`OnnxSessions` / `LiteRtSessions` / `ExecutorchSessions` / `VulkanSessions`), then the model handle (`WhisperHandle`, `NllbHandle`, `GemmaTypes`, `MaiaHandle`, `ClipHandle`, `SelfieSegmenter`, …). Pre/post via `OnnxPreprocess`, `OcrPost`, `SegmentationMask`.
15**Entry points:** The `*Handle` for your model → its `*Sessions` runtime → `VulkanBridge`/`VulkanWire` if GPU.
16**Gotchas:** Model files are large and versioned per consumer — never share weights across models without checking compatibility; GPU paths need device-specific testing. `TextRecognizer` is thread-safe without caller locks: passes are serialised internally and `close()` defers the native destroy until any in-flight pass returns; the Rust side enforces the same lifetime with the exclusive `OCR_LIFETIME` lock in `ocr_guard.rs` (recognise passes and `destroyOcr` take the same lock), so passes on one handle never overlap and a handle is never freed under a live `recognizeText` call.
17
18## Key files
19- com/vayunmathur/library/ml/OnnxSessions.kt
20- com/vayunmathur/library/ml/LiteRtSessions.kt
21- com/vayunmathur/library/ml/ExecutorchSessions.kt
22- com/vayunmathur/library/ml/VulkanSessions.kt
23- com/vayunmathur/library/ml/VulkanBridge.kt
24- com/vayunmathur/library/ml/VulkanWire.kt
25- com/vayunmathur/library/ml/MlHandle.kt — shared native-handle lifetime (`handle`/`isAvailable`/idempotent `close`) plus the asset/file descriptor factories every `*Handle` and `SupertonicSynthesizer`/`MusicGate` build on
26- com/vayunmathur/library/ml/WhisperHandle.kt
27- com/vayunmathur/library/ml/NllbHandle.kt
28- com/vayunmathur/library/ml/GemmaTypes.kt
29- com/vayunmathur/library/ml/MaiaHandle.kt
30- com/vayunmathur/library/ml/ClipHandle.kt
31- com/vayunmathur/library/ml/Faces.kt
32- com/vayunmathur/library/ml/SelfieSegmenter.kt
33- com/vayunmathur/library/ml/SubjectSegmenter.kt
34- com/vayunmathur/library/ml/SegmentationMask.kt
35- com/vayunmathur/library/ml/SupertonicSynthesizer.kt
36- com/vayunmathur/library/ml/TextRecognizer.kt
37- com/vayunmathur/library/ml/TextRecognizerEt.kt
38- com/vayunmathur/library/ml/EtTensors.kt
39- com/vayunmathur/library/ml/OcrPost.kt
40- com/vayunmathur/library/ml/OnnxPreprocess.kt
41
42## Verify (this module only)
43```
44./gradlew :library:ml:compileDevKotlin
45./gradlew :library:ml:lint
46```