Skip to content

feat(dictation): add pure-Rust ONNX backend for Cleanup Tagger v2 on Windows and Linux - #3078

Merged
kitlangton merged 2 commits into
devfrom
cleanup-v2-win-linux
Nov 29, 2026
Merged

kitlangton merged 2 commits into
devfrom
cleanup-v2-win-linux

Conversation

@kitlangton

Copy link
Copy Markdown
Collaborator

Adds a cross-platform pure-Rust CPU ONNX backend (tract-onnx) for Cleanup Tagger v2 so Windows and Linux run the same 4-head tagger pipeline (bpe, decode, render, itn, post) as macOS Core ML, instead of returning the transcript unchanged.

Before / After

  • Before: src/dictation/cleanup/v2/ only ran under #[cfg(target_os = "macos")] (Core ML), and Feature::CleanupTaggerV2 was gated to MACOS. Windows and Linux skipped v2 completely.
  • After: Windows and Linux load cleanup_tagger_v2.int8.onnx (preferred, 32.5 MB) or cleanup_tagger_v2.onnx alongside tokenizer.json and optional runtime.json from <models>/cleanup-v2/ (or HEX_CLEANUP_V2_DIR) through src/dictation/cleanup/v2/onnx.rs using tract-onnx (default-features = false, zero C++/DLL/VCRUNTIME dependencies, Nix-offline compatible). macOS Core ML (runtime::CoreMlV2) is untouched and does not link tract-onnx in non-test builds.

Implementation details

  • Weight-only INT8 dequantization on load: Standard ONNX DynamicQuantizeLinear quantizes activations per-tensor, which lets GeGLU outlier channels collapse normal token activations to the zero point. Folding DynamicQuantizeLinear -> MatMulInteger -> Cast -> Mul with constant INT8/UINT8 weights into f32 MatMul on load matches Core ML's weight-only quantization while keeping the 32.5 MB on-disk artifact.
  • Graceful fallback & lifecycle: Missing model/tokenizer returns Skip::NotInstalled without blocking or crashing; Windows and Linux dictation loops call cleanup::prepare() on startup and hotkey press to warm the model in the background; labs.unload_idle and reconcile release it.
  • Labs gate: Widened Feature::CleanupTaggerV2 from MACOS to EVERY (still Dev audience, off by default) and surfaced it in Labs on Windows and Linux developer builds.

Measured parity & latency (cleanup_tagger_v2.int8.onnx, release CPU)

Metric Measured
Cold load + optimize + warm-up 143 ms
4-head argmax agreement vs Core ML (model-parity.json) 399/400 (action 400/400, punct 400/400, case 400/400, span 399/400)
Action logit max abs diff vs Core ML 0.3805
Rendered lines vs Core ML (model-parity.json) 39/40 (the 1 diff is "21st." matching PyTorch/ORT FP32 vs Core ML's "20 first.")
Inference latency (40 sentences) 4.12 ms median, 5.82 ms p95, 5.88 ms max
400-word single window 123.7 ms

Verification

  • HEX_UPDATE_LABS_JSON=1 scripts/check labs::web (2/2 passed)
  • scripts/check labs control::settings (102/102 passed)
  • scripts/check dictation::cleanup (110/110 passed)
  • scripts/check rune_ui (648/648 passed)
  • cargo clippy --locked --bin hex -- -D warnings (clean)
  • python3 scripts/code-shape.py (no hard problems)
  • Real-model ignored tests passed for both ONNX (the_real_v2_onnx_model_answers_as_the_reference_recorded) and macOS Core ML (the_real_v2_model_answers_as_the_reference_recorded)

@kitlangton
kitlangton merged commit 3392a4b into dev Nov 29, 2026
5 of 6 checks passed
@kitlangton
kitlangton deleted the cleanup-v2-win-linux branch November 29, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant