Run this model with HF Jobs
Run moncefem/canary-180m-flash-onnx-split on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/moncefem/canary-180m-flash-onnx-split. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/moncefem/canary-180m-flash-onnx-split on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use moncefem/canary-180m-flash-onnx-split with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- NeMo
How to use moncefem/canary-180m-flash-onnx-split with NeMo:
import nemo.collections.asr as nemo_asr asr_model = nemo_asr.models.ASRModel.from_pretrained("moncefem/canary-180m-flash-onnx-split") transcriptions = asr_model.transcribe(["file.wav"]) - Notebooks
- Google Colab
- Kaggle
Canary 180M Flash · int8 ONNX with a split decoder
Speech-to-text in English, French, German and Spanish that runs on the CPU, in a browser tab or in Node, with punctuation and capitals.
This is NVIDIA Canary-180M-Flash as int8 ONNX, with its decoder split in two so that greedy decoding stays fast in single-thread WebAssembly (onnxruntime-web).
| Parameters | 182M (17-layer FastConformer encoder, 4-layer Transformer decoder) |
| Languages | English, French, German, Spanish |
| Download | 213 MB (int8) |
| Runtime | onnxruntime-web (WebAssembly), onnxruntime-node, onnxruntime (Python) |
| Input | 16 kHz mono audio, 128-bin log-mel features |
| Output | Text with punctuation and capitals |
| License | CC-BY-4.0 (from NVIDIA) |
Why a split decoder
The usual ONNX export of Canary passes the full encoder output to the decoder at every token, and each of the 4 decoder layers recomputes its cross-attention keys and values from it. On a server GPU that hardly matters. In single-thread WebAssembly it costs over 60 ms per token, about 90 % of the transcription time.
Here that work runs once per recording:
decoder-cross.int8.onnxturns the encoder output into each layer's cross-attention mask, keys and values (12 tensors).decoder-step.int8.onnxdecodes one token at a time from those tensors.
The split moves graph nodes and does not change any weight. Transcripts are the same as with the original decoder.
| 12 s recording, single-thread WebAssembly (Apple M5 Max) | Original decoder | Split decoder |
|---|---|---|
| Decoder time per token | 68 ms | 24 ms |
| Total, two candidate languages | 11.2 s | 4.5 s |
| Total, one language | 6.3 s | 2.8 s |
With native onnxruntime the whole pipeline runs at about 0.05× real time on one CPU core.
Files
| File | Size | Role | SHA-256 |
|---|---|---|---|
encoder-model.int8.onnx |
133.7 MB | FastConformer encoder (unchanged copy) | 996d1c89e6cbc891… |
decoder-cross.int8.onnx |
8.5 MB | Decoder, cross-attention part: run once per recording | 6cf5fb8d1dbb565c… |
decoder-step.int8.onnx |
71.0 MB | Decoder, per-token part | cd793635fca463c0… |
vocab.txt |
0.1 MB | Tokenizer vocabulary (unchanged copy) | 2dae6fc7815f9640… |
Also included: transcribe.mjs (the example below), split_canary_decoder.py
(the script that made the split) and NOTICE.md (attribution).
Quick start (Node)
npm install onnxruntime-node @huggingface/transformers
hf download moncefem/canary-180m-flash-onnx-split --local-dir canary
node canary/transcribe.mjs canary speech-16k-mono.wav en,fr
# [fr] Quelles sont les dates des examens du deuxième semestre à l'Université de Créteil ?
The same code runs in a browser with onnxruntime-web; load the model files from
https://huggingface.co/moncefem/canary-180m-flash-onnx-split/resolve/main/.
transcribe.mjs
// node transcribe.mjs <model-dir> <audio-16k-mono.wav> [languages, default "en,fr"]
// npm install onnxruntime-node @huggingface/transformers
import { readFileSync } from "node:fs";
import * as ort from "onnxruntime-node";
import { ParakeetFeatureExtractor } from "@huggingface/transformers";
const [dir, wav, langs = "en,fr"] = process.argv.slice(2);
const load = (f) => ort.InferenceSession.create(`${dir}/${f}`);
const [encoder, cross, step] = await Promise.all([
load("encoder-model.int8.onnx"), load("decoder-cross.int8.onnx"), load("decoder-step.int8.onnx"),
]);
// vocab.txt: "<piece> <id>" per line; for a repeated piece the last id wins.
const pieces = [], ids = new Map();
for (const line of readFileSync(`${dir}/vocab.txt`, "utf8").split("\n")) {
const cut = line.lastIndexOf(" ");
if (cut <= 0) continue;
const id = Number(line.slice(cut + 1)), piece = line.slice(0, cut);
pieces[id] = piece; ids.set(piece, id);
}
const tok = (p) => ids.get(p);
const EOS = tok("<|endoftext|>");
// 16-bit PCM WAV, 16 kHz mono.
const buf = readFileSync(wav), at = buf.indexOf("data") + 8;
const pcm = new Int16Array(buf.buffer.slice(buf.byteOffset + at, buf.byteOffset + buf.length - ((buf.length - at) % 2)));
const audio = Float32Array.from(pcm, (x) => x / 32768);
// NeMo log-mel features: 128 bins, 25 ms window, 10 ms hop, pre-emphasis 0.97.
const fe = new ParakeetFeatureExtractor({ feature_size: 128, sampling_rate: 16000, hop_length: 160, n_fft: 512, win_length: 400, preemphasis: 0.97 });
const { input_features } = await fe(audio); // [1, frames, 128]
const [, frames, bins] = input_features.dims;
const feats = new Float32Array(frames * bins); // the encoder wants [1, 128, frames]
for (let t = 0; t < frames; t++) for (let m = 0; m < bins; m++) feats[m * frames + t] = input_features.data[t * bins + m];
const enc = await encoder.run({
audio_signal: new ort.Tensor("float32", feats, [1, bins, frames]),
length: new ort.Tensor("int64", BigInt64Array.of(BigInt(frames)), [1]),
});
// Once per recording: every layer's cross-attention mask, keys and values.
const context = await cross.run({ encoder_embeddings: enc.encoder_embeddings, encoder_mask: enc.encoder_mask });
async function decode(lang) {
const l = tok(`<|${lang}|>`);
let feed = [tok("▁"), tok("<|startofcontext|>"), tok("<|startoftranscript|>"), tok("<|emo:undefined|>"),
l, l, tok("<|pnc|>"), tok("<|noitn|>"), tok("<|notimestamp|>"), tok("<|nodiarize|>")];
let mems = new ort.Tensor("float32", new Float32Array(0), [6, 1, 0, 1024]);
const out = [];
let logprob = 0;
while (out.length < 512) {
const r = await step.run({ ...context, input_ids: new ort.Tensor("int64", BigInt64Array.from(feed, BigInt), [1, feed.length]), decoder_mems: mems });
const V = r.logits.dims[2], off = (r.logits.dims[1] - 1) * V, d = r.logits.data;
let best = -1;
for (let v = 0; v < V; v++) if ((out.length || v !== EOS) && (best < 0 || d[off + v] > d[off + best])) best = v;
if (best === EOS) break;
out.push(best); logprob += d[off + best];
mems = r.decoder_hidden_states; feed = [best];
}
const text = out.map((i) => pieces[i]).filter((p) => !/^<.*>$/.test(p)).join("").replaceAll("▁", " ").trim();
return { lang, text, score: out.length ? logprob / out.length : -Infinity };
}
// Canary does not detect the language: decode each candidate, keep the most confident.
const results = [];
for (const lang of langs.split(",")) results.push(await decode(lang));
const best = results.reduce((a, b) => (b.score > a.score ? b : a));
console.log(`[${best.lang}] ${best.text}`);
How to call the graphs
Features. NeMo log-mel: 16 kHz, 512-point FFT, 25 ms Hann window, 10 ms hop,
pre-emphasis 0.97, 128 slaney mel bins, log(x + 2^-24), then per-feature mean and
variance normalisation over the clip. Transformers.js ParakeetFeatureExtractor
with the settings in the example computes exactly this.
| Graph | Inputs | Outputs |
|---|---|---|
| encoder | audio_signal f32 [1, 128, T], length i64 [1] |
encoder_embeddings f32 [1, T/8, 1024], encoder_mask i64 [1, T/8] |
| cross | encoder_embeddings, encoder_mask |
12 tensors (names kept from the original graph) |
| step | input_ids i64 [1, L], decoder_mems f32 [6, 1, M, 1024], the 12 cross outputs by name |
logits f32 [1, L, 5248] (log-softmax), decoder_hidden_states f32 [6, 1, M+L, 1024] |
Decoding. Start with the prompt
▁ <|startofcontext|> <|startoftranscript|> <|emo:undefined|> <|xx|> <|xx|> <|pnc|> <|noitn|> <|notimestamp|> <|nodiarize|>,
where xx is the spoken language (en, fr, de, es), and empty decoder_mems
(M = 0). Take the argmax of the last position, feed it back as a single token with
decoder_mems set to the previous decoder_hidden_states, and stop at
<|endoftext|>. Join the pieces and replace ▁ with spaces.
Language. Canary does not detect the language. Decode each candidate in full and keep the transcript with the best mean log-probability: the cross tensors are shared, so only the step model runs again. Do not decide after a few tokens: with the wrong language prompt, Canary starts a confident translation and only loses confidence later in the sentence.
Two practical tips.
- On noisy audio, Canary can emit
<|endoftext|>as its very first token. If you know the clip holds speech, skip that token at step 0 (the example does). - Cut long silences out before transcribing, and split long recordings at pauses (segments of up to ~20-30 s work well).
Quality check
A small sanity check, not a benchmark: 7 sentences read by macOS voices (4 French, 3 English), clean and with white noise added at 10 dB SNR. Word error rate after lower-casing and removing punctuation, with the language chosen automatically between French and English:
| Clean | Noisy (10 dB SNR) | |
|---|---|---|
| French | 1.8 % | 1.8 % |
| English | 0 % | 0 % |
The French errors are hyphenation only ("Aide moi" for "Aide-moi"). For real accuracy figures see NVIDIA's model card. Synthetic voices are easier than real speakers.
Reproduce the split
pip install onnx==1.19.0
hf download istupakov/canary-180m-flash-onnx decoder-model.int8.onnx \
--revision 92c2231a4e2b2524277fea759be967d2e6edfc49 --local-dir src
python split_canary_decoder.py src/decoder-model.int8.onnx decoder-cross.int8.onnx decoder-step.int8.onnx
sha256sum decoder-cross.int8.onnx decoder-step.int8.onnx # same hashes as below
996d1c89e6cbc891a7c88bf410884c178ffa474f7b13084522ac74a5e144cc81 encoder-model.int8.onnx
6cf5fb8d1dbb565c07f70ce2a48889076c8a42db20d76f90baa4e826dfe82cde decoder-cross.int8.onnx
cd793635fca463c0add3e267b0687bb10d3d3c74d29906ddb43a6e447397b6bd decoder-step.int8.onnx
2dae6fc7815f9640645e0c765522b278ee0cef49b482d91f6913e334628d3e77 vocab.txt
Attribution and license
- Model: NVIDIA Canary-180M-Flash, © NVIDIA, under CC-BY-4.0. See the original model card for training data, evaluation and intended use.
- ONNX conversion: istupakov/canary-180m-flash-onnx
at commit
92c2231a, made for onnx-asr (CC-BY-4.0). - Changes in this repository: the encoder and vocabulary are unchanged copies.
The int8 decoder was modified: split into
decoder-cross.int8.onnxanddecoder-step.int8.onnxbysplit_canary_decoder.py. No weights were changed or retrained. - Decoding recipe: the prompt tokens and greedy decoding in
transcribe.mjsfollow onnx-asr by istupakov (MIT). No onnx-asr code is copied here. - Features: the example computes log-mel features with Transformers.js by Hugging Face (Apache-2.0), installed from npm, not bundled.
The model files are shared under CC-BY-4.0, like the model they come from. If you
redistribute them, keep this attribution (or NOTICE.md) and state your own
changes. This repository is not affiliated with or endorsed by NVIDIA or by the
authors of onnx-asr.
- Downloads last month
- 31
Model tree for moncefem/canary-180m-flash-onnx-split
Base model
nvidia/canary-180m-flash