Views
No views yet
kb-whisper-large in whisper.cpp with CoreML/ANE acceleration on Apple Silicon Macs.| File | Description |
|---|---|
ggml-model-encoder.mlmodelc/ | CoreML encoder with int8-quantized weights (float32 I/O). 609 MB — half the size of a float32 encoder, faster on ANE. |
1wget https://huggingface.co/KBLab/kb-whisper-large/resolve/main/ggml-model-q5_0.bin
2# or the full-precision version:
3# wget https://huggingface.co/KBLab/kb-whisper-large/resolve/main/ggml-model.binggml-model-encoder.mlmodelc/ from this repo and place it in the same directory as the GGML model file:your-model-dir/
├── ggml-model-q5_0.bin ← GGML weights
└── ggml-model-encoder.mlmodelc/ ← this CoreML encoder1git clone https://github.com/ggerganov/whisper.cpp
2cd whisper.cpp
3cmake -B build -DWHISPER_COREML=ON
4cmake --build build --config Release./build/bin/whisper-cli -m your-model-dir/ggml-model-q5_0.bin -f audio.wav -l sv1# Greedy decoding (drop beam search) — biggest single speedup
2./build/bin/whisper-cli -m ggml-model-q5_0.bin -f audio.wav -l sv -bs 1 --best-of 1
3
4# M1/M2: use 4 threads (performance cores only)
5./build/bin/whisper-cli -m ggml-model-q5_0.bin -f audio.wav -l sv -t 4coremltools and compute_units=ALL.logmel_data (not mel). An incorrectly named input causes silent garbage output from the encoder.main branch of KBLab/kb-whisper-large as of May 2025 (Stage 2 checkpoint). If KBLab update their weights, regenerate using the script below.1# make_coreml.py
2import numpy as np
3import torch
4import coremltools as ct
5import coremltools.optimize.coreml as cto
6from transformers import WhisperForConditionalGeneration
7
8class EncoderWrapper(torch.nn.Module):
9 def __init__(self, encoder):
10 super().__init__()
11 self.encoder = encoder
12
13 def forward(self, mel):
14 return self.encoder(mel).last_hidden_state
15
16MODEL_DIR = "path/to/kb_whisper_large" # local HuggingFace checkout
17OUTPUT_MLPACKAGE = f"{MODEL_DIR}/ggml-model-encoder.mlpackage"
18
19model = WhisperForConditionalGeneration.from_pretrained(MODEL_DIR)
20encoder = EncoderWrapper(model.model.encoder).eval()
21dummy = torch.randn(1, 128, 3000)
22traced = torch.jit.trace(encoder, dummy, strict=False)
23
24mlmodel = ct.convert(
25 traced,
26 convert_to="mlprogram",
27 inputs=[ct.TensorType(name="logmel_data", shape=dummy.shape, dtype=np.float32)],
28 outputs=[ct.TensorType(name="output", dtype=np.float32)],
29 compute_units=ct.ComputeUnit.ALL,
30 minimum_deployment_target=ct.target.macOS13,
31)
32
33# Quantize weights to int8 — halves size, faster on ANE
34op_config = cto.OpLinearQuantizerConfig(mode="linear_symmetric", dtype="int8", granularity="per_channel")
35config = cto.OptimizationConfig(global_config=op_config)
36mlmodel = cto.linear_quantize_weights(mlmodel, config=config)
37
38mlmodel.save(OUTPUT_MLPACKAGE)
39
40# Then compile:
41# xcrun coremlcompiler compile ggml-model-encoder.mlpackage path/to/output/