Skip to content

Granite NAR current-API fix (cleaned-up #45) - #47

Merged
paulbrav merged 4 commits into
masterfrom
cleanup/nar-current-api
Jun 14, 2026
Merged

Granite NAR current-API fix (cleaned-up #45)#47
paulbrav merged 4 commits into
masterfrom
cleanup/nar-current-api

Conversation

@paulbrav

Copy link
Copy Markdown
Owner

Owner-controlled, review-hardened version of #45 (original by @sumgup0). Rebased onto current master (post-#46) and carries @sumgup0's commits plus the thermonuclear-review follow-ups. Supersedes #45.

What #45 does

Makes Granite NAR inference version-robust against the upstream generate()transcribe() / text_predspreds API drift (would otherwise AttributeError on the next model refresh — on Linux too), and lifts the Windows NAR gate.

Review verdict

No regression to the primary Linux gfx1151 user — verified against the actual cached model revision: it falls to generate()/text_preds, byte-identical to master. No blockers.

Cleanups applied on top

  • Lazy NAR tokenizer. The contributor eagerly loaded a tokenizer in _load() that the current Linux revision never uses (it returns text_preds). Deferred to a cached _get_tokenizer() called only on the preds path, so the primary user's startup is unchanged from master, and _load() returns to its 2-tuple shape. prefetch still caches the tokenizer for offline use.
  • _nar_infer: clear RuntimeError when a model exposes neither transcribe() nor generate().
  • Trimmed the _nar_decode docstring.

Kept as-is (judged correct): the ungated NAR-on-Windows code is consistent with Linux (linux_cpu also allows NAR ungated), and the catalog/profiles formatting is ruff-compliant — reverting it would re-introduce drift.

Validation

ruff clean, ty unchanged (33), 393 tests pass (incl. the version-robust NAR tests). Recommend one warm gfx1151 NAR transcription before merge (CI is GPU-less).

🤖 Generated with Claude Code

sumgup0 and others added 4 commits June 15, 2026 02:51
…ndows

The published ibm-granite/granite-speech-4.1-2b-nar custom code drifted:
its inference entrypoint was renamed generate() -> transcribe()
(can_generate() now returns False), and the output changed from decoded
strings (output.text_preds) to raw token-id tensors (output.preds). The
NAR backend still called the old API, so transcribe() raised
AttributeError on the current revision under transformers 5.x -- on every
platform, not just Windows. The catalog gate merely kept Linux/Mac users
from discovering it; the friend's pinned Linux NAR works only because it
predates the upstream rename.

- asr.py: make NAR inference version-robust. Prefer model.transcribe()
  and fall back to model.generate(); prefer output.text_preds and else
  decode output.preds token ids with a tokenizer now loaded in _load().
  Old and new model revisions both work, so Linux/Mac do not regress.
- catalog.py / profiles.py: lift the deliberate "NAR unsupported on
  Windows" gate now that NAR runs on Windows CUDA. AR
  (granite-speech-4.1-2b) stays the Windows default; NAR becomes
  selectable. Incremental transcription stays gated on Windows (separate
  validation) with an accurate reason.

Verified on an RTX 5090 (Blackwell, cu128): NAR loads on cuda:0, warm
transcribe ~0.06s (vs ~0.33s for AR), correct transcript. New unit tests
cover both the new (transcribe/preds) and old (generate/text_preds) code
paths without needing the model downloaded.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow-up to the nar-current-api review:

- models/prefetch.py: _prefetch_granite_nar now also caches the tokenizer
  (AutoTokenizer) so a fresh prefetch covers everything the NAR backend
  loads with local_files_only=True; it previously relied on AutoProcessor
  co-caching the tokenizer files.
- asr.py: _nar_decode uses truthiness instead of `is not None`, so a
  present-but-empty text_preds/preds falls through instead of raising
  IndexError; documented that already-decoded text_preds wins when both
  are present. New tests pin both behaviours.
- README/CONTEXT: Granite NAR is now selectable on Windows CUDA (AR stays
  the default); updated the support matrix and the Windows ASR list. ROCm
  remains unsupported on Windows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Upstream PR #43 added a new `windows_openvino` runtime profile that set
`granite_nar_unsupported_reason=GRANITE_NAR_UNSUPPORTED_WINDOWS`. This branch
deletes that constant when lifting the NAR-on-Windows gate, so git's textual
auto-merge (the two changes never overlapped a line) left a dangling reference
that `ty` flagged as unresolved-reference. Lift the gate on windows_openvino
too, consistent with NAR being selectable on every Windows profile -- device
resolution handles actual CUDA availability.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Review follow-ups on top of sumgup0's NAR-current-api work:
- Load the NAR tokenizer lazily (cached) instead of eagerly in _load(). The
  current cached Linux gfx1151 revision returns decoded `text_preds` and never
  uses the tokenizer, so the eager load added an unused object to the PRIMARY
  user's startup. Deferring it keeps that path byte-for-byte as it was, and
  reverts _load() to its master 2-tuple shape. prefetch still caches the
  tokenizer so the lazy load works offline (local_files_only=True).
- _nar_infer: raise a clear RuntimeError when a model exposes neither
  transcribe() nor generate(), instead of a bare AttributeError.
- Trim the _nar_decode docstring.

Validated: ruff clean, ty unchanged (33), 393 tests pass (incl. the version-robust
NAR tests, updated for the load_tokenizer callable).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@paulbrav
paulbrav merged commit 62c5e34 into master Jun 14, 2026
3 checks passed
@paulbrav
paulbrav deleted the cleanup/nar-current-api branch June 14, 2026 19:16
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