GigaAM-v4-c

A dependency-free C runtime for streaming speech recognition with ai-sage/GigaAM-v4 (RNN-T, Russian and English), plus the pipeline that turns the original checkpoint into the single model file it reads.

  • Streaming with partial results at 160, 320 or 640 ms context, both output heads (e2e: punctuated and capitalised, raw: lowercase).
  • Pure C11, no BLAS or other libraries: hand-written NEON (ARM) and AVX2 (x86) kernels. One shared read-only model, any number of independent streams, no locks or globals.
  • Same transcripts as the original PyTorch model (see Accuracy).
  • Optional: split one stream across threads, step many streams as one batch, or use an int8 model file for about 2x the speed at some cost in accuracy.

Quick start

# 1. Python environment for the conversion pipeline (Python 3.12)
uv venv .venv && uv pip install --python .venv/bin/python -r requirements.txt

# 2. Original checkpoint -> ONNX -> build/gigaam-v4-rnnt.gigaam (+ the int8 variant)
make models

# 3. C runtime (needs only a C compiler)
make

# 4. Transcribe
build/gigaam_bench build/gigaam-v4-rnnt.gigaam speech.wav --partials   # 16 kHz mono wav
build/gigaam_mic build/gigaam-v4-rnnt.gigaam                           # macOS microphone

make models runs four steps, each also available on its own:

Step Command Output
Download ai-sage/GigaAM-v4 at a pinned revision make fetch model/
Export the streaming ONNX graphs make onnx onnx/
Convert to the C model file (f16, lossless) make model build/gigaam-v4-rnnt.gigaam (489 MB)
Convert with int8 encoder weights make model-int8 build/gigaam-v4-rnnt-int8.gigaam (287 MB)

make check compares every weight in the .gigaam file against the original model.safetensors (all 361 tensors match exactly).

Tools

gigaam_bench transcribes a wav file as a live stream and reports latency.

build/gigaam_bench MODEL speech.wav [--context-ms 160|320|640] [--partials]
    [--stream-threads N]   # split each step across N threads (lower latency)
    [--threads N]          # N independent streams on one shared model
    [--batch N]            # each worker steps N streams together
    [--heads e2e|raw|all] [--out PREFIX]

gigaam_mic transcribes live audio: the microphone on macOS, or raw 16 kHz 16-bit mono PCM on stdin anywhere.

build/gigaam_mic MODEL [--context-ms N] [--threads N] [--head e2e|raw] [--endpoint-ms N]
arecord -q -f S16_LE -r 16000 -c 1 -t raw | build/gigaam_mic MODEL --stdin      # Linux
ffmpeg -loglevel quiet -i any.mp3 -f s16le -ac 1 -ar 16000 - | build/gigaam_mic MODEL --stdin

Browser: the GigaAM-v4-c Space runs the same runtime as WebAssembly (SIMD128 + threads): load a .gigaam file and transcribe the microphone or an audio file inside the tab. make wasm builds it (with emcc, or Docker for emscripten/emsdk) and copies it into the Space checkout at SPACE_DIR (default ../../spaces/eschmidbauer/GigaAM-v4-c).

stream_transcribe.py is the Python reference (PyTorch or ONNX Runtime) the C output is checked against: .venv/bin/python stream_transcribe.py speech.wav --backend onnx.

C API

src/gigaam.h, linked from build/libgigaam.a:

gigaam_model *model = gigaam_model_load("build/gigaam-v4-rnnt.gigaam", err, sizeof err);
/* or gigaam_model_load_memory(bytes, size, err, sizeof err) for a file already in memory */
gigaam_stream_config config = {.context_ms = 320, .threads = 1};
gigaam_stream *stream = gigaam_stream_new(model, &config);

gigaam_stream_feed_i16(stream, pcm, samples);              /* any packet size, 16 kHz */
const char *partial = gigaam_stream_take(stream, head);    /* text added since last take */
gigaam_stream_flush(stream);                               /* end of utterance */
const char *text = gigaam_stream_text(stream, head);

gigaam_stream_free(stream);
gigaam_model_free(model);

A model is immutable after loading and can be shared by any number of threads; each stream is used by one thread at a time. For servers, gigaam_stream_push + gigaam_batch_step run one model step for many streams together, reading the weights once. Each stream gets exactly the result it would get alone.

Build options

make                       # hand-written kernels (default)
make BLAS=openblas         # reference build against OpenBLAS
make BLAS=accelerate       # macOS Accelerate
docker buildx build --platform linux/arm64,linux/amd64 --target export -o dist .

The Docker build cross-compiles static Linux binaries for arm64 and amd64. Requirements: arm64 needs ARMv8 NEON; dot-product (sdot) and matrix-multiply (smmla) instructions are used for int8 when the CPU has them, detected at run time. x86 needs AVX2, FMA and F16C (x86-64-v3); there is no runtime dispatch.

Accuracy

There is no reference transcript for the test recording used here (256 s of noisy phone audio, Russian and English), so accuracy means agreement with the original PyTorch streaming model.

  • f16 model (default): identical transcripts to PyTorch and ONNX Runtime at 640 and 320 ms, both heads. At 160 ms the e2e head is identical and the raw head differs by one word in 475, at a point where two outputs score within 0.001 of each other. Identical across thread counts, batch sizes, arm64/amd64 and the OpenBLAS build.
  • int8 model (opt-in): encoder weights and activations quantized to int8 with one scale per 32 values. 2-5% of words differ from the f16 model, mostly in noisy stretches. Whether that is worse or just different needs labelled data. bf16-rounded weights, by comparison, change nothing.

For upstream word error rates on public test sets see the GigaAM-v4 model card.

Speed

Milliseconds of compute per packet, one stream, Apple M2 Max:

Context f16, 1 thread f16, 4 threads int8, 1 thread int8, 4 threads
640 ms 79 25 36 13
160 ms 30 11 13 6

The f16 model takes about 520 MB of memory, most of it the memory-mapped model file shared between processes; each extra stream adds about 6 MB. With all 8 performance cores busy, the M2 Max sustains about 60x realtime with f16 and 120x with int8 at 640 ms context. Linux arm64 is within about 10% of these numbers; x86 has only been tested under emulation.

Repository layout

Path Contents
src/ C runtime: gigaam.h API, encoder/frontend/decoder, kernels, tools
scripts/fetch_model.py download the original checkpoint
scripts/export_onnx.py streaming ONNX export (upstream's exporter)
scripts/onnx_to_bin.py, gigaam_bin.py ONNX -> .gigaam (optionally int8)
scripts/check_bin.py .gigaam vs original weights
scripts/compare_backends.py transcripts and numerics: PyTorch vs ONNX vs C
scripts/docker_bench.sh, compare_dumps.py hand-written kernels vs OpenBLAS in Docker
stream_transcribe.py Python streaming reference

License

MIT. The GigaAM-v4 weights and modeling_gigaam.py are downloaded from ai-sage/GigaAM-v4 under their own MIT license and are not included in this repository.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for eschmidbauer/GigaAM-v4-c

Finetuned
(5)
this model