File size: 7,930 Bytes
3e06cf4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | ---
license: apache-2.0
base_model: higurashi-ai/Haru-4B
language:
- ja
- en
- zh
- ko
- es
- pt
- de
- fr
- ru
pipeline_tag: audio-to-audio
tags:
- coreai
- apple-silicon
- metal4
- swift
- macos
- speech
- full-duplex
- speech-to-speech
- haru
---
# Haru-4B Core AI (Apple Silicon + Native macOS App)
High-performance native **Apple Core AI + Metal 4** port of [`higurashi-ai/Haru-4B`](https://huggingface.co/higurashi-ai/Haru-4B) β a 7.5 Hz full-duplex continuous speech-to-speech dialogue model β packaged with **ready-to-run Core AI weights (`weights/`)** AND a **native Swift 6 / SwiftUI macOS full-duplex voice app (`app/HaruCoreAI-macOS.zip` + full SwiftPM source)**.
Built for **Japanese, English, and mixed JP/EN code-switching** live voice conversations on Apple Silicon, decisively beating `haru_mlx` (`int8` & `bf16`) on latency, footprint, load time, **and** audio/logit quality.
---
## Performance & Bilingual Quality vs `haru_mlx` (Apple M4 Pro)
Measured on Apple M4 Pro (48 GB Unified Memory, macOS 27.3, 50 timed frames after 10 warmup; 7.5 Hz real-time budget = `133.3 ms/frame`):
| Metric | `haru_mlx` bf16 | `haru_mlx` int8 (`g=64`) | **Haru-4B Core AI (`this repo`)** | Gain vs `haru_mlx` int8 |
|---|---:|---:|---:|---|
| **E2E Full Frame (p50 / min)** | 56.78 ms | 37.44 ms | **29.32 / 28.79 ms** | **1.28x faster (-8.12 ms)** |
| **Live Critical Path (p50 / min)** | 55.25 ms | 34.86 ms | **27.39 / 26.72 ms** | **1.27x faster (-7.47 ms)** |
| **Prefill (169 pos, warm)** | 301.29 ms | 317.90 ms | **307.42 ms** | **1.03x faster (-10.48 ms)** |
| **Warm Model Load** | ~1.2 s | 0.76 s | **0.00β0.01 s** (OS cache) | **~76x faster** |
| **Real-Time Factor (RTF)** | 2.35x | 3.56x | **4.55x E2E / 4.87x Live** | **+1.31x headroom** |
| **Model Asset / Weight Size** | 10.68 GB | 6.74 GB | **5.48 GB** | **1.26 GB smaller (-18.7%)** |
### Compiled GPU Quality vs PyTorch `bfloat16` Ground Truth (40 Streaming Frames)
| Suite | Metric | `haru_mlx` bf16 | `haru_mlx` int8 | **Haru-4B Core AI** | vs `haru_mlx` int8 |
|---|---|---:|---:|---:|---|
| **English** | Codec Enc / Dec PSNR | 43.99 / 64.71 dB | 43.99 / 64.71 dB | **48.53 / 66.46 dB** | **+4.54 / +1.75 dB** |
| **English** | Codec Multi-Res STFT L1 | 0.00021 | 0.00021 | **0.00018** | **1.17x lower error** |
| **English** | LM Logits KL Div / Top-1 | 0.00194 / 100% | 0.00323 / 100% | **0.00224 / 100%** | **1.44x lower KL** |
| **English** | PAD/EOP Margin MAE | 0.0481 | 0.2102 | **0.1328** | **1.58x better** |
| **English** | MeanFlow Head E2E PSNR | 43.64 dB | 38.06 dB | **38.93 dB** | **+0.87 dB** |
| **JP / Mixed** | Codec Enc / Dec PSNR | 42.75 / 63.61 dB | 42.75 / 63.61 dB | **43.65 / 64.53 dB** | **+0.90 / +0.92 dB** |
| **JP / Mixed** | Codec Multi-Res STFT L1 | 0.00024 | 0.00024 | **0.00022** | **1.09x lower error** |
| **JP / Mixed** | LM Logits PSNR / Top-5 | 49.92 dB / 100% | 43.56 dB / 100% | **46.33 dB / 100%** | **+2.77 dB** |
| **JP / Mixed** | PAD/EOP Margin MAE | 0.0316 | 0.1454 | **0.0531** | **2.74x better** |
| **JP / Mixed** | MeanFlow Head E2E PSNR | 42.81 dB | 32.97 dB | **35.25 dB** | **+2.28 dB** |
See [`LOG.md`](LOG.md) for the complete engineering log, 32-layer quantization sensitivity analysis, and ablation tables.
---
## Quickstart: Native macOS App (`HaruCoreAI.app`)
**Requirements**: Apple Silicon Mac (M1/M2/M3/M4) running **macOS 27.0+** (native `CoreAI.framework`).
### Option A β Download the Prebuilt App
1. Download [`app/HaruCoreAI-macOS.zip`](app/HaruCoreAI-macOS.zip) (3.1 MB) and unzip `HaruCoreAI.app`.
2. Open `HaruCoreAI.app` (if macOS warns about ad-hoc signature, right-click β Open or run `xattr -dr com.apple.quarantine HaruCoreAI.app`).
3. Click **Download from Hugging Face** inside the app to pull `weights/` (5.48 GB) automatically β or point it at a local `weights/` folder via **Choose Local Folderβ¦** (`βO`).
4. Pick a preset (**γγ« Β· Bilingual JP/EN**, **γγ« Β· ζ₯ζ¬θͺ**, or **Haru Β· English**), optionally load any 3β12 s custom voice clip (`.wav`/`.m4a`/`.mp3`), and press **Start Conversation** (`βReturn`).
### Option B β Build from Source (Swift 6 / SwiftPM)
```bash
hf download typealias/Haru-4B-CoreAI --local-dir ./Haru-4B-CoreAI
cd Haru-4B-CoreAI/app/swift
# Build the macOS app + HaruCoreAIRuntime library + haru-bench CLI
swift build -c release
# Run the native SwiftUI app
.build/release/HaruCoreAI
# Or run the CLI benchmark against the downloaded weights
.build/release/haru-bench ../../weights
```
---
## Key Technical Optimizations
1. **Zero-Copy Pipelined `ComputeStream` Runtime (`HaruCoreAIRuntime`)**: Encodes `codec.encode_front` β `codec.encode_back` β `lm_step` β `codec.decode` over shared ping-pong `MTLBuffer`s on a single Core AI `ComputeStream`, eliminating inter-stage CPU-GPU stalls.
2. **6 Custom Metal 4 `TorchMetalKernel`s**:
- `gdn_conv_silu_step_8192`: fuses GatedDeltaNet conv-state shift + 4-tap depthwise conv (`fp32` accum) + `SiLU` + `q/k/v` split + GQA `repeat_interleave(2)` + transpose into 1 dispatch per layer (-432 ops/frame).
- `causal_depthwise_mixer_k7_tiled8` & `causal_depthwise_mixer_k7_t1`: 8-step register shift-register tiled depthwise conv (`256` threads/TG).
- `conv_transpose_overlap_add`: pre-permuted zero-transpose `ConvTranspose1d` + fused overlap-add & state update.
- `enc_stem_conv1d_k7` & `dec_head_conv1d_k7_clamp`: zero-copy stride-1 stem/head convolutions.
3. **Surgical Mixed-Precision & Algebraic Folding**:
- LM & tied embeddings in `bfloat16` compute + `uint8 per_block=128 minval` (avoiding fp16 overflow in layers 27β31 where activations peak at 182k, and avoiding 4-bit degradation identified in our 32-layer EN + JP/EN sensitivity scan).
- **Exact uncompressed `float32` `[PAD, EOP]` rows (20 KB)** preserved outside quantized embeddings, yielding **2.74x better** JP/EN turn-taking precision (`PAD/EOP MAE = 0.0531`).
- `MeanFlowHead` in `float16` (`u8_pb64` with 10-bit scale mantissa + precomputed scalar embeddings eliminating 8 linears / ~60 MB per frame).
- VibeVoice Codec v3 with load-time LayerScale (`gamma` / `ffn_gamma`) folding + hybrid quantization (`u8_pb64` only on bandwidth-bound Stages 5β6 enc / 0β1 dec; uncompressed `bf16` on compute-bound small stages).
4. **100% Pure-Swift Bilingual App**: Zero Python runtime dependency β includes a pure-Swift Qwen3.5 ByteLevel BPE tokenizer, incremental multi-byte UTF-8 Japanese/English `StreamDetokenizer`, exact DRY repetition penalty, Apple `AVAudioEngine` Voice Processing (AEC + NS) at 24 kHz, and built-in HF Hub downloader.
---
## Repository Layout
```
βββ README.md # Model card & usage guide
βββ LOG.md # Full engineering log, ablations & sensitivity sweeps
βββ weights/ # Ready-to-run Core AI bundle (5.48 GB)
β βββ haru_lm.aimodel/ # 4.72 GB multi-entrypoint LM + MeanFlowHead (`step` + `prefill`)
β βββ haru_codec.aimodel/ # 0.76 GB VibeVoice Codec v3 (`encode_full`, `encode_front`, `encode_back`, `decode`)
β βββ codec_meta.json
β βββ config.json
β βββ tokenizer.json
β βββ tokenizer_config.json
βββ app/
β βββ HaruCoreAI-macOS.zip # Ready-to-run signed macOS app bundle (3.1 MB)
β βββ swift/ # Swift 6 SwiftPM package (HaruCoreAIRuntime, HaruApp, HaruBench, Tests)
βββ export/ # Reproducible Python Core AI export pipeline (`coreai-torch`, `coreai-opt`, `coreai-models`)
βββ benchmarks/ # Baseline & optimization JSON metrics + EN/JP-EN sample outputs
```
## Credits
- Base model & architecture: [`higurashi-ai/Haru-4B`](https://huggingface.co/higurashi-ai/Haru-4B) (Apache 2.0)
- Core AI port, Metal 4 kernels, Swift 6 runtime, and macOS app: [`typealias`](https://huggingface.co/typealias)
|