Skip to content

New Community Model: Granite Speech 5.0 2B (IBM) - #1332

Merged
0xShug0 merged 25 commits into
0xShug0:mainfrom
eutychus:granite-speech-2b
Nov 19, 2026
Merged

0xShug0 merged 25 commits into
0xShug0:mainfrom
eutychus:granite-speech-2b

Conversation

@eutychus

Copy link
Copy Markdown
Contributor

Summary

Adds granite_speech_2b, a community port of IBM Granite Speech 5.0 2B (pinned rev ec49ca6b), an autoregressive multilingual ASR model: Conformer encoder, Q-Former projector, and Granite causal LLM. This is a separate inference architecture — and therefore a separate family — from the existing TurboCTC granite5asr loader, which is untouched (loader, packages, and granite_speech* aliases unchanged).

Scope: offline multilingual ASR (en/fr/de/es/pt/ja) with punctuation and capitalization, optional source-language hints, framework offline chunking, keyword biasing, and speech translation (en→fr/de/es/pt/it, ja→en) through the CLI and legacy server. Related: #54.

Implementation

  • New family under src/community_models/granite_speech_2b/ + include/engine/community_models/granite_speech_2b/, model-spec v1 (model_specs/granite_speech_2b.json, status: community).
  • Frontend: shared NemoMelFrontend (centered periodic Hann, reflect pad, HTK, 512/400/160, DensePowerLog10 1e-10 floor), per-clip max floor over all raw frames then (v/4)+1, adjacent-frame pairing with odd-row drop.
  • Acoustic: 16-layer Conformer (pre-norm Macaron FFN ×0.5, Shaw attention in 200-frame blocks, full-sequence conv, block-8 CTC feedback) + Q-Former (15-row windows, 3 queries, eps 1e-12, pads participate) — with a fixed bug found in validation: the projector graph node budget now scales with window count (was a fixed 65536, aborting spans above ~60 s).
  • Decoder: Granite weights bound into the shared decoder behind neutral-default opt-in fields (embed ×12, attn scale 0.0078125, residual ×0.22, YaRN base-10000/factor-4, logits ÷8). Existing callers are bit-identical by construction; Audio8/Qwen3 + chunked-prefill + packed-projection regressions green. One shared-converter guard (float --keep-type on rank-0 tensors warns instead of throwing) with a new unit test.
  • Prompt: LlamaBpeTokenizer (Llama3 preset, proven by exact ID parity), single-turn template with model-owned audio marker 100352, BOS/EOS 100257, sorted-contiguous injection (A·2048), reserved-marker rejection, per-chunk language hints.
  • Session/loader: make_granite_speech_2b_loader, RuntimeSessionBase offline session (auto/fixed/vad/none chunking, 120 s cap, VAD fallback, JP-aware join, error recovery + A/B/A isolation). Multipart target_language is a loud 400 directing to JSON options.target_language (single-file shape has no options channel); batch multipart requires native batching this family doesn't implement.

Download packages

  • Default install today: granite_speech_2b_safetensors (pinned IBM snapshot, installs via model_manager_v2 install — verified from an empty root, goldens reproduce from the installed artifact).
  • granite_speech_2b_q8_0 (280 Q8_0 + 658 BF16 + 16 I64, native keys preserved): E2-gated release artifact; becomes the default once uploaded to the release remote (upload + pin + flip steps recorded in the validation report §9/§11). Convert locally meanwhile: audiocpp_gguf --family granite_speech_2b --type q8_0 --keep-type 'encoder.*=bf16' ... (full recipe in docs/models/granite_speech_2b.md).

Performance & Verification

Pinned reference: Transformers 4.57.0, torch 2.8.0 CPU, FP32, eager. Audio: LibriVox Monte Cristo ch.1 (16 kHz mono; 180 s excerpt + full 1179.4 s chapter). Machine: i9-12900K, 31 GB RAM; RTX 3080 12 GB.

Implementation Clip Wall RTF
Reference (HF, CPU) 180 s 110.3 s (load 1.2 + generate 109.0) 0.61
C++ CPU, native 180 s 135.8 s 0.75
C++ CPU, Q8_0 180 s 132.5 s 0.74
C++ GPU (RTX 3080), native 180 s 11.33 s 0.063
C++ GPU, Q8_0 180 s / full 11.56 s / 67.4 s ~0.06
C++ CPU native, chunked full 1179 s 993.7 s 0.84

Matched single-span runs are at parity or better for C++ (prefill 10.0 s vs 14.5 s reference; decode parity; frontend parity). The 180 s gap is structural: the CLI chunks (120+60, 2×512-token budget) while the reference runs one 1800-placeholder prompt with a single 512 budget.

Parity gates: 19/19 compare_trace stages through generate on all fixtures (rel_rms ~1e-6, logits max-abs ~1e-4 vs 2e-2 tol); 120 s segment transcript byte-identical to the reference; native≡orig≡Q8_0 transcripts byte-identical (WER 2.90%, CER 6.25%, Δ+0.00pp); IBM official Q8_0 pair agrees (one comma-only long-EN diff). Runtime integration green (CLI native/embedded, server JSON + multipart + auto-JA + xx reject, valid-after-failure, two-session repeat, TurboCTC golden + timestamps). Full matrix: custom/full composite configure, ctest -R 'granite_speech_2b|granite5asr_ctc|server_parallel' 8/8 + model_spec_system_test green, loader/catalog sync clean for this family.

Docs: docs/models/granite_speech_2b.md (usage, conversion, options), docs/reports/granite_speech_2b_validation.md (full E2 gate table + release decision), docs/reports/granite_speech_2b_porting_notes.md (architecture map, numerical contract, gotchas, benchmarks).

server.json

{
  "host": "127.0.0.1", "port": 18080, "backend": "cpu",
  "models": [{ "id": "granite-2b", "family": "granite_speech_2b",
                "path": "models/Granite-Speech-5.0-2B-hf", "task": "asr", "mode": "offline" }]
}

CLI & Server Usage

# Offline transcription (native snapshot, installed package dir, or GGUF)
audiocpp_cli --task asr --family granite_speech_2b --model build/granite-2b-handoff/hf \
  --audio sample.wav --request-option language=en --backend cpu --threads 8
# Keyword biasing (comma-separated terms travel in the text channel)
audiocpp_cli --task asr --family granite_speech_2b --model <model> --audio sample.wav \
  --text "Concord, tents"
# Speech translation (JSON options; OpenAI-compat multipart has no options channel)
curl http://127.0.0.1:18080/v1/audio/transcriptions -H 'Content-Type: application/json' \
  --data-binary '{"model":"granite-2b","audio":"sample.wav","language":"en","options":{"target_language":"fr"}}'

Known limitations

  • Advertised translation: en→fr/de/es/pt/it + ja→en only (others prompt-parity-covered but unadvertised; en→zh diverges at token 1 — quarantined, root cause pending before advertising zh).
  • Natural >60 s audio and fr/de/es/pt evaluation rows pending (synthetic 63.9 s chunk-requiring slice passes byte-identical).
  • Prebuilt Q8_0 remote not yet uploaded (install the snapshot package or convert locally until then).
  • CPU-only runtime tags; no word timings/speakers/streaming (unset by design).

AI Disclaimer: Yes, I used AI assistance to implement this port. Every milestone was task-reviewed, all gates are evidenced in-tree, and the shared-framework changes are neutral-defaulted with existing-caller regressions green.

@eutychus eutychus changed the title community: add IBM Granite Speech 5.0 2B autoregressive ASR New Community Model: Granite Speech 5.0 2B (IBM) Nov 18, 2026
@0xShug0

0xShug0 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

@eutychus Thanks for contributing a new model! There are some issues and I'll make changes directly to the PR.

eutychus and others added 24 commits November 18, 2026 21:00
- can_load installed-dir fallback and GGUF package path reject
  directories holding native weight files (foreign native checkpoint
  with a stray GGUF no longer misroutes); red-green covered by a new
  d_units symlink test plus predicate checks.
- require_shape errors name the tensor source file; tail-rebalance
  comment states the real <=cap+128 bound; stale Task-E comment fixed;
  C1 fixtures end with a newline.
- reference.py rope-dict hook fails closed with RuntimeError on
  partial/missing keys instead of leaking KeyError.
- Validation doc: synth row scoping, natural->60s pending wording,
  operator-step numbering.
… count

The per-window Q-Former loop adds O(100+) graph nodes per window against
a fixed 65536-node budget, aborting (GGML_ASSERT n_nodes < size) on
spans above ~60 s (W=600 at 180 s). Reserve base + 1024 nodes per
planned window instead. Regression test: synthetic 9000-step projector
run (red: same assert, green: finite outputs, A=1800).
Covers the granite_speech_2b port (checkpoint rev, architecture map,
numerical contract, verification, CPU/GPU/reference RTF on Monte
Cristo ch.1, release state, reproduce commands). Notes file only; no
models, weights, build outputs, or audio.
Flip family status experimental -> community. Add installable
granite_speech_2b_safetensors package (pinned IBM snapshot rev) since
the prebuilt Q8_0 remote is not yet uploaded; repo rule requires the
default package to be GGUF, so it stays the E2-gated Q8_0 entry and
ui.recommended_package tracks it. Until the org upload lands, install
the snapshot package id explicitly or convert locally.

Verified: model_spec_system_test, loader/catalog sync (no g2b drift),
clean-root snapshot install, CLI goldens (en+ja) from the installed
artifact, b1/d/f/lifecycle/timestamps green.
Replace hardcoded CUDA toolkit paths with <cuda-home> placeholders
(referencing docs/build/linux.md) and scratch-dir paths with
$GRANITE2B_WORK/<build-dir> placeholders. Benchmark hardware
provenance retained as data.
Matches the per-model validation-report convention
(nemotron_transcribe, underdog_bark3, phonon2, glm_tts). No content
changes beyond path updates in cross-links.
Remove stored fixtures and porting artifacts, keep independent parity tooling, and scope shared decoder extensions to neutral defaults. Reuse session-owned framework graphs, batched Q-Former windows, and the shared greedy decoder. Rename the new family to granite_speech5 while preserving granite5asr registration and aliases. Restore generic server and tensor-source behavior to main.

Validated controlled FP32 parity, native and mixed-Q8 inference, CUDA/Vulkan/CPU lifecycle and warmed performance, targeted existing decoder callers, and final smoke/spec/catalog checks.
@0xShug0
0xShug0 marked this pull request as draft November 19, 2026 04:05
@0xShug0
0xShug0 marked this pull request as ready for review November 19, 2026 04:41
@0xShug0

0xShug0 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@eutychus

I refactored the implementation to address some problematic patterns inherited from Granite5ASR. Performance has also improved.

The conversion script now handles the tensor layout correctly, so no changes to the shared TensorSource are needed.

I removed the bundled fixtures. The repository already provides a minimal shared fixture set; model-specific fixtures should be hosted externally rather than stored in the code repository.

A = orig PR B = after refactor Native BF16 tensor

Backend A RTF range B RTF range
CUDA 0.02409–0.04168 0.02008–0.03444
Vulkan 0.02831–0.04873 0.02119–0.03978
CPU 0.57555–0.88333 0.36485–0.57124
Process peak memory A → B
CUDA VRAM 6,148 → 5,418 MiB
Vulkan VRAM 5,580 → 5,121 MiB
CPU RAM 6,065 → 5,420 MiB

@0xShug0
0xShug0 merged commit 5e7273d into 0xShug0:main Nov 19, 2026
7 checks passed
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.

2 participants