Views
No views yet
onnxruntime instead of PyTorch/TorchScript — useful for
platforms where PyTorch is heavy or hard to build (e.g. Android/Termux).
License follows the original: MIT.model-asr.fp16.ts)
wrapped in a transformers-compatible loader, needing torch +
transformers + sentencepiece at runtime — a heavy stack on
resource-constrained platforms. This repo provides the same model as two
ONNX graphs (encoder.onnx, decoder_joint.onnx) runnable with just
onnxruntime — smaller dependency footprint, and in testing, noticeably
faster than the PyTorch CPU path (see benchmarks below).| File | Size | Purpose |
|---|---|---|
encoder.onnx | ~1.77GB (fp32) | Conformer encoder: feats[B,128,T], feature_lengths[B] → enc_out[B,1024,T'], enc_lengths[B] |
decoder_joint.onnx | ~43MB | LSTM predictor + joint network, single decode step: f[1,1024,1], tgt[1,1] int32, tlen[1] int32, h_in/c_in[1,1,640] → logits[1,1,1,5006], aux, h_out, c_out |
config.json | Model config (vocab_size, blank_id, durations, etc. — same as original) | |
tokenizer.model | SentencePiece tokenizer, unchanged from original | |
preproc.pt | Mel-spectrogram frontend params (window, filterbank), unchanged from original |
.ts checkpoint, trading disk space for CPU-inference
correctness).onnx_transcribe.py
in the companion GitHub repo for a complete reference implementation
(feature extraction + greedy decode + tokenizer, using only onnxruntime,
sentencepiece, torch for the STFT frontend, and soundfile).1import onnxruntime as ort
2
3enc_sess = ort.InferenceSession("encoder.onnx", providers=["CPUExecutionProvider"])
4dj_sess = ort.InferenceSession("decoder_joint.onnx", providers=["CPUExecutionProvider"])
5# feats: [1, 128, T] mel-spectrogram, feature_lengths: [1]
6enc_out, enc_lengths = enc_sess.run(None, {"feats": feats, "feature_lengths": feature_lengths})
7# then greedy-decode by stepping dj_sess once per encoder frame - see
8# onnx_transcribe.py for the full loop| Path | Total inference time | Realtime factor |
|---|---|---|
Original PyTorch (model.transcribe(...)) | ~11s (6s clip) | ~1.8x — slower than realtime |
This ONNX export, CPUExecutionProvider | 1.35s | 0.31x — faster than realtime |
This ONNX export, NnapiExecutionProvider | 2.32s | 0.53x — faster than realtime, but slower than plain CPU |
CPUExecutionProvider.export_onnx.py
in the companion GitHub repo to reproduce this conversion yourself. Note:
export on a normal desktop PC, not Android/Termux — Termux's PyTorch
build has a libc++/libcxxabi defect that corrupts TorchScript graph
attribute reading during ONNX export (unrelated to this model; a general
Android/Termux PyTorch packaging issue). Plain desktop PyTorch doesn't
have this problem.