Skip to content

Add MLX Whisper and faster-whisper instrumentation - #88

Merged
piotrekno1 merged 4 commits into
develfrom
feat/whisper-instrumentation
Oct 21, 2026
Merged

piotrekno1 merged 4 commits into
develfrom
feat/whisper-instrumentation

Conversation

@piotrekno1

@piotrekno1 piotrekno1 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Adds opt-in mlx_whisper and faster_whisper integrations for local speech recognition, closing #65. See docs/whisper.md.

Model loads

  • Recorded with backend, format, family, accelerator and compute type/quantization.
  • Model IDs use the hub repo name (also for Hugging Face cache paths) or the local folder name. They are worked out once, at load.
  • Every load is recorded, including MLX reloads after switching models and repeat WhisperModel instances.
  • A model that MLX had cached before the SDK started is reported once, with model_cache_hit=true.

Transcriptions

  • Duration, audio metadata, language and confidence.
  • Word count, left out for languages written without spaces.
  • time_to_first_segment_ms for faster-whisper.
  • faster-whisper's BatchedInferencePipeline is tracked too.

faster-whisper lifecycle

  • Decoding stays lazy. Exhaustion, close() and decoder errors each record one outcome.
  • A loop that exits early without close() records STREAM_ABANDONED when the iterator is collected. This is a deliberate exception to the no-finalizer rule in docs/streaming.md; otherwise early-stopped and failed transcriptions would vanish silently.
  • Models stay bound to the client that loaded them, using bind_client_reference.

Capture

  • Audio and transcript attachments require attachments_enabled=True.
  • Each attachment is capped at 10 MiB, and the existing attachment filter applies.

Shared changes outside the Whisper modules

  • New wildedge/accelerators.py with the SDK's accelerator names. Whisper reports cuda/mps/cpu like the other integrations; moving the rest of the SDK onto it follows in a separate PR.
  • The client's auto-load callback gains reload=.
  • Stream wrappers expose started/finished.
  • hf_repo_from_cache_path() is now shared with ONNX.
  • stream_error_code() is now shared by the OpenAI, Anthropic and GGUF streams.

Before 0.3.0: raw audio uploads whenever attachments are enabled. A per-media setting (for example attachment_media, defaulting to text only) is planned as a separate PR and must land before the release.

Validation

  • SDK suite: 839 passed, 28 skipped; Ruff and formatting checks pass.
  • Compatibility tests against real libraries, pinned versions:
    • MLX decoding with tiny random weights.
    • faster-whisper with the pinned public tiny model, including the snapshot-path model ID and the batched pipeline.
  • Manual checks with the real libraries:
    • An early break on real speech records one STREAM_ABANDONED event, timed to the last segment.
    • MLX reports bf16 and follows the default device (cpu/gpu).
  • From the original commit, before the review changes: real models (MLX large-v3-turbo, CTranslate2 small) and app capture modes off/text/audio, with transport stubbed.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Coverage report

  • Total: 89% (11702/13149 lines)

Top uncovered files

  • wildedge/integrations/mlx.py: 28.7% (122 lines missed)
  • wildedge/integrations/transformers.py: 62.9% (112 lines missed)
  • wildedge/integrations/ultralytics.py: 67.7% (86 lines missed)
  • wildedge/integrations/pytorch.py: 66.0% (69 lines missed)
  • wildedge/platforms/macos.py: 56.8% (67 lines missed)

- Name models once at load: Hugging Face cache paths use the repo name
  instead of the snapshot hash, and local folders resolve relative paths.
- Record every real load, including MLX reloads after switching models and
  repeat WhisperModel instances.
- Track BatchedInferencePipeline, which does not go through
  WhisperModel.transcribe.
- Report a faster-whisper loop that exits early as STREAM_ABANDONED when the
  iterator is collected; never-iterated streams send nothing.
- Bind faster-whisper models with bind_client_reference like provider
  clients, so a replaced client warns once.
- Report time_to_first_segment_ms; leave out word counts for languages
  written without spaces.
- Detect the MLX device and bf16, and read quantization from layers for
  models cached before instrumentation.
- Share one capture limit constant, clearer track_transcription arguments,
  a transcript collector class and one MLX fallback helper.
- Split and extend tests; restructure docs/whisper.md; add a changelog entry.
- Name backend, source, WAV encoding and upstream-default constants, and
  move 16-bit WAV encoding into its own helper.
- Share Hugging Face cache path parsing with the ONNX integration, and
  STREAM_* error codes with the stream integrations.
- Add reload= to the client's auto-load callback instead of editing its
  dedupe set from the integration; record cached MLX loads through one helper.
- Expose started/finished on stream wrappers so the segment stream no longer
  reads private state.
- Compare MLX devices directly, leave unknown dtypes unlabelled, bind the MLX
  loader's signature, and reuse registered handles per transcription.
- Clearer names and keyword arguments; tests share the MLX fixture and use a
  weak-referenceable fake model.
Whisper reported "gpu", which no other integration uses. faster-whisper now
passes through CTranslate2's resolved device ("cpu" or "cuda") and MLX
reports "mps" for the Apple GPU, matching GGUF, TensorFlow and Keras on the
same machine. Accelerator names live in the new wildedge.accelerators module.
@piotrekno1
piotrekno1 merged commit aba75f0 into devel Oct 21, 2026
14 checks passed
@piotrekno1
piotrekno1 deleted the feat/whisper-instrumentation branch October 21, 2026 09:29
@github-actions github-actions Bot mentioned this pull request Oct 21, 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.

1 participant