Skip to content

Fix Granite NAR inference for the current model API; enable NAR on Windows - #45

Closed
sumgup0 wants to merge 3 commits into
paulbrav:masterfrom
sumgup0:nar-current-api
Closed

Fix Granite NAR inference for the current model API; enable NAR on Windows#45
sumgup0 wants to merge 3 commits into
paulbrav:masterfrom
sumgup0:nar-current-api

Conversation

@sumgup0

@sumgup0 sumgup0 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

The published ibm-granite/granite-speech-4.1-2b-nar remote code (loaded via
trust_remote_code) has drifted: its inference entrypoint was renamed
model.generate() -> model.transcribe() (can_generate() now returns False),
and its 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_waveform() raises AttributeError on the current model revision
under transformers 5.x - on every platform, not just Windows. The catalog gate
merely kept Linux/macOS users from discovering it.

This makes the NAR inference call version-robust (works against both the old and
new model revisions, protecting the pinned Linux NAR default) and lifts the
deliberate "NAR unsupported on Windows" gate now that NAR runs on Windows CUDA.

Changes

  • asr.py - version-robust NAR inference. Prefer model.transcribe(), fall
    back to model.generate(); prefer output.text_preds, else decode
    output.preds token ids with a tokenizer now loaded in _load(). Old and new
    model revisions both work, so the Linux NAR default does not regress.
  • catalog.py / profiles.py - lift the Windows gate. Add Windows to the
    NAR entry's supported_platforms and drop granite_nar_unsupported_reason from
    the Windows profiles (including the new windows_openvino one). Granite AR stays
    the Windows default; NAR becomes selectable. Incremental transcription stays
    gated on Windows (separate validation).
  • prefetch.py - _prefetch_granite_nar also caches the tokenizer, so a fresh
    models prefetch covers everything _load(local_files_only=True) needs.
  • Tests for both the new (transcribe/preds) and old (generate/text_preds)
    code paths; inverted the policy tests that asserted NAR-rejected-on-Windows;
    README/CONTEXT updated.

Why this likely matters on Linux too

The Linux NAR default runs the same transcribe_waveform. It works today only
because the cached model revision predates the upstream generate->transcribe
rename; the next time that remote code refreshes (or transformers is bumped), the
Linux default would hit the same AttributeError. The version-robust fix covers
both.

Testing

  • Verified on Windows 11 / RTX 5090 (cu128): NAR loads on cuda:0, ~0.06 s warm
    transcribe (vs ~0.33 s for Granite AR), correct transcript via the production
    path with local_files_only=True.
  • New unit tests for _nar_infer / _nar_decode (both API shapes) pass without
    the model downloaded.
  • ruff check + ty clean. Coexists with the OpenVINO backend - the ty lane
    caught the windows_openvino profile interaction during the rebase onto master.

sumgup0 and others added 3 commits June 13, 2026 22:38
…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 paulbrav#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>
paulbrav added a commit that referenced this pull request Jun 14, 2026
Version-robust NAR inference (transcribe/preds + generate/text_preds) with a lazy tokenizer so the Linux gfx1151 startup is unchanged. Supersedes #45 (orig by @sumgup0).
@paulbrav

Copy link
Copy Markdown
Owner

Superseded by #47, which merged your work (thanks @sumgup0!) rebased onto current master + review follow-ups: the NAR tokenizer is now loaded lazily so the Linux gfx1151 startup path is unchanged, plus a clearer inference error. The version-robust transcribe()/preds fix is in master as of 62c5e34. Closing this in favor of the merged version.

@paulbrav paulbrav closed this Jun 14, 2026
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