Skip to content

Latest commit

 

History

History
123 lines (86 loc) · 6.27 KB

File metadata and controls

123 lines (86 loc) · 6.27 KB

MedASR

Google's google/medasr ported to transcribe.cpp. 105M-parameter encoder-CTC for medical-dictation English ASR. 17-layer Conformer encoder with RoPE attention (rope_theta=10000), macaron FFNs (residual scalars [1.5, 0.5]), BatchNorm conv module (kernel=32, residual scalars [2.0, 1.0]), and a Linear 512→512 CTC head over a SentencePiece BPE vocabulary.

What it's for

Offline English speech-to-text optimized for medical dictation (radiology, internal medicine, family medicine). Decoder is greedy CTC; no language model, no beam search. This matches what HuggingFace transformers' AutoModelForCTC does by default.

Trained on ~5,000 hours of de-identified physician dictations on top of a LibriHeavy 50k-hour pretrain. The upstream model card flags lower accuracy on non-native accents and a male-skewed speaker distribution.

Licensed under the Health AI Developer Foundations terms. The upstream repo is gated; you must accept the HF terms before download.

Ported from upstream commit ae1e484, pinned 2026-06-04.

Input limits

MedASR is trained for audio up to about 400 seconds (~6.7 min) — the encoder's rotary-position window. Longer audio is accepted, but the library logs a WARN and accuracy may degrade past that window; it is not rejected. Segment long recordings for best results. See the input-length contract.

Download

Quantization Download Size WER (LibriSpeech test-clean)
F32 medasr-F32.gguf 417 MB 17.88%
F16 medasr-F16.gguf 202 MB 17.88%
Q8_0 medasr-Q8_0.gguf 122 MB 17.86%
Q6_K medasr-Q6_K.gguf 101 MB 17.93%
Q5_K_M medasr-Q5_K_M.gguf 90 MB 17.91%
Q4_K_M medasr-Q4_K_M.gguf 79 MB 18.14%

Recommended default: Q8_0. Smallest preset with no statistically detectable WER degradation versus F32 (122 MB; +0.00 pp within bootstrap CI). Q4_K_M shows a real +0.26 pp degradation on LibriSpeech and is shipped for completeness but not recommended — prefer Q5_K_M if you need smaller than Q8_0.

WER measured on the full LibriSpeech test-clean split (2,620 utterances) with greedy CTC decoding and no external LM. F32 reference baseline (HuggingFace transformers, Mac MPS): 17.88%; transcribe.cpp F32 matches exactly. Absolute WER is higher than general-purpose ASR (e.g. Whisper-base ≈ 5%) because the model is fine-tuned for medical dictation — on the publisher's internal RAD-DICT / GENERAL-DICT / FM-DICT datasets the model scores 6.6%–9.3%, but those datasets are not publicly reproducible. See reports/wer/medasr.test-clean.summary.md for the full sweep.

Quick Start

cmake -B build
cmake --build build

build/bin/transcribe-cli \
  -m models/medasr/medasr-Q8_0.gguf \
  --language en \
  samples/jfk.wav

If your audio is not already 16 kHz mono WAV, convert it first:

ffmpeg -i input.mp3 -ar 16000 -ac 1 output.wav

Performance

Cells are wall-clock latency (mean over 3 iterations after 1 warmup), with speedup over realtime in parentheses. Units: ms below 1 s, s above (2 decimal places).

Apple M4 Max

Backend Sample Q8_0 Q4_K_M
Metal jfk (11.0 s) 38 ms (290×) 44 ms (248×)
Metal dots (35.3 s) 84 ms (419×) 90 ms (394×)
CPU jfk (11.0 s) 161 ms (68×) 180 ms (61×)
CPU dots (35.3 s) 558 ms (63×) 623 ms (57×)

macOS 26.5, transcribe.cpp 8139a4b. Metal device: Apple M4 Max. Mel pipeline uses the shared MelFrontend (Accelerate vDSP fp64 FFT + cblas_sgemm); encoder is the conformer + RoPE + BatchNorm-conv graph in src/arch/medasr/encoder.cpp.

AMD Ryzen 7 4750U Pro

Backend Sample Q8_0 Q4_K_M
Vulkan jfk (11.0 s) 163 ms (68×) 174 ms (63×)
Vulkan dots (35.3 s) 481 ms (74×) 495 ms (71×)
CPU jfk (11.0 s) 543 ms (20×) 488 ms (23×)
CPU dots (35.3 s) 1.84 s (19×) 1.63 s (22×)

Fedora 43, transcribe.cpp 79d139a. Vulkan device: AMD Radeon Graphics (RADV RENOIR).

Benchmark reproduction:

uv run scripts/bench/run.py \
  --models medasr --quants q8_0,q4_k_m --samples jfk,dots \
  --backends metal,cpu,vulkan --iters 3 --warmup 1 --name medasr-publication

Numerical Validation

transcribe.cpp is validated tensor-by-tensor against the upstream HuggingFace Transformers reference on samples/jfk.wav via scripts/validate.py. The family-level forward map at reports/porting/medasr/forward-map.md documents the per-stage divergence sources (fp64 vDSP STFT, BatchNorm fusion, CUDA fp16-accumulator workarounds in the macaron + conv residual stack).

Field Value
Reference transformers @ 65dc2615 (dev commit; v5.0.0 not yet released), AutoModelForCTC.from_pretrained("google/medasr") device=mps fp32
Dump script scripts/dump_reference_medasr_transformers.py
Manifest tests/golden/medasr/medasr.manifest.json
Command uv run scripts/validate.py all --family medasr --variant medasr

Reproduction

Convert

uv run --project scripts/envs/medasr \
  scripts/convert-medasr.py google/medasr

Quantize

build/bin/transcribe-quantize \
  models/medasr/medasr-F32.gguf \
  models/medasr/medasr-Q8_0.gguf \
  --quant Q8_0

Validate

uv run scripts/validate.py all --family medasr --variant medasr