roccoro 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
roccoro-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sergey Plis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include LICENSE README.md Makefile
2
+ recursive-include src/roccoro/csrc *.h *.cpp *.hip Makefile
3
+ recursive-include tests *.py
roccoro-0.1.1/Makefile ADDED
@@ -0,0 +1,19 @@
1
+ .PHONY: all engine bench verify install clean
2
+
3
+ all:
4
+ $(MAKE) -C src/roccoro/csrc all
5
+
6
+ engine:
7
+ $(MAKE) -C src/roccoro/csrc roccoro-engine
8
+
9
+ bench:
10
+ $(MAKE) -C src/roccoro/csrc kokoro_bench_hip
11
+
12
+ verify:
13
+ $(MAKE) -C src/roccoro/csrc verify_fixture
14
+
15
+ install:
16
+ $(MAKE) -C src/roccoro/csrc install
17
+
18
+ clean:
19
+ $(MAKE) -C src/roccoro/csrc clean
roccoro-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: roccoro
3
+ Version: 0.1.1
4
+ Summary: Native ROCm/HIP Kokoro-82M TTS engine (~245x real-time on AMD Strix Halo / RDNA3+ with zero PyTorch or ONNX Runtime at inference).
5
+ Author: Sergey Plis
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sergeyplis/roccoro
8
+ Project-URL: Repository, https://github.com/sergeyplis/roccoro
9
+ Project-URL: Issues, https://github.com/sergeyplis/roccoro/issues
10
+ Keywords: tts,kokoro,rocm,hip,amd,strix-halo,gfx1151,speech-synthesis
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy>=1.24
19
+ Requires-Dist: huggingface-hub>=0.24
20
+ Requires-Dist: tqdm>=4.66
21
+ Requires-Dist: misaki[en]>=0.9.4
22
+ Provides-Extra: export
23
+ Requires-Dist: kokoro>=0.9.4; extra == "export"
24
+ Requires-Dist: torch>=2.4; extra == "export"
25
+ Dynamic: license-file
26
+
27
+ # Roccoro
28
+
29
+ **Native ROCm/HIP Kokoro-82M TTS engine — ~245× real-time on AMD Strix Halo (`gfx1151`), ~830 MB VRAM/GTT, zero PyTorch or ONNX Runtime at inference.**
30
+
31
+ `roccoro` implements the complete [Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M) acoustic model (ALBERT/PL-BERT, 6 BiLSTMs, AdaINResBlk1d, ConvTranspose1d + fused Snake, 9-harmonic NSF sine source, 20-pt STFT/iSTFT) directly in standalone C++/HIP + rocBLAS — bypassing MIOpen completely and running at roofline on AMD RDNA3 / RDNA3.5 GPUs.
32
+
33
+ ---
34
+
35
+ ## Why Roccoro?
36
+
37
+ On AMD Strix Halo (`gfx1151` / Radeon 8060S), PyTorch ROCm's MIOpen backend stalls on Kokoro-82M at **< 1× real-time** due to workspace fallback issues, while CPU ONNX Runtime caps out around **~33× RT**.
38
+
39
+ `roccoro` replaces the ~4 GB `torch` + `onnxruntime` + `transformers` stack with a single ~500 KB HIP binary (`roccoro-engine`) plus lightweight `misaki` G2P:
40
+
41
+ | Backend (AMD Ryzen AI MAX+ 395 / Radeon 8060S `gfx1151`) | Speed (`× RT`) | GPU / GTT Memory | 9-Hour Audiobook | Inference Deps |
42
+ |---|---:|---:|---:|---|
43
+ | PyTorch ROCm (`cudnn=True` / MIOpen) | `< 1× RT` | ~3+ GB | > 9 hours | `torch`, `transformers`, `kokoro` |
44
+ | ONNX Runtime CPU FP32 (16 Zen 5 threads) | `33.4× RT` | 0 MB | ~16 min | `onnxruntime`, `kokoro` |
45
+ | **`roccoro` (native HIP, wave32 WMMA + persistent FP32 BiLSTM)** | **`245× RT` synth** (`222× RT` e2e w/ G2P+Opus) | **~830 MB** | **~2 min 14 sec** | **`numpy`, `misaki` (zero `torch`/`ort`)** |
46
+
47
+ ### Quality & Hardware Parity (verified vs PyTorch FP32 reference)
48
+ - **Exact FP32 durations**: `0/43` phoneme duration mismatches on reference fixture (`verify_fixture` — 19/19 layer checks pass).
49
+ - **Audio fidelity**: `cos = 0.99936` waveform correlation on deterministic fixture, `env_mel_cos = 0.9999986` / `env_mel_lsd_db = 0.0395 dB` vs ONNX CPU FP32 on an 82-minute chapter.
50
+ - **Roofline utilization**: Custom `gfx1151` wave32 FP16-WMMA implicit-GEMM Conv1d kernel (`__builtin_amdgcn_wmma_f32_16x16x16_f16_w32`, `BM=64, BN=128, BK=64`) hits **27.61 TFLOP/s** (**107.7%** of measured 25.64 TFLOP/s roof); single-launch persistent FP32 BiLSTM (`k_bilstm_persistent_h256`) slashes BiLSTM time 12–16× while preserving exact FP32 prosody.
51
+ - **Coexists safely with large LLMs**: Uses only **~830 MB** total GTT (199 MiB weights + 448 MiB arena + runtime), leaving room to run alongside an 85 GB resident `llama-server`.
52
+
53
+ ---
54
+
55
+ ## Quickstart (AMD Strix Halo / RDNA3 / RDNA3.5 + ROCm)
56
+
57
+ ### 1. Install `roccoro`
58
+ ```bash
59
+ pip install roccoro
60
+ ```
61
+
62
+ ### 2. Build the native HIP binary (auto-detects your GPU arch via `rocminfo`)
63
+ ```bash
64
+ roccoro build
65
+ # Or specify explicitly, e.g. Strix Halo (gfx1151) or RX 7900 XTX (gfx1100):
66
+ roccoro build --arch gfx1151
67
+ ```
68
+ This compiles `roccoro-engine` and installs it to `~/.cache/roccoro/roccoro-engine`.
69
+
70
+ ### 3. One-time weight export from `hexgrad/Kokoro-82M`
71
+ Only this one-time conversion step needs `torch` + `kokoro` (you can run it in a throwaway venv if you want your inference environment 100% torch-free):
72
+ ```bash
73
+ pip install "roccoro[export]"
74
+ roccoro export-weights
75
+ ```
76
+ This folds `weight_norm` and writes a compact ~199 MiB 64-byte-aligned `~/.cache/roccoro/kokoro_v1_fp32.khip`.
77
+
78
+ ### 4. Synthesize speech
79
+ ```bash
80
+ # CLI (24 kHz WAV)
81
+ roccoro "Hello from Strix Halo at two hundred forty five times real time!" -o hello.wav
82
+
83
+ # Synthesize a text file with voice blending
84
+ roccoro --text-file chapter.txt -o chapter.wav --voice af_heart,af_bella --speed 1.0
85
+
86
+ # Check device, binary, and weights status
87
+ roccoro info
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Python API
93
+
94
+ ```python
95
+ import roccoro
96
+
97
+ with roccoro.KokoroEngine(voice="af_heart") as engine:
98
+ # Single call -> 24 kHz float32 NumPy waveform
99
+ audio = engine.synthesize("Hello from Roccoro on Strix Halo!", speed=1.0)
100
+ roccoro.write_wav("hello.wav", audio)
101
+
102
+ # Or write directly to WAV
103
+ out_path, duration_s = engine.synthesize_to_file("Fast local TTS.", "fast.wav")
104
+
105
+ # Low-level pipelined API (used by mumblebee for 222x RT full-book synthesis)
106
+ phonemes = engine.phonemize_batch("Paragraph one.\n\nParagraph two.")
107
+ chunks = engine.synthesize_phonemes(phonemes, model_speed=1.0, show_progress=True)
108
+ ```
109
+
110
+ ---
111
+
112
+ ## Standalone C++/HIP Binary & Benchmarks (Zero Python Required)
113
+
114
+ If you clone the repo directly:
115
+
116
+ ```bash
117
+ git clone https://github.com/sergeyplis/roccoro.git
118
+ cd roccoro
119
+ make install # builds roccoro-engine + installs to ~/.cache/roccoro/roccoro-engine
120
+ make verify bench # builds verify_fixture and kokoro_bench_hip
121
+ ```
122
+
123
+ ### Layer-by-layer Numerical Verification
124
+ ```bash
125
+ roccoro export-weights --out kokoro_v1_fp32.khip --dump-fixture fixture_short.khip
126
+ ./src/roccoro/csrc/verify_fixture kokoro_v1_fp32.khip fixture_short.khip
127
+ ```
128
+
129
+ ### Binary Pipe Protocol (`roccoro-engine`)
130
+ `roccoro-engine` can be driven from any language (C++, Rust, Go, Node, Python) over stdin/stdout without Python:
131
+ 1. Launch: `roccoro-engine --weights kokoro_v1_fp32.khip --arena-mb 448 --max-batch 32`
132
+ 2. Engine writes 4-byte ready magic `0x4B484F4B` (`"KHOK"`).
133
+ 3. Client sends request frames: `<magic=0x4B485251, num_chunks, speed_f32, max_batch>` followed by `num_chunks` records of `<token_len_u32, seed_u64, style_256xf32, tokens_lenxi32>`.
134
+ 4. Engine replies: `<magic=0x4B485250, num_chunks>` followed by `num_chunks` records of `<n_samples_u32, pcm_f32[n_samples]>`.
135
+ 5. Send `num_chunks = 0` (or close stdin) to exit cleanly.
136
+
137
+ ---
138
+
139
+ ## Configuration & Environment Variables
140
+
141
+ | Variable | Purpose |
142
+ |---|---|
143
+ | `ROCCORO_BIN` | Explicit path to `roccoro-engine` binary |
144
+ | `ROCCORO_WEIGHTS` | Explicit path to `kokoro_v1_fp32.khip` weights |
145
+ | `ROCCORO_CACHE_DIR` | Override cache dir (default: `$XDG_CACHE_HOME/roccoro` or `~/.cache/roccoro`) |
146
+ | `ROCM_PATH` | ROCm root used by `roccoro build` (default: `/opt/rocm`) |
147
+
148
+ ## GPU Compatibility
149
+ - **Tested & tuned**: AMD Radeon 8060S / Strix Halo (`gfx1151`, ROCm 7.2.2).
150
+ - **Compatible ISA**: RDNA3 / RDNA3.5 GPUs supporting wave32 FP16 WMMA (`gfx1100`, `gfx1101`, `gfx1102`, `gfx1103`, `gfx1150`, `gfx1151`). Build with `roccoro build --arch <gfxXXXX>`.
151
+
152
+ ## Credits & License
153
+ - Model architecture & weights: [Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M) (Apache 2.0) and [Misaki](https://github.com/hexgrad/misaki) G2P.
154
+ - Extracted from [mumblebee](https://github.com/sergeyplis/mumblebee) and inspired by custom HIP roofline kernel engineering in [brainchop-core](https://github.com/neuroneural/brainchop-core).
155
+ - Licensed under the [MIT License](LICENSE).
@@ -0,0 +1,129 @@
1
+ # Roccoro
2
+
3
+ **Native ROCm/HIP Kokoro-82M TTS engine — ~245× real-time on AMD Strix Halo (`gfx1151`), ~830 MB VRAM/GTT, zero PyTorch or ONNX Runtime at inference.**
4
+
5
+ `roccoro` implements the complete [Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M) acoustic model (ALBERT/PL-BERT, 6 BiLSTMs, AdaINResBlk1d, ConvTranspose1d + fused Snake, 9-harmonic NSF sine source, 20-pt STFT/iSTFT) directly in standalone C++/HIP + rocBLAS — bypassing MIOpen completely and running at roofline on AMD RDNA3 / RDNA3.5 GPUs.
6
+
7
+ ---
8
+
9
+ ## Why Roccoro?
10
+
11
+ On AMD Strix Halo (`gfx1151` / Radeon 8060S), PyTorch ROCm's MIOpen backend stalls on Kokoro-82M at **< 1× real-time** due to workspace fallback issues, while CPU ONNX Runtime caps out around **~33× RT**.
12
+
13
+ `roccoro` replaces the ~4 GB `torch` + `onnxruntime` + `transformers` stack with a single ~500 KB HIP binary (`roccoro-engine`) plus lightweight `misaki` G2P:
14
+
15
+ | Backend (AMD Ryzen AI MAX+ 395 / Radeon 8060S `gfx1151`) | Speed (`× RT`) | GPU / GTT Memory | 9-Hour Audiobook | Inference Deps |
16
+ |---|---:|---:|---:|---|
17
+ | PyTorch ROCm (`cudnn=True` / MIOpen) | `< 1× RT` | ~3+ GB | > 9 hours | `torch`, `transformers`, `kokoro` |
18
+ | ONNX Runtime CPU FP32 (16 Zen 5 threads) | `33.4× RT` | 0 MB | ~16 min | `onnxruntime`, `kokoro` |
19
+ | **`roccoro` (native HIP, wave32 WMMA + persistent FP32 BiLSTM)** | **`245× RT` synth** (`222× RT` e2e w/ G2P+Opus) | **~830 MB** | **~2 min 14 sec** | **`numpy`, `misaki` (zero `torch`/`ort`)** |
20
+
21
+ ### Quality & Hardware Parity (verified vs PyTorch FP32 reference)
22
+ - **Exact FP32 durations**: `0/43` phoneme duration mismatches on reference fixture (`verify_fixture` — 19/19 layer checks pass).
23
+ - **Audio fidelity**: `cos = 0.99936` waveform correlation on deterministic fixture, `env_mel_cos = 0.9999986` / `env_mel_lsd_db = 0.0395 dB` vs ONNX CPU FP32 on an 82-minute chapter.
24
+ - **Roofline utilization**: Custom `gfx1151` wave32 FP16-WMMA implicit-GEMM Conv1d kernel (`__builtin_amdgcn_wmma_f32_16x16x16_f16_w32`, `BM=64, BN=128, BK=64`) hits **27.61 TFLOP/s** (**107.7%** of measured 25.64 TFLOP/s roof); single-launch persistent FP32 BiLSTM (`k_bilstm_persistent_h256`) slashes BiLSTM time 12–16× while preserving exact FP32 prosody.
25
+ - **Coexists safely with large LLMs**: Uses only **~830 MB** total GTT (199 MiB weights + 448 MiB arena + runtime), leaving room to run alongside an 85 GB resident `llama-server`.
26
+
27
+ ---
28
+
29
+ ## Quickstart (AMD Strix Halo / RDNA3 / RDNA3.5 + ROCm)
30
+
31
+ ### 1. Install `roccoro`
32
+ ```bash
33
+ pip install roccoro
34
+ ```
35
+
36
+ ### 2. Build the native HIP binary (auto-detects your GPU arch via `rocminfo`)
37
+ ```bash
38
+ roccoro build
39
+ # Or specify explicitly, e.g. Strix Halo (gfx1151) or RX 7900 XTX (gfx1100):
40
+ roccoro build --arch gfx1151
41
+ ```
42
+ This compiles `roccoro-engine` and installs it to `~/.cache/roccoro/roccoro-engine`.
43
+
44
+ ### 3. One-time weight export from `hexgrad/Kokoro-82M`
45
+ Only this one-time conversion step needs `torch` + `kokoro` (you can run it in a throwaway venv if you want your inference environment 100% torch-free):
46
+ ```bash
47
+ pip install "roccoro[export]"
48
+ roccoro export-weights
49
+ ```
50
+ This folds `weight_norm` and writes a compact ~199 MiB 64-byte-aligned `~/.cache/roccoro/kokoro_v1_fp32.khip`.
51
+
52
+ ### 4. Synthesize speech
53
+ ```bash
54
+ # CLI (24 kHz WAV)
55
+ roccoro "Hello from Strix Halo at two hundred forty five times real time!" -o hello.wav
56
+
57
+ # Synthesize a text file with voice blending
58
+ roccoro --text-file chapter.txt -o chapter.wav --voice af_heart,af_bella --speed 1.0
59
+
60
+ # Check device, binary, and weights status
61
+ roccoro info
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Python API
67
+
68
+ ```python
69
+ import roccoro
70
+
71
+ with roccoro.KokoroEngine(voice="af_heart") as engine:
72
+ # Single call -> 24 kHz float32 NumPy waveform
73
+ audio = engine.synthesize("Hello from Roccoro on Strix Halo!", speed=1.0)
74
+ roccoro.write_wav("hello.wav", audio)
75
+
76
+ # Or write directly to WAV
77
+ out_path, duration_s = engine.synthesize_to_file("Fast local TTS.", "fast.wav")
78
+
79
+ # Low-level pipelined API (used by mumblebee for 222x RT full-book synthesis)
80
+ phonemes = engine.phonemize_batch("Paragraph one.\n\nParagraph two.")
81
+ chunks = engine.synthesize_phonemes(phonemes, model_speed=1.0, show_progress=True)
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Standalone C++/HIP Binary & Benchmarks (Zero Python Required)
87
+
88
+ If you clone the repo directly:
89
+
90
+ ```bash
91
+ git clone https://github.com/sergeyplis/roccoro.git
92
+ cd roccoro
93
+ make install # builds roccoro-engine + installs to ~/.cache/roccoro/roccoro-engine
94
+ make verify bench # builds verify_fixture and kokoro_bench_hip
95
+ ```
96
+
97
+ ### Layer-by-layer Numerical Verification
98
+ ```bash
99
+ roccoro export-weights --out kokoro_v1_fp32.khip --dump-fixture fixture_short.khip
100
+ ./src/roccoro/csrc/verify_fixture kokoro_v1_fp32.khip fixture_short.khip
101
+ ```
102
+
103
+ ### Binary Pipe Protocol (`roccoro-engine`)
104
+ `roccoro-engine` can be driven from any language (C++, Rust, Go, Node, Python) over stdin/stdout without Python:
105
+ 1. Launch: `roccoro-engine --weights kokoro_v1_fp32.khip --arena-mb 448 --max-batch 32`
106
+ 2. Engine writes 4-byte ready magic `0x4B484F4B` (`"KHOK"`).
107
+ 3. Client sends request frames: `<magic=0x4B485251, num_chunks, speed_f32, max_batch>` followed by `num_chunks` records of `<token_len_u32, seed_u64, style_256xf32, tokens_lenxi32>`.
108
+ 4. Engine replies: `<magic=0x4B485250, num_chunks>` followed by `num_chunks` records of `<n_samples_u32, pcm_f32[n_samples]>`.
109
+ 5. Send `num_chunks = 0` (or close stdin) to exit cleanly.
110
+
111
+ ---
112
+
113
+ ## Configuration & Environment Variables
114
+
115
+ | Variable | Purpose |
116
+ |---|---|
117
+ | `ROCCORO_BIN` | Explicit path to `roccoro-engine` binary |
118
+ | `ROCCORO_WEIGHTS` | Explicit path to `kokoro_v1_fp32.khip` weights |
119
+ | `ROCCORO_CACHE_DIR` | Override cache dir (default: `$XDG_CACHE_HOME/roccoro` or `~/.cache/roccoro`) |
120
+ | `ROCM_PATH` | ROCm root used by `roccoro build` (default: `/opt/rocm`) |
121
+
122
+ ## GPU Compatibility
123
+ - **Tested & tuned**: AMD Radeon 8060S / Strix Halo (`gfx1151`, ROCm 7.2.2).
124
+ - **Compatible ISA**: RDNA3 / RDNA3.5 GPUs supporting wave32 FP16 WMMA (`gfx1100`, `gfx1101`, `gfx1102`, `gfx1103`, `gfx1150`, `gfx1151`). Build with `roccoro build --arch <gfxXXXX>`.
125
+
126
+ ## Credits & License
127
+ - Model architecture & weights: [Kokoro-82M](https://huggingface.co/hexgrad/Kokoro-82M) (Apache 2.0) and [Misaki](https://github.com/hexgrad/misaki) G2P.
128
+ - Extracted from [mumblebee](https://github.com/sergeyplis/mumblebee) and inspired by custom HIP roofline kernel engineering in [brainchop-core](https://github.com/neuroneural/brainchop-core).
129
+ - Licensed under the [MIT License](LICENSE).
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "roccoro"
7
+ version = "0.1.1"
8
+ description = "Native ROCm/HIP Kokoro-82M TTS engine (~245x real-time on AMD Strix Halo / RDNA3+ with zero PyTorch or ONNX Runtime at inference)."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Sergey Plis" }]
13
+ requires-python = ">=3.10"
14
+ keywords = ["tts", "kokoro", "rocm", "hip", "amd", "strix-halo", "gfx1151", "speech-synthesis"]
15
+ classifiers = [
16
+ "Operating System :: POSIX :: Linux",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: Multimedia :: Sound/Audio :: Speech",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ ]
21
+ dependencies = [
22
+ "numpy>=1.24",
23
+ "huggingface-hub>=0.24",
24
+ "tqdm>=4.66",
25
+ "misaki[en]>=0.9.4",
26
+ ]
27
+
28
+ [project.optional-dependencies]
29
+ export = [
30
+ "kokoro>=0.9.4",
31
+ "torch>=2.4",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/sergeyplis/roccoro"
36
+ Repository = "https://github.com/sergeyplis/roccoro"
37
+ Issues = "https://github.com/sergeyplis/roccoro/issues"
38
+
39
+ [project.scripts]
40
+ roccoro = "roccoro.cli:main"
41
+
42
+ [tool.setuptools.packages.find]
43
+ where = ["src"]
44
+
45
+ [tool.setuptools.package-data]
46
+ roccoro = ["csrc/*.h", "csrc/*.cpp", "csrc/*.hip", "csrc/Makefile"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,49 @@
1
+ """Roccoro — Native ROCm/HIP Kokoro-82M TTS engine."""
2
+
3
+ from .build import build_engine, detect_gpu_arch
4
+ from .engine import (
5
+ BUILTIN_KOKORO_VOCAB,
6
+ KOKORO_REPO,
7
+ MAGIC_READY,
8
+ MAGIC_REQ,
9
+ MAGIC_RESP,
10
+ SAMPLE_RATE,
11
+ KokoroEngine,
12
+ MisakiG2P,
13
+ cache_dir,
14
+ decode_response_frame,
15
+ encode_request_frame,
16
+ find_engine_binary,
17
+ find_weights,
18
+ is_available,
19
+ load_kokoro_vocab,
20
+ load_voice_pack,
21
+ phonemes_to_token_ids,
22
+ write_wav,
23
+ )
24
+
25
+ __version__ = "0.1.1"
26
+
27
+ __all__ = [
28
+ "__version__",
29
+ "BUILTIN_KOKORO_VOCAB",
30
+ "KOKORO_REPO",
31
+ "MAGIC_READY",
32
+ "MAGIC_REQ",
33
+ "MAGIC_RESP",
34
+ "SAMPLE_RATE",
35
+ "KokoroEngine",
36
+ "MisakiG2P",
37
+ "build_engine",
38
+ "cache_dir",
39
+ "decode_response_frame",
40
+ "detect_gpu_arch",
41
+ "encode_request_frame",
42
+ "find_engine_binary",
43
+ "find_weights",
44
+ "is_available",
45
+ "load_kokoro_vocab",
46
+ "load_voice_pack",
47
+ "phonemes_to_token_ids",
48
+ "write_wav",
49
+ ]
@@ -0,0 +1,6 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ if __name__ == "__main__":
6
+ sys.exit(main())
@@ -0,0 +1,74 @@
1
+ """Build helper for compiling the native ROCm/HIP `roccoro-engine` binary."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ import re
8
+ import shutil
9
+ import subprocess
10
+
11
+ from .engine import _package_csrc_dir, cache_dir
12
+
13
+
14
+ def detect_gpu_arch(rocm_path: str | Path = "/opt/rocm") -> str:
15
+ """Auto-detect the active AMD GPU ISA (e.g. `gfx1151`, `gfx1100`) via `rocminfo`."""
16
+ rocminfo = Path(rocm_path) / "bin" / "rocminfo"
17
+ cmd = str(rocminfo) if rocminfo.is_file() else shutil.which("rocminfo")
18
+ if cmd:
19
+ try:
20
+ out = subprocess.check_output([cmd], text=True, stderr=subprocess.DEVNULL, timeout=10)
21
+ for match in re.findall(r"\bgfx[0-9a-f]+\b", out):
22
+ if match != "gfx000":
23
+ return match
24
+ except Exception:
25
+ pass
26
+ return "gfx1151"
27
+
28
+
29
+ def build_engine(
30
+ arch: str | None = None,
31
+ rocm_path: str | Path | None = None,
32
+ install_dir: str | Path | None = None,
33
+ targets: tuple[str, ...] = ("roccoro-engine",),
34
+ ) -> Path:
35
+ """Compile the HIP C++ sources into a writable cache build dir and install `roccoro-engine`."""
36
+ rocm = Path(rocm_path or os.environ.get("ROCM_PATH", "/opt/rocm"))
37
+ hipcc = rocm / "bin" / "hipcc"
38
+ if not hipcc.is_file():
39
+ found = shutil.which("hipcc")
40
+ if not found:
41
+ raise FileNotFoundError(
42
+ f"hipcc not found at {hipcc} or in PATH. Install ROCm or set ROCM_PATH."
43
+ )
44
+ hipcc = Path(found)
45
+ rocm = hipcc.parent.parent
46
+
47
+ gpu_arch = arch or detect_gpu_arch(rocm)
48
+ csrc = _package_csrc_dir()
49
+ if not (csrc / "kokoro_kernels.hip").is_file():
50
+ raise FileNotFoundError(f"Missing C++/HIP sources under {csrc}")
51
+
52
+ dest_dir = Path(install_dir).expanduser() if install_dir else cache_dir()
53
+ build_dir = dest_dir / "build"
54
+ build_dir.mkdir(parents=True, exist_ok=True)
55
+ dest_dir.mkdir(parents=True, exist_ok=True)
56
+
57
+ for src_file in csrc.iterdir():
58
+ if src_file.is_file() and (
59
+ src_file.name == "Makefile" or src_file.suffix in (".h", ".cpp", ".hip")
60
+ ):
61
+ shutil.copy2(src_file, build_dir / src_file.name)
62
+
63
+ cmd = [
64
+ "make",
65
+ "-C", str(build_dir),
66
+ f"ROCM_PATH={rocm}",
67
+ f"HIPCC={hipcc}",
68
+ f"ARCH={gpu_arch}",
69
+ f"INSTALL_DIR={dest_dir}",
70
+ *targets,
71
+ "install",
72
+ ]
73
+ subprocess.run(cmd, check=True)
74
+ return dest_dir / "roccoro-engine"
@@ -0,0 +1,155 @@
1
+ """Command-line interface for Roccoro (native ROCm/HIP Kokoro-82M TTS)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ from pathlib import Path
7
+ import sys
8
+ import time
9
+
10
+ from . import __version__
11
+ from .build import build_engine, detect_gpu_arch
12
+ from .engine import (
13
+ KokoroEngine,
14
+ cache_dir,
15
+ find_engine_binary,
16
+ find_weights,
17
+ is_available,
18
+ )
19
+ from .export import export_weights
20
+
21
+
22
+ def _cmd_info() -> int:
23
+ print(f"roccoro {__version__}")
24
+ print(f" /dev/kfd : {'present' if Path('/dev/kfd').exists() else 'missing'}")
25
+ print(f" GPU arch : {detect_gpu_arch()}")
26
+ print(f" cache dir : {cache_dir()}")
27
+ print(f" engine binary: {find_engine_binary() or 'NOT FOUND (run `roccoro build`)'}")
28
+ print(f" weights : {find_weights() or 'NOT FOUND (run `roccoro export-weights`)'}")
29
+ print(f" ready : {is_available()}")
30
+ return 0
31
+
32
+
33
+ def _cmd_build(argv: list[str]) -> int:
34
+ ap = argparse.ArgumentParser(prog="roccoro build", description="Compile the native ROCm/HIP engine binary.")
35
+ ap.add_argument("--arch", default=None, help="Target AMD GPU ISA (default: auto-detect via rocminfo, else gfx1151)")
36
+ ap.add_argument("--rocm-path", default=None, help="ROCm installation root (default: $ROCM_PATH or /opt/rocm)")
37
+ ap.add_argument("--install-dir", default=None, help="Where to install roccoro-engine (default: ~/.cache/roccoro)")
38
+ ap.add_argument("--all", action="store_true", help="Also build verify_fixture and kokoro_bench_hip")
39
+ args = ap.parse_args(argv)
40
+ targets = ("roccoro-engine", "verify_fixture", "kokoro_bench_hip") if args.all else ("roccoro-engine",)
41
+ out = build_engine(arch=args.arch, rocm_path=args.rocm_path, install_dir=args.install_dir, targets=targets)
42
+ print(f"Built and installed: {out}")
43
+ return 0
44
+
45
+
46
+ def _cmd_export(argv: list[str]) -> int:
47
+ ap = argparse.ArgumentParser(
48
+ prog="roccoro export-weights",
49
+ description="One-time export of Kokoro-82M FP32 folded weights into `.khip` format.",
50
+ )
51
+ ap.add_argument("--out", type=Path, default=None, help="Output .khip path (default: ~/.cache/roccoro/kokoro_v1_fp32.khip)")
52
+ ap.add_argument("--repo-id", default="hexgrad/Kokoro-82M", help="Hugging Face repo ID")
53
+ ap.add_argument("--voices-dir", type=Path, default=None, help="Optional directory to also export raw .bin voice packs")
54
+ ap.add_argument("--voices", nargs="*", default=["af_heart"], help="Voices to export with --voices-dir")
55
+ ap.add_argument("--dump-fixture", type=Path, default=None, help="Optional verification fixture .khip output path")
56
+ args = ap.parse_args(argv)
57
+ export_weights(
58
+ out_path=args.out,
59
+ repo_id=args.repo_id,
60
+ voices_dir=args.voices_dir,
61
+ voices=args.voices,
62
+ dump_fixture=args.dump_fixture,
63
+ )
64
+ return 0
65
+
66
+
67
+ def _cmd_synth(argv: list[str]) -> int:
68
+ ap = argparse.ArgumentParser(
69
+ prog="roccoro",
70
+ description="Native ROCm/HIP Kokoro-82M TTS (~245x RT on AMD Strix Halo / RDNA3+).",
71
+ )
72
+ ap.add_argument("text", nargs="?", help="Text to synthesize (or pass --text-file / pipe stdin)")
73
+ ap.add_argument("-f", "--text-file", type=Path, help="Read input text from a UTF-8 file")
74
+ ap.add_argument("-o", "--output", type=Path, default=Path("out.wav"), help="Output 24 kHz WAV path (default: out.wav)")
75
+ ap.add_argument("-v", "--voice", default="af_heart", help="Voice name, file path, or comma-blended voices (default: af_heart)")
76
+ ap.add_argument("--lang", default="a", help="Language code: 'a' (US English) or 'b' (UK English)")
77
+ ap.add_argument("--speed", type=float, default=1.0, help="Speech speed multiplier (default: 1.0)")
78
+ ap.add_argument("--pause", type=float, default=0.0, help="Optional silence gap in seconds between chunks")
79
+ ap.add_argument("--arena-mb", type=int, default=448, help="GPU scratch arena size in MiB (default: 448)")
80
+ ap.add_argument("--max-batch", type=int, default=32, help="Max dynamic batch size (default: 32)")
81
+ ap.add_argument("--binary", type=Path, default=None, help="Path to roccoro-engine binary")
82
+ ap.add_argument("--weights", type=Path, default=None, help="Path to kokoro_v1_fp32.khip weights")
83
+ ap.add_argument("-q", "--quiet", action="store_true", help="Disable progress bar")
84
+ args = ap.parse_args(argv)
85
+
86
+ if args.text_file:
87
+ text = args.text_file.read_text(encoding="utf-8")
88
+ elif args.text:
89
+ text = args.text
90
+ elif not sys.stdin.isatty():
91
+ text = sys.stdin.read()
92
+ else:
93
+ ap.error("Provide text as an argument, --text-file, or stdin (or run `roccoro --help`).")
94
+ return 2
95
+
96
+ t0 = time.perf_counter()
97
+ with KokoroEngine(
98
+ voice=args.voice,
99
+ lang_code=args.lang,
100
+ binary_path=args.binary,
101
+ weights_path=args.weights,
102
+ arena_mb=args.arena_mb,
103
+ max_batch=args.max_batch,
104
+ ) as engine:
105
+ t_synth = time.perf_counter()
106
+ out_path, audio_s = engine.synthesize_to_file(
107
+ text,
108
+ args.output,
109
+ speed=args.speed,
110
+ pause_s=args.pause,
111
+ show_progress=not args.quiet,
112
+ )
113
+ synth_s = max(time.perf_counter() - t_synth, 1e-6)
114
+ total_s = max(time.perf_counter() - t0, 1e-6)
115
+ print(
116
+ f"Saved {out_path} ({audio_s:.2f}s audio in {synth_s:.2f}s synth / {total_s:.2f}s total, "
117
+ f"{audio_s / synth_s:.1f}x RT)"
118
+ )
119
+ return 0
120
+
121
+
122
+ def main(argv: list[str] | None = None) -> int:
123
+ args = list(sys.argv[1:] if argv is None else argv)
124
+ if not args or args[0] in ("-h", "--help"):
125
+ print(
126
+ "usage: roccoro <text | subcommand> [options]\n\n"
127
+ "Native ROCm/HIP Kokoro-82M TTS engine (~245x RT on AMD Strix Halo / RDNA3+).\n\n"
128
+ "subcommands:\n"
129
+ " build Compile and install the native HIP `roccoro-engine` binary\n"
130
+ " export-weights One-time export of Kokoro-82M weights into `.khip` format\n"
131
+ " info Show ROCm device, binary, weights, and cache status\n\n"
132
+ "synthesis:\n"
133
+ " roccoro \"Hello from Strix Halo!\" -o hello.wav [--voice af_heart]\n"
134
+ " roccoro --text-file chapter.txt -o chapter.wav\n\n"
135
+ "options:\n"
136
+ " -h, --help Show this help message and exit\n"
137
+ " -V, --version Show program version and exit"
138
+ )
139
+ return 0
140
+ if args[0] in ("-V", "--version"):
141
+ print(f"roccoro {__version__}")
142
+ return 0
143
+
144
+ cmd = args[0]
145
+ if cmd == "info":
146
+ return _cmd_info()
147
+ if cmd == "build":
148
+ return _cmd_build(args[1:])
149
+ if cmd == "export-weights":
150
+ return _cmd_export(args[1:])
151
+ return _cmd_synth(args)
152
+
153
+
154
+ if __name__ == "__main__":
155
+ sys.exit(main())