From 94ccb1019f0995c4168d551148bbae44f6b49dad Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Fri, 6 Nov 2026 05:37:34 -0500 Subject: [PATCH 1/5] chore: move llama.cpp to v0.9.0 (cd959bae) --- third_party/llama.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/llama.cpp b/third_party/llama.cpp index 8642541b..cd959bae 160000 --- a/third_party/llama.cpp +++ b/third_party/llama.cpp @@ -1 +1 @@ -Subproject commit 8642541b255bfb5dc39cd351a178be09013a55d6 +Subproject commit cd959bae99ff4bed22bef2604f45241c09bbb8c8 From 5c8042f56deff94eccedb99d69739275b48bdf78 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Fri, 6 Nov 2026 05:47:29 -0500 Subject: [PATCH 2/5] Qualify llama.cpp v0.9.0 and audit its CPU ISA source pair Add v0.9.0 rows to every validate_wrapper.yml lane and admit the reviewed v0.9.0 ggml/src + KleidiAI v1.32.0 pair with the v0.8.0 function set. Document the wrapper, carried-patch and consumer ABI delta. --- .github/workflows/validate_wrapper.yml | 42 +++++------ AGENTS.md | 3 + docs/platform_backend_strategy.md | 4 +- docs/v090_android_isa_qualification.md | 98 ++++++++++++++++++++++++++ docs/v090_qualification.md | 77 ++++++++++++++++++++ tests/test_android_cpu_isa.py | 6 +- tests/test_ci_scope.py | 24 ++++--- tools/validate_android_cpu_isa.py | 13 +++- 8 files changed, 231 insertions(+), 36 deletions(-) create mode 100644 docs/v090_android_isa_qualification.md create mode 100644 docs/v090_qualification.md diff --git a/.github/workflows/validate_wrapper.yml b/.github/workflows/validate_wrapper.yml index 70d679f5..27b61a22 100644 --- a/.github/workflows/validate_wrapper.yml +++ b/.github/workflows/validate_wrapper.yml @@ -21,6 +21,8 @@ env: LLAMADART_V070_QUALIFICATION_SHA: 620d2225cc436ab0b001e3200e590e3b286ef9ab # Stable v0.8.0, the 0.17.1 runtime upgrade candidate (llamadart-native#112). LLAMADART_V080_QUALIFICATION_SHA: 8642541b255bfb5dc39cd351a178be09013a55d6 + # Stable v0.9.0, the next runtime candidate and the pinned upstream. + LLAMADART_V090_QUALIFICATION_SHA: cd959bae99ff4bed22bef2604f45241c09bbb8c8 jobs: changes: @@ -47,7 +49,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [post-v0.4.0, v0.4.1, v0.5.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [post-v0.4.0, v0.4.1, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -55,7 +57,7 @@ jobs: submodules: recursive - name: Select candidate upstream env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || matrix.upstream == 'v0.4.1' && env.LLAMADART_V041_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || matrix.upstream == 'v0.4.1' && env.LLAMADART_V041_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -114,7 +116,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, v0.5.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -123,7 +125,7 @@ jobs: - name: Select candidate upstream if: matrix.upstream != 'pinned' env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -204,7 +206,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [post-v0.4.0, v0.4.1, v0.5.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [post-v0.4.0, v0.4.1, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -212,7 +214,7 @@ jobs: submodules: recursive - name: Select candidate upstream env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || matrix.upstream == 'v0.4.1' && env.LLAMADART_V041_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || matrix.upstream == 'v0.4.1' && env.LLAMADART_V041_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -253,7 +255,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, post-v0.4.0, v0.5.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, post-v0.4.0, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -265,7 +267,7 @@ jobs: arch: arm64 - name: Select candidate upstream env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} if: matrix.upstream != 'pinned' shell: bash run: | @@ -297,7 +299,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, v0.5.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -311,7 +313,7 @@ jobs: if: matrix.upstream != 'pinned' shell: bash env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -352,7 +354,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, v0.7.0, v0.8.0] + upstream: [pinned, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -362,7 +364,7 @@ jobs: if: matrix.upstream != 'pinned' shell: bash env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -405,7 +407,7 @@ jobs: fail-fast: false matrix: arch: [x64, arm64] - upstream: [pinned, post-v0.4.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, post-v0.4.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -414,7 +416,7 @@ jobs: - name: Select candidate upstream if: matrix.upstream != 'pinned' env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -477,7 +479,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, post-v0.4.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, post-v0.4.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -486,7 +488,7 @@ jobs: - name: Select the candidate upstream release if: matrix.upstream != 'pinned' env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -597,7 +599,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, post-v0.4.0, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, post-v0.4.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0] steps: - uses: actions/checkout@v7 with: @@ -607,7 +609,7 @@ jobs: if: matrix.upstream != 'pinned' shell: bash env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || matrix.upstream == 'v0.6.0' && env.LLAMADART_V060_QUALIFICATION_SHA || matrix.upstream == 'v0.5.0' && env.LLAMADART_V050_QUALIFICATION_SHA || env.LLAMADART_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" @@ -675,7 +677,7 @@ jobs: strategy: fail-fast: false matrix: - upstream: [pinned, v0.6.0, v0.7.0, v0.8.0] + upstream: [pinned, v0.6.0, v0.7.0, v0.8.0, v0.9.0] build: [release, address-sanitizer] include: # The shipped configuration: Release with link-time optimization. @@ -702,7 +704,7 @@ jobs: - name: Select candidate upstream if: matrix.upstream != 'pinned' env: - LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || env.LLAMADART_V060_QUALIFICATION_SHA }} + LLAMADART_QUALIFICATION_SHA: ${{ matrix.upstream == 'v0.9.0' && env.LLAMADART_V090_QUALIFICATION_SHA || matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA || matrix.upstream == 'v0.7.0' && env.LLAMADART_V070_QUALIFICATION_SHA || env.LLAMADART_V060_QUALIFICATION_SHA }} run: | git -C third_party/llama.cpp fetch --depth=1 origin "$LLAMADART_QUALIFICATION_SHA" git -C third_party/llama.cpp checkout --detach "$LLAMADART_QUALIFICATION_SHA" diff --git a/AGENTS.md b/AGENTS.md index 1fb5b3c5..129120ee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,6 +56,9 @@ See `docs/v080_qualification.md` for the v0.8.0 candidate, its wrapper gate, carried-patch status and consumer ABI delta. See `docs/v080_android_isa_qualification.md` for the v0.8.0/KleidiAI v1.32.0 source pair, its SVE I8MM-gated Q8 kernels and remaining gates. +See `docs/v090_qualification.md` for the v0.9.0 candidate, retired patch 0004 +and consumer ABI delta, and `docs/v090_android_isa_qualification.md` for its +source pair and ggml SVE256 repack paths. See `docs/v080_1_wrapper_rebuild.md` for the `v0.8.0-1` Metal kernel patch and the OS floor check `metal_os_floor.yml`, which runs on `macos-15`, `macos-26` and the oldest iOS simulator because ggml compiles Metal source on the user's diff --git a/docs/platform_backend_strategy.md b/docs/platform_backend_strategy.md index f11557f3..6ed2f084 100644 --- a/docs/platform_backend_strategy.md +++ b/docs/platform_backend_strategy.md @@ -132,8 +132,8 @@ qualified releases as separate regression inputs. which KleidiAI compiles with `-march=armv8.2-a+sve+sve2`. The baseline ISA audit reads `.dynsym` and cannot attribute a local routine, so it fails. GCC 13 emits no SVE in that file. ggml reaches the routine only through - `q4_k_rhs_pack`, whose one table entry requires `SME2 | FP16` (v0.7.0 and - v0.8.0; KleidiAI v1.31.0 and v1.32.0 have the same file). That gate does + `q4_k_rhs_pack`, whose one table entry requires `SME2 | FP16` (v0.7.0 to + v0.9.0; KleidiAI v1.31.0 and v1.32.0 have the same file). That gate does not make the SVE safe: the routine runs outside streaming mode, and SME2 does not imply SVE there. On an Apple M4 Max (SME2, no FEAT_SVE) this instruction raises SIGILL outside streaming mode and runs inside it. diff --git a/docs/v090_android_isa_qualification.md b/docs/v090_android_isa_qualification.md new file mode 100644 index 00000000..87860c93 --- /dev/null +++ b/docs/v090_android_isa_qualification.md @@ -0,0 +1,98 @@ +# v0.9.0 Android CPU ISA qualification + +Candidate upstream is stable v0.9.0 +`cd959bae99ff4bed22bef2604f45241c09bbb8c8`, compared with audited v0.8.0 +`8642541b255bfb5dc39cd351a178be09013a55d6`. KleidiAI stays at v1.32.0 and no +dispatch input changes, so v0.9.0 grants exactly the v0.8.0 function set. Its +complete source subtree pair is: + +- ggml/src: `fead7601e3b35651ee62764c76f28b50ee564160b543ff79be6fcc81837216c4` +- kai: `fd5b9ca98d07b81671eca377c258da74e72173f92f3cab0acdf6c17ab870bd9d` (v0.8.0's) + +The 2026-11-05 automatic stable dispatch of v0.9.0 +([run 42016701448](https://github.com/leehack/llamadart-native/actions/runs/42016701448)) +failed only where this pair was unaudited: the Linux arm64 Vulkan core lane and +both Android arm64 lanes. It published nothing. This document does not claim a +published or device-qualified v0.9.0 runtime. + +## Source and dispatch audit + +v0.9.0 is v0.8.0 plus 150 commits. These are unchanged: the KleidiAI release +and archive MD5 in CPU CMake, `ggml-cpu/kleidiai/` (tables, probes, SME +override, thread cap, fallback mask), `arch/arm/cpu-feats.cpp`, +`arch-fallback.h`, `ggml-cpu.cpp`, the generic `repack.cpp`/`repack.h` +selection, `arch/arm/quants.c` and `ggml-backend-reg.cpp` scoring and loading. +No feature probe, selector, KleidiAI call or CMake flag changes. + +The only ARM change is `arch/arm/repack.cpp`, which adds three ggml-owned +scalable paths, each behind `__ARM_FEATURE_SVE` and a runtime 256-bit vector +check: + +| Function | Compile guard | Runtime guard | +| --- | --- | --- | +| `ggml_gemv_mxfp4_4x4_q8_0` | SVE | `svcntb() * 8 == 256` | +| `ggml_gemv_q8_0_4x8_q8_0` | SVE | `ggml_cpu_get_sve_cnt() == QK8_0` | +| `ggml_gemm_q6_K_8x8_q8_K` | SVE and `__ARM_FEATURE_MATMUL_INT8` | `svcntb() * 8 == 256` | + +`armv8.2-a+dotprod+fp16` and every other non-SVE variant (Android +`armv8.0_1` to `armv8.6_1`, Linux arm64 baseline, `linux_armv8.2_2` and +`linux_armv8.6_1`) do not define `__ARM_FEATURE_SVE`, so these paths are not +compiled there and their NEON paths are unchanged. They compile only into the +Android SVE variants (`armv9.0_1`, `armv9.2_1`, `armv9.2_2`), which ggml scores +only on CPUs reporting SVE/SVE2, and they run only with 256-bit vectors. Android +SVE devices with 128-bit vectors take the existing NEON path. The `q6_K` GEMM's +`svmmla` is SVE I8MM, which the variant scores infer from NEON I8MM plus SVE; +v0.8.0's existing SVE I8MM paths in `arch/arm/quants.c` and `repack.cpp` +already rely on that. + +The other CPU changes add no scalable code to non-SVE builds: OCP FP8 E4M3 +(`GGML_TYPE_F8_E4M3`) conversion, dup and `ggml_vec_dot_f8_e4m3_f32`, whose +SIMD loop is compiled only without `__ARM_FEATURE_SVE`; `kv_rows` support in +flash attention; empty batched-copy buffer callbacks; and RISC-V guards changed +from `__riscv_v_intrinsic` to `__riscv_v`. The rest of `ggml/src` is +accelerator backends (CUDA, Metal, OpenCL, SYCL, Vulkan and others), the meta +backend, batched tensor copies in `ggml-backend.cpp`, and FP8 in `ggml.c` and +`ggml-quants.c`, none of which is in `libggml-cpu.so`. This review covers ISA +containment only, not numerical changes or accelerator backends. + +## Compiled evidence + +The production `build_android_arm64_cpu_variant` helper built +`android_armv8.2_2` (`armv8.2-a+dotprod+fp16`, KleidiAI on, `GGML_NATIVE=OFF`) +with NDK `28.2.13676358` on macOS arm64. Before the policy change the audit +failed with the same unaudited-pair error as the release. With the v0.9.0 pair +it passes: 265,940 instructions (v0.8.0: 261,765), with all 3,130 scalable +instructions in the same 22 exact functions. As on v0.8.0, the 20 v0.7.0 +functions hold 2,542 of them and the two SVE Q8_0 kernels 201 and 387. + +```bash +LLVM="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin" +python3 tools/validate_android_cpu_isa.py \ + --objdump "$LLVM/llvm-objdump" --readelf "$LLVM/llvm-readelf" \ + --llama-source third_party/llama.cpp \ + --kleidiai-source build/android-isa/_deps/kleidiai-src \ + build/android-isa/bin/libggml-cpu.so +``` + +`llamadart_kleidiai_dispatch_test` against v0.9.0 checked all 128 feature masks +and the 12 quantized matmuls against the scalar reference in each run: + +| Host | CPU | Selected (Q4_0 / Q8_0) | Result | +| --- | --- | --- | --- | +| Apple M4 Max, native | SME2, no SVE | SME2, with and without `GGML_KLEIDIAI_SME=1` | pass | +| `ubuntu:24.04` arm64 container, GCC 13.3, `armv8-a`, QEMU 8.2.2 | `cortex-a53` | NEON baseline | pass | +| same | `max,sve=off,sme=off` | I8MM | pass | +| same | `max,sve256=on,sme=off` | SVE | pass | + +Each QEMU row also passed with `GGML_KLEIDIAI_SME=1`. The `sve256` row executes +the two SVE Q8_0 kernels that v0.8.0 added. No lane had run them before. + +## Remaining gates + +- Hosted `android-arm64-isa`, `kleidiai-dispatch-emulated`, + `windows-arm64-kleidiai` and `linux-artifact-contract (arm64, *)` v0.9.0 + rows. Windows needs no `cmake/kleidiai_windows.cmake` change because KleidiAI + is unchanged. +- No lane runs the new ggml SVE256 repack paths. That needs an SVE variant + under QEMU with 256-bit vectors, or Neoverse V1 hardware. Physical Android + and SME-enabled device runs remain separate layers. diff --git a/docs/v090_qualification.md b/docs/v090_qualification.md new file mode 100644 index 00000000..d4b21726 --- /dev/null +++ b/docs/v090_qualification.md @@ -0,0 +1,77 @@ +# v0.9.0 qualification + +Stable upstream v0.9.0, `cd959bae99ff4bed22bef2604f45241c09bbb8c8` +(2026-11-04), is the next runtime candidate. It is v0.8.0 +`8642541b255bfb5dc39cd351a178be09013a55d6` plus 150 commits. Its native release +identity is the stable tag `v0.9.0`, which `latest` selects. + +This change moves the production submodule to v0.9.0 and adds a `v0.9.0` row +to every lane in `validate_wrapper.yml`. Native `v0.9.0` is not published: +the 2026-11-05 automatic dispatch failed at the CPU ISA audits +([v090_android_isa_qualification.md](v090_android_isa_qualification.md)), and +the next scheduled dispatch after this change reaches `main` publishes it. + +## Wrapper + +The wrapper builds against v0.9.0 without source changes, and every +`CMakeLists.txt` header probe succeeds. The exported API is unchanged. + +- `mtmd_gen_audio_info` gains `n_voices`. The wrapper reads only `type` and + `sample_rate`. +- `mtmd_helper_gen_audio_inp` loses `voice`, which the wrapper never set. +- `MTMD_GEN_AUDIO_TYPE_CHATTERBOX` maps to `LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN`, + so the TTS entry points report it unsupported. Chatterbox and the new + predefined-voice API are not wrapped. + +Evidence, 2026-11-06, Apple M4 Max, macOS arm64, Metal on, Release, +`LLAMADART_BUILD_TESTS=ON`, `LLAMADART_BUILD_TTS_SMOKE=ON`: native CTest +84/84; `tools/validate_exports.py` with `--forbid-import __cxa_atexit` passes +(92 required exports); `tools/llama_cpp_patches.py check-apple` passes on +`libllamadart.dylib`. + +## Carried patches + +`tools/llama_cpp_patches.py apply --strict` succeeds on v0.9.0 and applies only +0001 and 0002. `manifest --upstream` lists only those two, so a v0.9.0 +`assets.json` lists only them. `series.json` is unchanged. + +- 0001 (Adreno 750, #79) is still needed: upstream PR #29165 is still an open + draft, and the matvec reduction selection it guards is unchanged. +- 0002 (buffer device address, leehack/llamadart#782) is still needed: v0.9.0 + still takes `bufferDeviceAddress` from `VkPhysicalDeviceVulkan12Features` + without checking for the entry point. +- 0003 (#114) stays retired, as on v0.8.0: its `upstream_fix` is in + `src/llama-context.cpp`. +- 0004 (#154) is retired on v0.9.0: upstream #31360 (`c9daee1`) is in v0.9.0, + and `unary.metal` contains its `upstream_fix` text. The patch is not applied + and `check-apple` does not require its marker. Its `required_text`, the + v0.8.0 `inline constexpr` form, no longer occurs in v0.9.0. + `metal_os_floor.yml` checks the unpatched v0.9.0 kernels on the oldest + runners. + +Delete 0004 once no `validate_wrapper.yml` row builds v0.8.0, and 0003 once +none builds v0.7.0 or older. + +## Consumer ABI delta from v0.8.0 + +No public C symbol is removed. Regenerated bindings must account for: + +| Header | Change | +| --- | --- | +| `llama.h` | Adds `LLAMA_FTYPE_MOSTLY_F8_E4M3 = 42`. | +| `ggml.h` | Adds `ggml_fp8_e4m3_t`, `GGML_TYPE_F8_E4M3 = 43` (`GGML_TYPE_COUNT` becomes 44), `GGML_FTYPE_MOSTLY_F8_E4M3 = 29` and `ggml_flash_attn_ext_rows`. | +| `ggml-backend.h` | Adds `ggml_backend_tensor_copy_n`, `ggml_backend_tensor_set_n`, `ggml_backend_tensor_get_n`, and the `ggml_backend_comm_bootstrap_callback` and `ggml_backend_comm_init_rank_t` typedefs. | +| `mtmd.h` | `mtmd_gen_audio_info`, returned by value, appends `int32_t n_voices` and grows from 16 to 24 bytes on 64-bit targets. Appends `MTMD_VIDEO_TEMPLATE_QWEN3VL` and `MTMD_GEN_AUDIO_TYPE_CHATTERBOX`. Adds `mtmd_bitmap_is_voice`, `mtmd_gen_audio_read_tensor`, `mtmd_gen_audio_voice_name`, `mtmd_gen_audio_get_voice` and `mtmd_gen_state_set_ref`. | +| `mtmd-helper.h` | `mtmd_helper_gen_audio_inp` drops `voice` after `lang`, so every later field moves back 8 bytes and the struct shrinks from 72 to 64 bytes on 64-bit targets. The C++ `gen_audio::inp` drops `set_voice`. Adds the C++-only test types `mtmd_helper_video_src` and `mtmd_helper_video_seq`. | + +`common.h`, which the bindings do not include, drops `fs_path_to_utf8` and +gives `common_control_vector_load` an `n_layer` argument; the wrapper uses +neither. + +## Remaining gates + +- Hosted `v0.9.0` and `pinned` rows of every lane in `validate_wrapper.yml`, + `validate_linux_release_rows.yml` and `metal_os_floor.yml`. +- Android ISA: [v090_android_isa_qualification.md](v090_android_isa_qualification.md). +- Model, family and device qualification stays with the consumer release; this + document claims none of it. diff --git a/tests/test_android_cpu_isa.py b/tests/test_android_cpu_isa.py index fe18a0e9..1e577da7 100644 --- a/tests/test_android_cpu_isa.py +++ b/tests/test_android_cpu_isa.py @@ -113,6 +113,9 @@ def test_exact_reviewed_source_pairs_are_required(self): ), ( "0b14cd6eac9832e7e50cee546495581c0067e7bca5c0db1dee6c3f7c0f7cf1f3", "fd5b9ca98d07b81671eca377c258da74e72173f92f3cab0acdf6c17ab870bd9d", + ), ( + "fead7601e3b35651ee62764c76f28b50ee564160b543ff79be6fcc81837216c4", + "fd5b9ca98d07b81671eca377c258da74e72173f92f3cab0acdf6c17ab870bd9d", )}) self.assertEqual(audit.SOURCE_PAIRS, expected) for ggml, kai in expected: @@ -138,7 +141,8 @@ def test_cli_binds_exact_function_ranges_to_the_reviewed_source_pair(self): args = ["audit", "--objdump", "objdump", "--readelf", "readelf", "--llama-source", "llama", "--kleidiai-source", "kleidiai", "test.so"] allowed_by_pair = {audit.V070_SOURCE_PAIR: audit.DISPATCHED_FUNCTIONS_V070, - audit.V080_SOURCE_PAIR: audit.DISPATCHED_FUNCTIONS_V080} + audit.V080_SOURCE_PAIR: audit.DISPATCHED_FUNCTIONS_V080, + audit.V090_SOURCE_PAIR: audit.DISPATCHED_FUNCTIONS_V080} for pair in audit.SOURCE_PAIRS: allowed = allowed_by_pair.get(pair, audit.DISPATCHED_FUNCTIONS) for artifact_ranges in (audit.DISPATCHED_FUNCTIONS, audit.DISPATCHED_FUNCTIONS_V070, diff --git a/tests/test_ci_scope.py b/tests/test_ci_scope.py index 061ea093..f03a1130 100644 --- a/tests/test_ci_scope.py +++ b/tests/test_ci_scope.py @@ -1,5 +1,6 @@ import json import os +import re from pathlib import Path import subprocess import sys @@ -91,7 +92,7 @@ def test_actual_workflow_routes_every_compiler_and_aggregate(self): self.assertIn('github.event.pull_request.base.sha || github.event.before',changes) self.assertIn('tools/ci_scope.py',changes) windows=workflow_job(workflow,'windows-arm64-kleidiai') - self.assertIn('upstream: [pinned, post-v0.4.0, v0.5.0, v0.6.0, v0.7.0, v0.8.0]',windows) + self.assertIn('upstream: [pinned, post-v0.4.0, v0.5.0, v0.6.0, v0.7.0, v0.8.0, v0.9.0]',windows) for filename in ('validate_wrapper.yml','validate_release_provenance.yml'): content=(ROOT/'.github/workflows'/filename).read_text() triggers=content.split('permissions:')[0] @@ -112,16 +113,19 @@ def test_v070_qualification_uses_the_exact_candidate_in_every_native_lane(self): self.assertIn('rev-parse HEAD)" = "$LLAMADART_QUALIFICATION_SHA"',body) - def test_v080_qualification_uses_the_exact_candidate_in_every_native_lane(self): + def test_v080_and_v090_qualification_use_the_exact_candidate_in_every_native_lane(self): workflow=(ROOT/'.github/workflows/validate_wrapper.yml').read_text() - self.assertIn('LLAMADART_V080_QUALIFICATION_SHA: 8642541b255bfb5dc39cd351a178be09013a55d6',workflow) - for job in JOBS: - with self.subTest(job=job): - body=workflow_job(workflow,job) - self.assertRegex(body,r'upstream: \[[^\n]*v0\.8\.0\]') - self.assertIn("matrix.upstream == 'v0.8.0' && env.LLAMADART_V080_QUALIFICATION_SHA",body) - self.assertIn('checkout --detach "$LLAMADART_QUALIFICATION_SHA"',body) - self.assertIn('rev-parse HEAD)" = "$LLAMADART_QUALIFICATION_SHA"',body) + candidates=(('v0.8.0','V080','8642541b255bfb5dc39cd351a178be09013a55d6'), + ('v0.9.0','V090','cd959bae99ff4bed22bef2604f45241c09bbb8c8')) + for upstream,name,sha in candidates: + self.assertIn(f'LLAMADART_{name}_QUALIFICATION_SHA: {sha}',workflow) + for job in JOBS: + with self.subTest(upstream=upstream,job=job): + body=workflow_job(workflow,job) + self.assertRegex(body,rf'upstream: \[[^\n]*{re.escape(upstream)}[,\]]') + self.assertIn(f"matrix.upstream == '{upstream}' && env.LLAMADART_{name}_QUALIFICATION_SHA",body) + self.assertIn('checkout --detach "$LLAMADART_QUALIFICATION_SHA"',body) + self.assertIn('rev-parse HEAD)" = "$LLAMADART_QUALIFICATION_SHA"',body) if __name__ == '__main__': unittest.main() diff --git a/tools/validate_android_cpu_isa.py b/tools/validate_android_cpu_isa.py index 112cdb82..6571ae20 100644 --- a/tools/validate_android_cpu_isa.py +++ b/tools/validate_android_cpu_isa.py @@ -21,8 +21,8 @@ # or a different KleidiAI combination invalidates the dispatch audit. # Candidate audit evidence: docs/post_v040_qualification.md, # docs/v041_android_isa_qualification.md, docs/v050_android_isa_qualification.md -# docs/v060_android_isa_qualification.md, docs/v070_android_isa_qualification.md -# and docs/v080_android_isa_qualification.md. +# docs/v060_android_isa_qualification.md, docs/v070_android_isa_qualification.md, +# docs/v080_android_isa_qualification.md and docs/v090_android_isa_qualification.md. V070_SOURCE_PAIR = ( "b571df853210d243a83b1ec34a6936f147916f0369d792f8bb0d17f37fc7894b", "deb324dbcf8c952ec149433ab58cbed0b2ab2374a557f0a4eea575b2da761377", @@ -31,6 +31,10 @@ "0b14cd6eac9832e7e50cee546495581c0067e7bca5c0db1dee6c3f7c0f7cf1f3", "fd5b9ca98d07b81671eca377c258da74e72173f92f3cab0acdf6c17ab870bd9d", ) +V090_SOURCE_PAIR = ( + "fead7601e3b35651ee62764c76f28b50ee564160b543ff79be6fcc81837216c4", + "fd5b9ca98d07b81671eca377c258da74e72173f92f3cab0acdf6c17ab870bd9d", +) SOURCE_PAIRS = frozenset({ ( # llama.cpp v0.4.0 / KleidiAI v1.24.0 "c4dc92a7d95ebfad7f5f55e75be2ae773b7d95faf72a9581c9479c42bc41bca0", @@ -54,6 +58,7 @@ ), V070_SOURCE_PAIR, # llama.cpp v0.7.0 / KleidiAI v1.31.0 V080_SOURCE_PAIR, # llama.cpp v0.8.0 8642541b255bfb5dc39cd351a178be09013a55d6 / KleidiAI v1.32.0 + V090_SOURCE_PAIR, # llama.cpp v0.9.0 cd959bae99ff4bed22bef2604f45241c09bbb8c8 / KleidiAI v1.32.0 }) # Exact ELF STT_FUNC ranges; never allow by kai_* prefix or disassembly label. @@ -92,7 +97,8 @@ """.split()) # KleidiAI v1.32.0 adds a Q8_0 table entry reachable only with runtime SVE256, -# SVE I8MM and DOTPROD. Its two kernels are exclusive to the v0.8.0 source pair. +# SVE I8MM and DOTPROD. v0.9.0 keeps KleidiAI and its ggml callers unchanged, so +# only the v0.8.0 and v0.9.0 source pairs grant these two kernels. DISPATCHED_FUNCTIONS_V080 = DISPATCHED_FUNCTIONS_V070 | frozenset(""" kai_kernel_matmul_clamp_f32_qai8dxp1x8_qsi8cxp8x8_1x8_sve_dot kai_kernel_matmul_clamp_f32_qai8dxp4x8sf32_qsi8cxp4vsx8sf32bf32_16x4vs_sve_i8mm @@ -101,6 +107,7 @@ PAIR_FUNCTIONS = { V070_SOURCE_PAIR: DISPATCHED_FUNCTIONS_V070, V080_SOURCE_PAIR: DISPATCHED_FUNCTIONS_V080, + V090_SOURCE_PAIR: DISPATCHED_FUNCTIONS_V080, } SCALABLE_REG = re.compile(r"\b(?:z\d+|p\d+|pn\d+|za\d*[hv]?|zt\d+)\b") From 7f15b5d1f7b215fc50916673b2c17db87c94ba8c Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Fri, 6 Nov 2026 05:47:29 -0500 Subject: [PATCH 3/5] Bump llama.cpp submodule to v0.9.0 --- third_party/llama.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/llama.cpp b/third_party/llama.cpp index 8642541b..cd959bae 160000 --- a/third_party/llama.cpp +++ b/third_party/llama.cpp @@ -1 +1 @@ -Subproject commit 8642541b255bfb5dc39cd351a178be09013a55d6 +Subproject commit cd959bae99ff4bed22bef2604f45241c09bbb8c8 From 16f27bdf27f0f7eca6f75a71079b86d1592f864b Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Fri, 6 Nov 2026 06:12:08 -0500 Subject: [PATCH 4/5] feat: add opt-in Chatterbox and Pocket TTS with predefined voices Map upstream v0.9.0 Chatterbox (Turbo, Multilingual V3) and Pocket TTS behind the _ext model-type mask, list and select a projector's predefined voices through upstream voice bitmaps, and own Chatterbox Multilingual's classifier-free-guidance sequence. The TTS sampler now applies the GGUF's suppress tokens, as upstream common_sampler does; without them Chatterbox samples text end-of-generation tokens. --- .github/workflows/validate_wrapper.yml | 1 + AGENTS.md | 2 + CMakeLists.txt | 33 +- README.md | 22 +- docs/lfm3_support.md | 2 + docs/tts_voices.md | 177 +++++++++ src/llama_dart_tts_internal.h | 10 +- src/llama_dart_tts_types_internal.h | 142 +++++-- src/llama_dart_wrapper.cpp | 232 +++++++++++- src/llama_dart_wrapper.h | 67 +++- tests/test_expected_tts_model_types.py | 42 ++- tests/test_validate_exports.py | 6 +- tests/tts_api_test.c | 23 +- tests/tts_types_test.cpp | 174 +++++++-- tools/expected_tts_model_types.py | 15 + tools/tts_voice_smoke.cpp | 492 +++++++++++++++++++++++++ tools/validate_exports.py | 2 + 17 files changed, 1338 insertions(+), 104 deletions(-) create mode 100644 docs/tts_voices.md create mode 100644 tools/tts_voice_smoke.cpp diff --git a/.github/workflows/validate_wrapper.yml b/.github/workflows/validate_wrapper.yml index 70d679f5..93262bd4 100644 --- a/.github/workflows/validate_wrapper.yml +++ b/.github/workflows/validate_wrapper.yml @@ -534,6 +534,7 @@ jobs: llamadart_tts_smoke llamadart_tts_lfm3_smoke llamadart_soprano_tts_smoke + llamadart_tts_voice_smoke - name: Run wrapper contract tests run: ctest --test-dir build/wrapper-contract --output-on-failure - name: Check that the build identity is reproducible and follows its inputs diff --git a/AGENTS.md b/AGENTS.md index 1fb5b3c5..3deda64d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -62,6 +62,8 @@ and the oldest iOS simulator because ggml compiles Metal source on the user's device, and for what it does not cover (macOS 13 and 14, iOS 16 and 17). See `docs/lfm3_support.md` for which LFM3 variants need wrapper surface, the opt-in LFM3-Audio speech exports and what stays unwrapped. +See `docs/tts_voices.md` for the opt-in Chatterbox and Pocket TTS types, the +predefined-voice exports and their ABI delta for the Dart bindings. See `docs/v070_native_contracts.md` for draft expert-cache isolation, dynamic export validation, ABI handoff and opt-in EmbeddingGemma-2 model qualification. See `docs/v060_1_wrapper_rebuild.md` for the `v0.6.0-1` header additions and diff --git a/CMakeLists.txt b/CMakeLists.txt index 4aa1dc0c..948e80e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,24 @@ unset(LLAMADART_MTMD_HAS_SOPRANO CACHE) llamadart_probe_declaration(LLAMADART_MTMD_HAS_SOPRANO "#include int main() { return MTMD_GEN_AUDIO_TYPE_SOPRANO == MTMD_GEN_AUDIO_TYPE_NONE; }") +# Predefined voices as voice bitmaps (upstream v0.9.0, #31429). +unset(LLAMADART_MTMD_HAS_GEN_VOICES CACHE) +llamadart_probe_declaration(LLAMADART_MTMD_HAS_GEN_VOICES + "#include +int main() { + mtmd_gen_audio_info info{}; + return info.n_voices != 0 || + sizeof(decltype(&mtmd_gen_audio_voice_name)) == 0 || + sizeof(decltype(&mtmd_gen_audio_get_voice)) == 0 || + sizeof(decltype(&mtmd_bitmap_is_voice)) == 0; +}") +unset(LLAMADART_MTMD_HAS_CHATTERBOX CACHE) +llamadart_probe_declaration(LLAMADART_MTMD_HAS_CHATTERBOX + "#include +int main() { + return MTMD_GEN_AUDIO_TYPE_CHATTERBOX == MTMD_GEN_AUDIO_TYPE_NONE || + sizeof(decltype(&mtmd_gen_audio_read_tensor)) == 0; +}") list(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/third_party/llama.cpp/common" "${CMAKE_CURRENT_SOURCE_DIR}/third_party/llama.cpp/vendor") @@ -278,6 +296,8 @@ target_compile_definitions(llamadart_lib PRIVATE LLAMADART_MTMD_HAS_GEN_STATE=$ LLAMADART_MTMD_HAS_LFM3A_GEN=$ LLAMADART_MTMD_HAS_SOPRANO=$ + LLAMADART_MTMD_HAS_GEN_VOICES=$ + LLAMADART_MTMD_HAS_CHATTERBOX=$ LLAMADART_SPECULATIVE_HAS_COMMON_BATCH=$ LLAMADART_SPECULATIVE_HAS_BATCH_STATE=$ LLAMADART_MTMD_HELPER_HAS_OPTIONS=$) @@ -382,7 +402,9 @@ if (LLAMADART_BUILD_TESTS) target_compile_features(llamadart_tts_types_test PRIVATE cxx_std_17) target_compile_definitions(llamadart_tts_types_test PRIVATE LLAMADART_MTMD_HAS_LFM3A_GEN=$ - LLAMADART_MTMD_HAS_SOPRANO=$) + LLAMADART_MTMD_HAS_SOPRANO=$ + LLAMADART_MTMD_HAS_GEN_VOICES=$ + LLAMADART_MTMD_HAS_CHATTERBOX=$) target_include_directories(llamadart_tts_types_test PRIVATE src third_party/llama.cpp/include @@ -762,6 +784,15 @@ if (LLAMADART_BUILD_TTS_SMOKE) third_party/llama.cpp/tools/mtmd src ) + + add_executable(llamadart_tts_voice_smoke tools/tts_voice_smoke.cpp) + target_compile_features(llamadart_tts_voice_smoke PRIVATE cxx_std_17) + target_link_libraries(llamadart_tts_voice_smoke PRIVATE llamadart_lib) + target_include_directories(llamadart_tts_voice_smoke PRIVATE + third_party/llama.cpp/include + third_party/llama.cpp/tools/mtmd + src + ) endif() if (LLAMADART_BUILD_EMBEDDING_SMOKE) diff --git a/README.md b/README.md index 6d43ad8e..7dd0304f 100644 --- a/README.md +++ b/README.md @@ -527,7 +527,8 @@ cmake -S . -B build/tts-smoke -G Ninja \ cmake --build build/tts-smoke --target \ llamadart_speculative_api_test llamadart_tts_api_test \ llamadart_tts_types_test llamadart_tts_eval_test llamadart_mtmd_compat_test \ - llamadart_tts_smoke llamadart_tts_lfm3_smoke llamadart_soprano_tts_smoke + llamadart_tts_smoke llamadart_tts_lfm3_smoke llamadart_soprano_tts_smoke \ + llamadart_tts_voice_smoke ctest --test-dir build/tts-smoke --output-on-failure build/tts-smoke/llamadart_tts_smoke \ /path/to/Qwen3-TTS-model.gguf \ @@ -611,6 +612,25 @@ one-frame failure, finite non-silent PCM, seeded repeats, a cancel issued inside the audio decode (it must stop at the decode's first chunk boundary) and `max_frames` truncation. +### Chatterbox and Pocket TTS + +Builds on llama.cpp v0.9.0 and later also drive Chatterbox (Turbo and +Multilingual V3) and Pocket TTS for callers whose `_ext` mask names +`LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX` or `LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS`. +`llama_dart_tts_get_voice_count` and `llama_dart_tts_get_voice_name` list a +projector's predefined voices, and `llama_dart_tts_start_with_voice` selects +one by name; an unknown name is `INVALID_ARGUMENT`. Without a voice or a +speaker reference the first voice speaks. Chatterbox Multilingual takes a +language and a second sequence for classifier-free guidance. Rules, ABI delta +and the qualified model files: [docs/tts_voices.md](docs/tts_voices.md). + +```bash +build/tts-smoke/llamadart_tts_voice_smoke \ + /path/to/chatterbox-turbo-Q8_0.gguf \ + /path/to/mmproj-chatterbox-turbo-F16.gguf \ + /tmp/voice-smoke --speaker /path/to/reference.wav --gpu +``` + ## Windows Build Notes MSVC release builds keep interprocedural optimization enabled by default, but diff --git a/docs/lfm3_support.md b/docs/lfm3_support.md index de2768d4..24f2f70a 100644 --- a/docs/lfm3_support.md +++ b/docs/lfm3_support.md @@ -40,6 +40,8 @@ The generator differs from Qwen3-TTS in ways an allowlist entry cannot cover: - Its prompt must be the model's `tts` chat template, ending in `<|audio_start|>`. The wrapper renders `request.text` with llama.cpp's `common_chat_get_tts_prompt`, `request.language` and the voice. + `llama_dart_tts_get_voice_name` lists the voices, `female` and `male` + ([tts_voices.md](tts_voices.md)). - Frames come from the hidden state. The text head is not sampled, so a text end-of-generation token cannot end the speech; the end-of-audio code does. - Upstream ignores a speaker reference with a warning; the wrapper refuses it. diff --git a/docs/tts_voices.md b/docs/tts_voices.md new file mode 100644 index 00000000..47b2f5fb --- /dev/null +++ b/docs/tts_voices.md @@ -0,0 +1,177 @@ +# Chatterbox, Pocket TTS and predefined voices + +Upstream stable v0.9.0 (`cd959bae`) adds Chatterbox Turbo and Multilingual V3 +([#30993](https://github.com/ggml-org/llama.cpp/pull/30993), `b97627967`) and +predefined voices for Pocket TTS +([#31429](https://github.com/ggml-org/llama.cpp/pull/31429), `d02b4c0d6`). +The wrapper drives both generators opt-in and lists and selects a projector's +predefined voices. Owner issues: +[#164](https://github.com/leehack/llamadart-native/issues/164) (Chatterbox) and +[#163](https://github.com/leehack/llamadart-native/issues/163) (Pocket TTS). + +## ABI delta for the Dart bindings + +Additive; no struct layout, status value or `LLAMA_DART_TTS_API_VERSION` +changes. + +| Change | Detail | +| --- | --- | +| `LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX = 4` | Reported only to `_ext` callers whose mask has `1u << 4`. | +| `LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS = 5` | Reported only to `_ext` callers whose mask has `1u << 5`. | +| `llama_dart_tts_supported_model_types()` | `0x3e` on v0.9.0 (was `0xe`). | +| `llama_dart_tts_get_voice_count` | New export, see below. | +| `llama_dart_tts_get_voice_name` | New export, see below. | +| `llama_dart_tts_start_with_voice` | Validates against the listed voices for every type. | + +```c +enum llama_dart_tts_status llama_dart_tts_get_voice_count( + const struct mtmd_context * mtmd, + uint32_t accepted_model_types, + int32_t * out_count); + +enum llama_dart_tts_status llama_dart_tts_get_voice_name( + const struct mtmd_context * mtmd, + uint32_t accepted_model_types, + int32_t index, + char * out_name, // NULL with out_capacity 0 queries the length + size_t out_capacity, // must exceed the length (room for the NUL) + size_t * out_length); // length without the NUL +``` + +Both take the same mask as `llama_dart_tts_get_info_ext`, so a caller sees no +voices of a generator it did not opt into (`UNSUPPORTED`, count 0). A model +without `LLAMA_DART_TTS_CAPABILITY_VOICE` has count 0. Index 0 is the voice a +request without one speaks with. Both run behind the exception barrier: a +caught exception returns `UPSTREAM_ERROR`. On a wrapper older than this change +the symbols are absent; resolve them lazily, as for the `_ext` exports. + +## Rules per model type + +| | Chatterbox Turbo | Chatterbox Multilingual | Pocket TTS | LFM3-Audio | +| --- | --- | --- | --- | --- | +| Capabilities | `VOICE`, `SPEAKER_REFERENCE` | `LANGUAGE`, `VOICE`, `SPEAKER_REFERENCE` | `VOICE` if the projector has voices, `SPEAKER_REFERENCE` if it has an encoder | `LANGUAGE`, `VOICE` | +| Voices | `default` (from `conds.pt`) | `default` | 25 in the Kyutai packs | `female`, `male` | +| No voice, no reference | first voice | first voice | first voice; unconditioned if none | template default | +| Voice + reference | `INVALID_ARGUMENT` | `INVALID_ARGUMENT` | `INVALID_ARGUMENT` | `UNSUPPORTED` (reference) | +| Language | `UNSUPPORTED` | prefixed as `[xx]`, not validated | `UNSUPPORTED` | chat template | +| Sampling | request settings | request settings | the weights' own | the GGUF's | +| Sequences | one | task sequence and `n_seq_max / 2 + sequence_id` | one | one | + +A voice is a voice bitmap from `mtmd_gen_audio_get_voice` passed as the speaker +reference, as `llama-tts` and `llama-server` do; LFM3-Audio keeps naming its +voice in the `tts` chat template. A name matches in any case, as upstream's +lookup does, and an unknown name is `INVALID_ARGUMENT`: the wrapper never falls +back to the default. Upstream Chatterbox fails without a voice or a reference, +so a Chatterbox projector without voices needs a reference +(`INVALID_ARGUMENT` otherwise). Pocket TTS without either speaks unconditioned, +as upstream allows. + +Chatterbox Multilingual runs classifier-free guidance on a second sequence. +The task owns it like its own sequence: it is cleared at start, on completion, +error, cancel, reset and free. `llama_dart_tts_init_ext` refuses a context +with `n_seq_max < 2`, and a `sequence_id` not below `n_seq_max / 2` is +`INVALID_ARGUMENT`, before the context is touched. A unified KV cache is not +needed; without one, each sequence holds `n_ctx / n_seq_max` positions. The +wrapper tells Multilingual from Turbo as the bundled helper does at v0.9.0, by +the `a.gen.t3.text_pos_emb` table. Upstream +[#31698](https://github.com/ggml-org/llama.cpp/pull/31698) (after v0.9.0) +moves that to `{arch}.classifier_free_guidance`; the bump that takes it must +move this check with it. + +## Sampling and suppress tokens + +The wrapper's TTS sampler now applies the GGUF's +`tokenizer.ggml.suppress_tokens` as `-inf` logit biases, as upstream +`common_sampler` does. Without it Chatterbox draws text tokens: with seeds 2, +3 and 5 its first token was GPT-2 `<|endoftext|>` (an end-of-generation token), +which ends the utterance with no audio. Upstream `llama-tts` gave 61 to 72 +frames for seeds 1 to 8 with the same settings. The Qwen3-TTS converter also +suppresses 1023 codec control tokens, so Qwen3-TTS now samples as upstream does +too; its smoke and transcription still pass, but a fixed seed may not repeat +the PCM of earlier wrappers. Soprano writes no suppress tokens. + +The Chatterbox GGUFs embed upstream's defaults in `general.sampling.*`: Turbo +`top_k 1000`, `top_p 0.95`, `min_p 0`, `temp 0.8`; Multilingual `top_k 0`, +`top_p 1`, `min_p 0.05`, `temp 0.8`. Their `penalty_repeat 1.2` is inert +upstream: `penalty_last_n -1` clamps to 0. The wrapper's request defaults +(`top_k 40`, `top_p 0.95`, `min_p 0`, `temp 0.8`) also give intelligible +speech; callers may pass the GGUF values to match `llama-tts`. + +## Why Pocket TTS is included + +It needs no new wrapper machinery. Its helper pipeline uses the step contract +LFM3-Audio already exercises (no backbone token, frames from the hidden state, +`stop` from the helper), and its voices are the same voice bitmaps. The bit is +gated on the voice API (`mtmd_gen_audio_get_voice`), so a build on older +headers still reports it `UNKNOWN`. Long text is split into chunks inside the +helper, each restarting from the voice; frames of every chunk count towards +`max_frames`. + +## Not exposed + +- Streaming PCM and `mtmd_helper_gen_audio_flush`. Chatterbox's flow decode is + one-shot anyway. +- `mtmd_gen_audio_read_tensor`, `mtmd_gen_state_set_ref` and raw voice bitmaps: + the helper calls them; callers name voices. +- Chatterbox CFG strength (fixed at 0.5 upstream). + +## Known upstream gaps + +- Multilingual text is not normalized + ([#31686](https://github.com/ggml-org/llama.cpp/issues/31686)): diacritics of + some languages drop. The wrapper passes `request.text` as given and does not + validate the language; check it against the model card. +- A short speaker clip makes Chatterbox run on: a 3 s clip reached 512 frames + in both `llama-tts` and the wrapper, an 8.7 s clip ended at 67 to 84 frames. + Upstream recommends about 10 s. +- The prompt is tokenized with special-token parsing (Chatterbox), as in + `llama-tts`. + +## Local check + +`llamadart_tts_voice_smoke` (`-DLLAMADART_BUILD_TTS_SMOKE=ON`) takes either +generator: + +```bash +build/tts-smoke/llamadart_tts_voice_smoke MODEL MMPROJ /tmp/voice-smoke \ + [--speaker REFERENCE.wav] [--gpu] +``` + +It checks that callers without the type's bit see `UNKNOWN`, the capability +metadata, voice listing (length query, short buffer, out-of-range index), +unknown-voice, voice-plus-reference, language and sequence rejections, the +Multilingual refusal of a one-sequence context, cancel before and during +generation and that both sequences are empty afterwards, that a request +without a voice equals one naming the first voice in upper case on another +sequence, that another voice, another seed and a reference each change the +PCM, a French Multilingual synthesis and `max_frames` truncation. It writes +`-default.wav`, `-.wav`, `-cloned.wav` and `-fr.wav`. + +Results on macOS arm64 (M4 Max) at `cd959bae`, CPU and Metal, all `PASS`; +transcripts from Qwen3-ASR-0.6B +([ggml-org/Qwen3-ASR-0.6B-GGUF](https://huggingface.co/ggml-org/Qwen3-ASR-0.6B-GGUF) +`928ab958`, Q8_0): + +| Model (repository @ revision) | Files (sha256 prefix) | Transcript of `-default.wav` | +| --- | --- | --- | +| [ggml-org/chatterbox-turbo-GGUF](https://huggingface.co/ggml-org/chatterbox-turbo-GGUF) @ `66f03935` | `chatterbox-turbo-Q8_0.gguf` (`c3b93d3c`), `mmproj-chatterbox-turbo-F16.gguf` (`de86b2ea`) | "Hello from Mama Dart. How are you today?" (CPU), "Hello from Llama Dart. How are you today?" (Metal) | +| [ggml-org/chatterbox-GGUF](https://huggingface.co/ggml-org/chatterbox-GGUF) @ `a5c19d4a` | `chatterbox-Q8_0.gguf` (`8fb23a40`), `mmproj-chatterbox-F16.gguf` (`e2bc7506`) | "Hello from Llama Dart. How are you today?"; `-fr.wav`: "Bonjour, comment allez-vous aujourd'hui?" | +| [macolomb/pocket-tts-without-voice-cloning](https://huggingface.co/macolomb/pocket-tts-without-voice-cloning) @ `cc72b003` | `english/pocket-tts-english.gguf` (`7146564b`), `english/mmproj-pocket-tts-english.gguf` (`35cbf36b`) | "Hello from Llama Dart. How are you today?" (also voice `vera`) | + +The ggml-org Multilingual card asks for a build with #31698; at v0.9.0 the +converted file still runs, detected by its position tables. The speaker +reference was 8.7 s of Pocket TTS voice `vera` from upstream `llama-tts` +(sha256 `1228cbef`); the cloned outputs transcribe to the same sentence, with +"Llama Dart" heard as "Lama Dart" or "llama dot" on Turbo. +The Kyutai packs ship no voice encoder, so Pocket TTS reference cloning is +covered only by its `UNSUPPORTED` refusal. + +Regressions at the same commit, CPU and Metal: `llamadart_tts_smoke` with +Qwen3-TTS-12Hz-1.7B-Base Q4_K_M (`8d18c94a`) and its Q8_0 mmproj (`6fd65188`), +`llamadart_tts_lfm3_smoke` with LFM3-Audio-2B Q4_K_M (`9a773289`) and its Q8_0 +mmproj (`2b6648b1`), and `llamadart_soprano_tts_smoke` with Soprano-1.1-80M +converted from [ekwek/Soprano-1.1-80M](https://huggingface.co/ekwek/Soprano-1.1-80M) +@ `27b5a5f5` by the v0.9.0 converter (`b02f1225`, mmproj `4fe5de0c`) all pass. +The Soprano mmproj conversion needed the converter's exact +`torch.equal` Hann-window check relaxed: the stored window differs from +`torch.hann_window` by 6e-8 under torch 2.11. diff --git a/src/llama_dart_tts_internal.h b/src/llama_dart_tts_internal.h index ce1b8bc3..8e2142c8 100644 --- a/src/llama_dart_tts_internal.h +++ b/src/llama_dart_tts_internal.h @@ -27,7 +27,10 @@ struct llama_dart_tts { const int8_t *cancel_flag = nullptr; llama_dart_tts_state state = LLAMA_DART_TTS_STATE_IDLE; llama_seq_id sequence_id = 0; + // Chatterbox Multilingual's unconditional sequence, -1 for other models. + llama_seq_id cfg_sequence_id = -1; bool owns_sequence = false; + bool paired_cfg = false; int32_t prompt_batch_size = 512; int32_t max_frames = 512; int32_t prompt_tokens_remaining = 0; @@ -78,9 +81,14 @@ llama_dart_tts_release_task_resources(llama_dart_tts *tts) { mtmd_helper_gen_audio_reset(tts->generator); } if (tts->owns_sequence) { - llama_memory_seq_rm(llama_get_memory(tts->llama), tts->sequence_id, 0, -1); + llama_memory_t memory = llama_get_memory(tts->llama); + llama_memory_seq_rm(memory, tts->sequence_id, 0, -1); + if (tts->cfg_sequence_id >= 0) { + llama_memory_seq_rm(memory, tts->cfg_sequence_id, 0, -1); + } tts->owns_sequence = false; } + tts->cfg_sequence_id = -1; tts->cancel_flag = nullptr; } diff --git a/src/llama_dart_tts_types_internal.h b/src/llama_dart_tts_types_internal.h index ce39c087..2f44c449 100644 --- a/src/llama_dart_tts_types_internal.h +++ b/src/llama_dart_tts_types_internal.h @@ -6,8 +6,7 @@ #include #include -#include -#include +#include #ifndef LLAMADART_MTMD_HAS_LFM3A_GEN #define LLAMADART_MTMD_HAS_LFM3A_GEN 0 @@ -15,6 +14,12 @@ #ifndef LLAMADART_MTMD_HAS_SOPRANO #define LLAMADART_MTMD_HAS_SOPRANO 0 #endif +#ifndef LLAMADART_MTMD_HAS_GEN_VOICES +#define LLAMADART_MTMD_HAS_GEN_VOICES 0 +#endif +#ifndef LLAMADART_MTMD_HAS_CHATTERBOX +#define LLAMADART_MTMD_HAS_CHATTERBOX 0 +#endif static constexpr uint32_t llama_dart_tts_model_type_bit(llama_dart_tts_model_type type) { @@ -28,6 +33,13 @@ static constexpr uint32_t llama_dart_tts_build_model_types = : 0u) | (LLAMADART_MTMD_HAS_SOPRANO ? llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_SOPRANO) + : 0u) | + // Both select their predefined voices through upstream voice bitmaps. + (LLAMADART_MTMD_HAS_CHATTERBOX && LLAMADART_MTMD_HAS_GEN_VOICES + ? llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX) + : 0u) | + (LLAMADART_MTMD_HAS_GEN_VOICES + ? llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS) : 0u); // What llama_dart_tts_get_info and llama_dart_tts_init accepted before the @@ -49,6 +61,14 @@ llama_dart_tts_model_type_from_upstream(mtmd_gen_audio_type type) { #if LLAMADART_MTMD_HAS_SOPRANO case MTMD_GEN_AUDIO_TYPE_SOPRANO: return LLAMA_DART_TTS_MODEL_TYPE_SOPRANO; +#endif +#if LLAMADART_MTMD_HAS_CHATTERBOX && LLAMADART_MTMD_HAS_GEN_VOICES + case MTMD_GEN_AUDIO_TYPE_CHATTERBOX: + return LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; +#endif +#if LLAMADART_MTMD_HAS_GEN_VOICES + case MTMD_GEN_AUDIO_TYPE_POCKETTTS: + return LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS; #endif default: return LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN; @@ -70,19 +90,36 @@ llama_dart_tts_accepted_model_type(mtmd_gen_audio_type type, : LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN; } +// What a loaded projector offers, read once by the wrapper. +struct llama_dart_tts_model_traits { + bool speaker_encoder = false; // mtmd_support_audio + bool predefined_voices = false; // mtmd_gen_audio_info.n_voices > 0 + bool multilingual = false; // Chatterbox Multilingual's position tables +}; + static inline uint32_t llama_dart_tts_model_capabilities(llama_dart_tts_model_type type, - bool takes_speaker_audio) { + const llama_dart_tts_model_traits &traits) { + const uint32_t speaker = + traits.speaker_encoder ? LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE : 0u; + const uint32_t voice = + traits.predefined_voices ? LLAMA_DART_TTS_CAPABILITY_VOICE : 0u; switch (type) { case LLAMA_DART_TTS_MODEL_TYPE_QWEN3: - return LLAMA_DART_TTS_CAPABILITY_LANGUAGE | - (takes_speaker_audio ? LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE - : 0u); + return LLAMA_DART_TTS_CAPABILITY_LANGUAGE | speaker; case LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO: // Its audio encoder is for chat input; the generator has no voice - // conditioning and ignores a speaker reference. + // conditioning and ignores a speaker reference. Its voices are names in + // the "tts" chat template. return LLAMA_DART_TTS_CAPABILITY_LANGUAGE | LLAMA_DART_TTS_CAPABILITY_VOICE; + case LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX: + // Turbo is English only and ignores a language upstream. + return (traits.multilingual ? LLAMA_DART_TTS_CAPABILITY_LANGUAGE : 0u) | + speaker | voice; + case LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS: + // The language is a property of the weights. + return speaker | voice; default: return 0; } @@ -95,31 +132,55 @@ static inline bool llama_dart_tts_language_supported(uint32_t capabilities, (capabilities & LLAMA_DART_TTS_CAPABILITY_LANGUAGE) != 0; } -// The LFM3-Audio "tts" chat template falls back to its default voice for any -// other name, so an unknown voice is rejected here instead of being ignored. -static inline bool llama_dart_tts_voice_supported( - llama_dart_tts_model_type model_type, const char *voice) { - if (voice == nullptr) { - return true; - } - if (model_type != LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO) { +// Voice names match case-insensitively, as upstream mtmd_gen_audio_get_voice +// and the LFM3-Audio "tts" chat template do. +static inline bool llama_dart_tts_voice_name_equal(const char *name, + const char *voice) { + if (name == nullptr || voice == nullptr) { return false; } - for (const char *name : {"female", "male"}) { - const size_t length = std::strlen(name); - if (std::strlen(voice) != length) { - continue; - } - size_t i = 0; - while (i < length && - std::tolower(static_cast(voice[i])) == name[i]) { - ++i; - } - if (i == length) { - return true; + size_t i = 0; + for (; name[i] != '\0' && voice[i] != '\0'; ++i) { + if (std::tolower(static_cast(name[i])) != + std::tolower(static_cast(voice[i]))) { + return false; } } - return false; + return name[i] == voice[i]; +} + +// LFM3-Audio voices for an mtmd that cannot list them (before upstream +// v0.9.0). Its "tts" chat template falls back to its default voice for any +// other name, so an unknown voice is rejected instead of being ignored. +static inline const char *llama_dart_tts_lfm3_voice_name(int32_t index) { + static const char *const names[] = {"female", "male"}; + return index >= 0 && index < 2 ? names[index] : nullptr; +} + +// Chatterbox and Pocket TTS take a voice as an upstream voice bitmap in place +// of a speaker reference; LFM3-Audio names it in its chat template. +static inline bool +llama_dart_tts_voice_is_conditioning(llama_dart_tts_model_type model_type) { + return model_type == LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX || + model_type == LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS; +} + +// Upstream Chatterbox fails without a speaker reference or a voice. +static inline bool +llama_dart_tts_requires_conditioning(llama_dart_tts_model_type model_type) { + return model_type == LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; +} + +// The unconditional sequence that upstream Chatterbox Multilingual decodes +// for classifier-free guidance, half the context's sequences away; -1 when +// the context has no such sequence for seq_id. +static inline int32_t llama_dart_tts_cfg_sequence(uint32_t n_seq_max, + int32_t seq_id) { + const int64_t half = static_cast(n_seq_max) / 2; + if (seq_id < 0 || half == 0 || seq_id >= half) { + return -1; + } + return static_cast(half + seq_id); } // Only Qwen3-TTS has a code predictor. Soprano's projector accepts GEN_WAV @@ -129,17 +190,28 @@ llama_dart_tts_primes_code_predictor(llama_dart_tts_model_type model_type) { return model_type == LLAMA_DART_TTS_MODEL_TYPE_QWEN3; } -// Qwen3-TTS and Soprano generate each frame from a sampled backbone token; -// LFM3-Audio frames come from the hidden state alone. +// Qwen3-TTS, Soprano and Chatterbox generate each frame from a sampled +// backbone token; LFM3-Audio and Pocket TTS frames come from the hidden state. static inline bool llama_dart_tts_samples_backbone_token(llama_dart_tts_model_type model_type) { return model_type == LLAMA_DART_TTS_MODEL_TYPE_QWEN3 || - model_type == LLAMA_DART_TTS_MODEL_TYPE_SOPRANO; + model_type == LLAMA_DART_TTS_MODEL_TYPE_SOPRANO || + model_type == LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; } -// Upstream Soprano fails a speaker reference; LFM3-Audio ignores one. +// Upstream Soprano fails a speaker reference and LFM3-Audio ignores one. +// Chatterbox and Pocket TTS fail one without a speaker encoder; Qwen3-TTS +// keeps its decode-time check. static inline bool -llama_dart_tts_rejects_speaker_reference(llama_dart_tts_model_type model_type) { - return model_type == LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO || - model_type == LLAMA_DART_TTS_MODEL_TYPE_SOPRANO; +llama_dart_tts_accepts_speaker_reference(llama_dart_tts_model_type model_type, + uint32_t capabilities) { + switch (model_type) { + case LLAMA_DART_TTS_MODEL_TYPE_QWEN3: + return true; + case LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX: + case LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS: + return (capabilities & LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE) != 0; + default: + return false; + } } diff --git a/src/llama_dart_wrapper.cpp b/src/llama_dart_wrapper.cpp index 2ca1be2f..654346da 100644 --- a/src/llama_dart_wrapper.cpp +++ b/src/llama_dart_wrapper.cpp @@ -107,21 +107,104 @@ static llama_dart_tts_status llama_dart_tts_mark_cancelled( return LLAMA_DART_TTS_STATUS_CANCELLED; } +static llama_dart_tts_model_traits +llama_dart_tts_traits(const mtmd_context *mtmd, + llama_dart_tts_model_type type) { + llama_dart_tts_model_traits traits; + traits.speaker_encoder = mtmd_support_audio(mtmd); +#if LLAMADART_MTMD_HAS_GEN_VOICES + traits.predefined_voices = mtmd_gen_audio_get_info(mtmd).n_voices > 0; +#endif +#if LLAMADART_MTMD_HAS_CHATTERBOX + // The bundled helper tells Multilingual from Turbo by this table; a size + // query reads no tensor data. + traits.multilingual = + type == LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX && + mtmd_gen_audio_read_tensor(const_cast(mtmd), + "a.gen.t3.text_pos_emb", nullptr, 0) > 0; +#else + (void)type; +#endif + return traits; +} + static uint32_t llama_dart_tts_capabilities( const mtmd_context *mtmd, llama_dart_tts_model_type type) { - return llama_dart_tts_model_capabilities( - type, - type == LLAMA_DART_TTS_MODEL_TYPE_QWEN3 && mtmd_support_audio(mtmd)); + return llama_dart_tts_model_capabilities(type, + llama_dart_tts_traits(mtmd, type)); +} + +static int32_t llama_dart_tts_voice_count(const mtmd_context *mtmd, + llama_dart_tts_model_type type, + uint32_t capabilities) { + if ((capabilities & LLAMA_DART_TTS_CAPABILITY_VOICE) == 0) { + return 0; + } +#if LLAMADART_MTMD_HAS_GEN_VOICES + (void)type; + return std::max(0, mtmd_gen_audio_get_info(mtmd).n_voices); +#else + (void)mtmd; + return type == LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO ? 2 : 0; +#endif +} + +static const char *llama_dart_tts_voice_name_at(const mtmd_context *mtmd, + llama_dart_tts_model_type type, + int32_t index) { +#if LLAMADART_MTMD_HAS_GEN_VOICES + (void)type; + return mtmd_gen_audio_voice_name(mtmd, index); +#else + (void)mtmd; + return type == LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO + ? llama_dart_tts_lfm3_voice_name(index) + : nullptr; +#endif +} + +// The listed name that voice selects, or nullptr for an unknown voice. +static const char *llama_dart_tts_find_voice(const llama_dart_tts *tts, + const char *voice) { + const int32_t count = llama_dart_tts_voice_count( + tts->mtmd, tts->model_type, tts->capabilities); + for (int32_t i = 0; i < count; ++i) { + const char *name = llama_dart_tts_voice_name_at(tts->mtmd, + tts->model_type, i); + if (llama_dart_tts_voice_name_equal(name, voice)) { + return name; + } + } + return nullptr; } static llama_sampler * -llama_dart_tts_sampler_init(const llama_dart_tts_request &request, +llama_dart_tts_sampler_init(const llama_vocab *vocab, + const llama_dart_tts_request &request, uint32_t seed) { llama_sampler *sampler = llama_sampler_chain_init(llama_sampler_chain_default_params()); if (sampler == nullptr) { return nullptr; } + // The GGUF's suppress tokens, which upstream common_sampler applies: the + // Chatterbox converter suppresses every text token, so that the backbone + // samples speech tokens only, and the Qwen3-TTS one the codec's control + // tokens. + int32_t n_suppress = 0; + const llama_token *suppress = + llama_vocab_get_suppress_tokens(vocab, &n_suppress); + if (suppress != nullptr && n_suppress > 0) { + std::vector bias; + bias.reserve(static_cast(n_suppress)); + for (int32_t i = 0; i < n_suppress; ++i) { + bias.push_back({suppress[i], -INFINITY}); + } + llama_sampler_chain_add( + sampler, llama_sampler_init_logit_bias(llama_vocab_n_tokens(vocab), + static_cast(bias.size()), + bias.data())); + } llama_sampler_chain_add(sampler, llama_sampler_init_top_k(request.top_k)); llama_sampler_chain_add(sampler, llama_sampler_init_top_p(request.top_p, 1)); @@ -2082,12 +2165,18 @@ static struct llama_dart_tts *llama_dart_tts_init_impl( : llama_dart_tts_accepted_model_type( mtmd_gen_audio_get_info(mtmd).type, accepted_model_types); + const llama_dart_tts_model_traits traits = + mtmd == nullptr ? llama_dart_tts_model_traits{} + : llama_dart_tts_traits(mtmd, model_type); const bool supported = model_type != LLAMA_DART_TTS_MODEL_TYPE_NONE && model_type != LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN && (model_type != LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO || (llama != nullptr && - llama_model_chat_template(llama_get_model(llama), "tts") != nullptr)); + llama_model_chat_template(llama_get_model(llama), "tts") != nullptr)) && + (!traits.multilingual || + (llama != nullptr && + llama_dart_tts_cfg_sequence(llama_n_seq_max(llama), 0) >= 0)); if (llama == nullptr || mtmd == nullptr || !supported) { if (out_status != nullptr && llama != nullptr && mtmd != nullptr) { *out_status = LLAMA_DART_TTS_STATUS_UNSUPPORTED; @@ -2112,7 +2201,8 @@ static struct llama_dart_tts *llama_dart_tts_init_impl( tts->mtmd = mtmd; tts->generator = generator; tts->model_type = model_type; - tts->capabilities = llama_dart_tts_capabilities(mtmd, model_type); + tts->capabilities = llama_dart_tts_model_capabilities(model_type, traits); + tts->paired_cfg = traits.multilingual; tts = llama_dart_exit_track_created(tts, llama_dart_tts_free_object, LLAMA_DART_EXIT_STAGE_SESSION, llama, mtmd); if (out_status != nullptr) { @@ -2182,20 +2272,53 @@ static enum llama_dart_tts_status llama_dart_tts_start_impl( return llama_dart_tts_error(tts, LLAMA_DART_TTS_STATUS_UNSUPPORTED, "the TTS model does not select voices"); } - if (!llama_dart_tts_voice_supported(tts->model_type, voice)) { + const char *voice_name = + voice != nullptr ? llama_dart_tts_find_voice(tts, voice) : nullptr; + if (voice != nullptr && voice_name == nullptr) { return llama_dart_tts_error(tts, LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT, "unknown TTS voice"); } - if (llama_dart_tts_rejects_speaker_reference(tts->model_type) && - request->speaker_audio_length > 0) { + const bool has_speaker = request->speaker_audio_length > 0; + if (has_speaker && !llama_dart_tts_accepts_speaker_reference( + tts->model_type, tts->capabilities)) { return llama_dart_tts_error(tts, LLAMA_DART_TTS_STATUS_UNSUPPORTED, "the TTS model takes no speaker reference"); } + if (has_speaker && voice != nullptr) { + return llama_dart_tts_error( + tts, LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT, + "a voice and a speaker reference cannot be combined"); + } if (!llama_dart_tts_language_supported(tts->capabilities, request->language)) { return llama_dart_tts_error(tts, LLAMA_DART_TTS_STATUS_UNSUPPORTED, "the TTS model takes no language"); } + const bool voice_conditions = + llama_dart_tts_voice_is_conditioning(tts->model_type); + if (voice_conditions && voice_name == nullptr && !has_speaker && + llama_dart_tts_voice_count(tts->mtmd, tts->model_type, + tts->capabilities) > 0) { + // Upstream llama-tts and llama-server speak with the first voice; Pocket + // TTS gives near silence without one. + voice_name = llama_dart_tts_voice_name_at(tts->mtmd, tts->model_type, 0); + } + if (llama_dart_tts_requires_conditioning(tts->model_type) && + voice_name == nullptr && !has_speaker) { + return llama_dart_tts_error( + tts, LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT, + "the TTS model needs a speaker reference or a voice"); + } + const int32_t cfg_sequence_id = + tts->paired_cfg + ? llama_dart_tts_cfg_sequence(llama_n_seq_max(tts->llama), + request->sequence_id) + : -1; + if (tts->paired_cfg && cfg_sequence_id < 0) { + return llama_dart_tts_error( + tts, LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT, + "sequence_id must be below half of the context's n_seq_max"); + } llama_dart_tts_release_task_resources(tts); tts->pcm.clear(); @@ -2211,9 +2334,23 @@ static enum llama_dart_tts_status llama_dart_tts_start_impl( tts->max_frames = request->max_frames; tts->language = request->language != nullptr ? request->language : ""; + tts->cfg_sequence_id = cfg_sequence_id; llama_memory_seq_rm(llama_get_memory(tts->llama), tts->sequence_id, 0, -1); + if (tts->cfg_sequence_id >= 0) { + llama_memory_seq_rm(llama_get_memory(tts->llama), tts->cfg_sequence_id, 0, + -1); + } tts->owns_sequence = true; - if (request->speaker_audio_length > 0) { + if (voice_conditions && voice_name != nullptr) { +#if LLAMADART_MTMD_HAS_GEN_VOICES + tts->speaker = mtmd_gen_audio_get_voice(tts->mtmd, voice_name); +#endif + if (tts->speaker == nullptr) { + return llama_dart_tts_fail(tts, LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR, + "TTS voice lookup failed"); + } + } + if (has_speaker) { mtmd_helper_bitmap_wrapper wrapper = llama_dart_bitmap_from_buffer( tts->mtmd, request->speaker_audio, request->speaker_audio_length); if (wrapper.bitmap == nullptr || !mtmd_bitmap_is_audio(wrapper.bitmap)) { @@ -2230,7 +2367,8 @@ static enum llama_dart_tts_status llama_dart_tts_start_impl( std::random_device random_seed; const uint32_t seed = llama_dart_tts_resolve_seed(request->seed, [&] { return random_seed(); }); - tts->sampler = llama_dart_tts_sampler_init(*request, seed); + tts->sampler = llama_dart_tts_sampler_init( + llama_model_get_vocab(llama_get_model(tts->llama)), *request, seed); if (tts->sampler == nullptr) { return llama_dart_tts_fail(tts, LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR, "sampler initialization failed"); @@ -2243,7 +2381,7 @@ static enum llama_dart_tts_status llama_dart_tts_start_impl( common_chat_templates_init(llama_get_model(tts->llama), ""); prompt = common_chat_get_tts_prompt( templates.get(), std::string(request->text, request->text_length), - tts->language, voice != nullptr ? voice : ""); + tts->language, voice_name != nullptr ? voice_name : ""); if (prompt.empty()) { return llama_dart_tts_fail(tts, LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR, "TTS chat template rendering failed"); @@ -2313,6 +2451,76 @@ LLAMADART_API enum llama_dart_tts_status llama_dart_tts_start_with_voice( tts, [=] { return llama_dart_tts_start_impl(tts, request, voice); }); } +// The model type the caller accepted and this build drives, else NONE or +// UNKNOWN; *out_capabilities is its capability mask. +static llama_dart_tts_model_type +llama_dart_tts_listed_model_type(const mtmd_context *mtmd, + uint32_t accepted_model_types, + uint32_t *out_capabilities) { + const llama_dart_tts_model_type type = llama_dart_tts_accepted_model_type( + mtmd_gen_audio_get_info(mtmd).type, accepted_model_types); + *out_capabilities = llama_dart_tts_capabilities(mtmd, type); + return type; +} + +LLAMADART_API enum llama_dart_tts_status +llama_dart_tts_get_voice_count(const struct mtmd_context *mtmd, + uint32_t accepted_model_types, + int32_t *out_count) { + return llama_dart_barrier(LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR, [=] { + if (mtmd == nullptr || out_count == nullptr) { + return LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT; + } + *out_count = 0; + uint32_t capabilities = 0; + const llama_dart_tts_model_type type = llama_dart_tts_listed_model_type( + mtmd, accepted_model_types, &capabilities); + if (type == LLAMA_DART_TTS_MODEL_TYPE_NONE || + type == LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN) { + return LLAMA_DART_TTS_STATUS_UNSUPPORTED; + } + *out_count = llama_dart_tts_voice_count(mtmd, type, capabilities); + return LLAMA_DART_TTS_STATUS_OK; + }); +} + +LLAMADART_API enum llama_dart_tts_status llama_dart_tts_get_voice_name( + const struct mtmd_context *mtmd, uint32_t accepted_model_types, + int32_t index, char *out_name, size_t out_capacity, size_t *out_length) { + return llama_dart_barrier(LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR, [=] { + if (mtmd == nullptr || out_length == nullptr || + (out_name == nullptr && out_capacity != 0)) { + return LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT; + } + *out_length = 0; + uint32_t capabilities = 0; + const llama_dart_tts_model_type type = llama_dart_tts_listed_model_type( + mtmd, accepted_model_types, &capabilities); + if (type == LLAMA_DART_TTS_MODEL_TYPE_NONE || + type == LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN) { + return LLAMA_DART_TTS_STATUS_UNSUPPORTED; + } + if (index < 0 || + index >= llama_dart_tts_voice_count(mtmd, type, capabilities)) { + return LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT; + } + const char *name = llama_dart_tts_voice_name_at(mtmd, type, index); + if (name == nullptr) { + return LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR; + } + const size_t length = std::strlen(name); + *out_length = length; + if (out_name == nullptr) { + return LLAMA_DART_TTS_STATUS_OK; + } + if (out_capacity <= length) { + return LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT; + } + std::memcpy(out_name, name, length + 1); + return LLAMA_DART_TTS_STATUS_OK; + }); +} + static enum llama_dart_tts_status llama_dart_tts_step_impl( struct llama_dart_tts *tts, struct llama_dart_tts_progress *out_progress) { diff --git a/src/llama_dart_wrapper.h b/src/llama_dart_wrapper.h index 649a162e..2a9bb676 100644 --- a/src/llama_dart_wrapper.h +++ b/src/llama_dart_wrapper.h @@ -72,6 +72,10 @@ enum llama_dart_tts_model_type { LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO = 2, // Reported only to callers that accept it, see llama_dart_tts_get_info_ext. LLAMA_DART_TTS_MODEL_TYPE_SOPRANO = 3, + // Reported only to callers that accept it, see llama_dart_tts_get_info_ext. + LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX = 4, + // Reported only to callers that accept it, see llama_dart_tts_get_info_ext. + LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS = 5, LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN = 255, }; @@ -968,9 +972,39 @@ LLAMADART_API const char * llama_dart_tts_last_error( // next chunk boundary. Fewer than two frames fail that step with // UPSTREAM_ERROR. request->seed seeds the backbone sampler, the only sampler. +// CHATTERBOX (Chatterbox Turbo and Multilingual V3) and POCKET_TTS speak +// with a predefined voice of the projector or clone a speaker reference; +// see llama_dart_tts_get_voice_count. A voice and a speaker reference together +// are INVALID_ARGUMENT, and a speaker reference needs +// LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE, else UNSUPPORTED. With neither, +// the first predefined voice speaks, as in upstream llama-tts; a Chatterbox +// without predefined voices then returns INVALID_ARGUMENT, and Pocket TTS +// speaks unconditioned. Both return complete PCM. +// +// CHATTERBOX samples backbone tokens with the request's sampling settings; +// request->seed seeds that sampler and the flow decoder. It decodes the whole +// utterance's audio on the step that ends generation, which a cancel +// interrupts as for SOPRANO. Turbo has no capability bit for a language and +// rejects one. Multilingual reports LANGUAGE: request->language is a code +// such as "fr", not validated, that upstream lower-cases and prefixes to the +// text. Multilingual decodes an unconditional twin of the task sequence +// for classifier-free guidance at sequence n_seq_max / 2 + sequence_id, which +// the task owns and clears like its own: llama_dart_tts_init_ext returns +// UNSUPPORTED for a context with n_seq_max < 2, and a request whose +// sequence_id is not below n_seq_max / 2 is INVALID_ARGUMENT. Without +// kv_unified each of the two sequences holds n_ctx / n_seq_max positions. +// +// All backbone samplers apply the GGUF's tokenizer.ggml.suppress_tokens, as +// upstream common_sampler does: Chatterbox suppresses its text tokens. +// +// POCKET_TTS generates from the hidden state with the sampling settings of +// its weights: request top_k, top_p, min_p and temperature are validated but +// unused, and request->seed seeds the flow decoder. It has no language +// capability: the language is that of the weights. + // Returns the mask of model types llama_dart_tts_init_ext can create in this -// build. QWEN3 is always set; LFM3_AUDIO and SOPRANO only when the bundled -// mtmd has their generators. +// build. QWEN3 is always set; LFM3_AUDIO, SOPRANO, CHATTERBOX and POCKET_TTS +// only when the bundled mtmd has their generators. LLAMADART_API uint32_t llama_dart_tts_supported_model_types(void); LLAMADART_API enum llama_dart_tts_status llama_dart_tts_get_info_ext( @@ -987,13 +1021,38 @@ LLAMADART_API struct llama_dart_tts * llama_dart_tts_init_ext( // llama_dart_tts_start with a voice; NULL is the model's default voice and // otherwise identical to llama_dart_tts_start. A voice needs -// LLAMA_DART_TTS_CAPABILITY_VOICE, else UNSUPPORTED. LFM3_AUDIO voices are -// "female" (default) and "male", in any case; others are INVALID_ARGUMENT. +// LLAMA_DART_TTS_CAPABILITY_VOICE, else UNSUPPORTED. It is one of the names +// llama_dart_tts_get_voice_name lists, matched in any case; any other name is +// INVALID_ARGUMENT, never a fallback to the default. LFM3_AUDIO voices are +// "female" (default) and "male". LLAMADART_API enum llama_dart_tts_status llama_dart_tts_start_with_voice( struct llama_dart_tts * tts, const struct llama_dart_tts_request * request, const char * voice); +// Writes the number of voices llama_dart_tts_start_with_voice accepts for the +// projector, 0 for a model without LLAMA_DART_TTS_CAPABILITY_VOICE. A model +// type outside accepted_model_types, or one this build cannot drive, is +// UNSUPPORTED as in llama_dart_tts_get_info_ext, with *out_count 0. +LLAMADART_API enum llama_dart_tts_status llama_dart_tts_get_voice_count( + const struct mtmd_context * mtmd, + uint32_t accepted_model_types, + int32_t * out_count); + +// Copies the index-th voice name, NUL-terminated, into out_name and writes +// its length without the NUL to *out_length. out_name may be NULL with +// out_capacity 0 to query the length. An index outside +// [0, voice count), or an out_capacity not above the length, is +// INVALID_ARGUMENT; the latter still writes *out_length. The order is +// upstream's; index 0 is the voice used when a request names none. +LLAMADART_API enum llama_dart_tts_status llama_dart_tts_get_voice_name( + const struct mtmd_context * mtmd, + uint32_t accepted_model_types, + int32_t index, + char * out_name, + size_t out_capacity, + size_t * out_length); + // Creates a sampler that applies llama.cpp's reasoning-token budget before an // optional grammar sampler. The returned sampler owns grammar_sampler. // diff --git a/tests/test_expected_tts_model_types.py b/tests/test_expected_tts_model_types.py index d0f513aa..1f14cafa 100644 --- a/tests/test_expected_tts_model_types.py +++ b/tests/test_expected_tts_model_types.py @@ -9,16 +9,24 @@ import expected_tts_model_types as expected HEADER = ROOT / 'src/llama_dart_wrapper.h' -QWEN3, LFM3, SOPRANO = 1 << 1, 1 << 2, 1 << 3 - -MTMD = 'enum mtmd_gen_audio_type {\n MTMD_GEN_AUDIO_TYPE_NONE = 0,\n MTMD_GEN_AUDIO_TYPE_QWEN3TTS,\n%s};\n' - - -def checkout(root: Path, *, soprano=False, lfm3_enum=False, helper=False, prompt=False) -> Path: - enums = (' MTMD_GEN_AUDIO_TYPE_SOPRANO,\n' if soprano else '') + ( - ' MTMD_GEN_AUDIO_TYPE_LFM3A,\n' if lfm3_enum else '') +QWEN3, LFM3, SOPRANO, CHATTERBOX, POCKET = 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5 + +MTMD = 'enum mtmd_gen_audio_type {\n MTMD_GEN_AUDIO_TYPE_NONE = 0,\n MTMD_GEN_AUDIO_TYPE_QWEN3TTS,\n%s};\n%s' + + +def checkout(root: Path, *, soprano=False, lfm3_enum=False, helper=False, prompt=False, + pocket_enum=False, chatterbox_enum=False, voices=False, read_tensor=False) -> Path: + enums = ''.join( + f' MTMD_GEN_AUDIO_TYPE_{name},\n' + for name, present in (('POCKETTTS', pocket_enum), ('SOPRANO', soprano), ('LFM3A', lfm3_enum), + ('CHATTERBOX', chatterbox_enum)) + if present) + functions = ('mtmd_bitmap * mtmd_gen_audio_get_voice(const mtmd_context * ctx, const char * name);\n' + if voices else '') + ( + 'size_t mtmd_gen_audio_read_tensor(mtmd_context * ctx, const char * name, float * out, size_t n_max);\n' + if read_tensor else '') for name, text in { - 'tools/mtmd/mtmd.h': MTMD % enums, + 'tools/mtmd/mtmd.h': MTMD % (enums, functions), 'tools/mtmd/mtmd-helper.h': 'bool mtmd_helper_gen_audio_next_is_text(void*);\n' if helper else '', 'common/chat.h': 'std::string common_chat_get_tts_prompt();\n' if prompt else '', }.items(): @@ -45,7 +53,21 @@ def test_lfm3_needs_the_enumerator_the_helper_and_the_prompt_function(self) -> N self.assertEqual(QWEN3, self.mask(**missing), missing) def test_the_v080_shape_reports_the_mask_the_macos_and_android_bundles_do(self) -> None: - self.assertEqual(0xE, self.mask(soprano=True, lfm3_enum=True, helper=True, prompt=True)) + self.assertEqual(0xE, self.mask(soprano=True, lfm3_enum=True, helper=True, prompt=True, pocket_enum=True)) + + def test_pocket_tts_needs_voice_bitmaps(self) -> None: + self.assertEqual(QWEN3, self.mask(pocket_enum=True)) + self.assertEqual(QWEN3 | POCKET, self.mask(pocket_enum=True, voices=True)) + + def test_chatterbox_needs_the_enumerator_voices_and_tensor_reads(self) -> None: + self.assertEqual(QWEN3 | CHATTERBOX, self.mask(chatterbox_enum=True, voices=True, read_tensor=True)) + for missing in ({'voices': True, 'read_tensor': True}, {'chatterbox_enum': True, 'read_tensor': True}, + {'chatterbox_enum': True, 'voices': True}): + self.assertEqual(QWEN3, self.mask(**missing), missing) + + def test_the_v090_shape_reports_every_type(self) -> None: + self.assertEqual(0x3E, self.mask(soprano=True, lfm3_enum=True, helper=True, prompt=True, pocket_enum=True, + chatterbox_enum=True, voices=True, read_tensor=True)) def test_a_moved_mtmd_header_is_an_error_not_an_empty_answer(self) -> None: with tempfile.TemporaryDirectory() as tmp: diff --git a/tests/test_validate_exports.py b/tests/test_validate_exports.py index 799fdf82..cec29ff6 100644 --- a/tests/test_validate_exports.py +++ b/tests/test_validate_exports.py @@ -56,8 +56,8 @@ def test_speculative_retirement_inventory_retains_nextn_query(self): self.assertEqual(len(retiring), 15) required = set(validate_exports.DEFAULT_REQUIRED_SYMBOLS) self.assertFalse(required & retiring) - self.assertEqual(len(validate_exports.DEFAULT_REQUIRED_SYMBOLS), 92) - self.assertEqual(len(required), 92) + self.assertEqual(len(validate_exports.DEFAULT_REQUIRED_SYMBOLS), 94) + self.assertEqual(len(required), 94) self.assertIn('llama_dart_speculative_need_embd_nextn', required) self.assertEqual(len(validate_exports.RETIRED_SPECULATIVE_SYMBOLS), 15) self.assertEqual(set(validate_exports.RETIRED_SPECULATIVE_SYMBOLS), retiring) @@ -88,7 +88,7 @@ def test_full_surviving_export_inventory_is_accepted(self): result, diagnostics = self.validate_synthetic_exports( validate_exports.DEFAULT_REQUIRED_SYMBOLS) self.assertEqual(result, 0, diagnostics) - self.assertIn('Validated 92 required export(s)', diagnostics) + self.assertIn('Validated 94 required export(s)', diagnostics) def test_retired_embedding_query_fails_with_all_required_exports(self): result, diagnostics = self.validate_synthetic_exports([ diff --git a/tests/tts_api_test.c b/tests/tts_api_test.c index 36442904..dcd761b2 100644 --- a/tests/tts_api_test.c +++ b/tests/tts_api_test.c @@ -66,6 +66,8 @@ int main(void) { const uint32_t qwen3 = 1u << LLAMA_DART_TTS_MODEL_TYPE_QWEN3; const uint32_t lfm3 = 1u << LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO; const uint32_t soprano = 1u << LLAMA_DART_TTS_MODEL_TYPE_SOPRANO; + const uint32_t chatterbox = 1u << LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; + const uint32_t pocket = 1u << LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS; // Read from the checked-out llama.cpp headers, not from the build's own // probes, which would agree with a probe that wrongly compiled a type out. const char *expected_text = getenv("LLAMADART_EXPECTED_TTS_MODEL_TYPES"); @@ -73,8 +75,10 @@ int main(void) { const uint32_t expected = (uint32_t)strtoul(expected_text, NULL, 0); const uint32_t supported = llama_dart_tts_supported_model_types(); if (supported != expected) { - fprintf(stderr, "supported TTS model types 0x%x, expected 0x%x (qwen3 0x%x, lfm3 0x%x, soprano 0x%x)\n", - supported, expected, qwen3, lfm3, soprano); + fprintf(stderr, + "supported TTS model types 0x%x, expected 0x%x (qwen3 0x%x, lfm3 0x%x, soprano 0x%x, " + "chatterbox 0x%x, pocket 0x%x)\n", + supported, expected, qwen3, lfm3, soprano, chatterbox, pocket); } assert(supported == expected); info.struct_size = sizeof(info); @@ -88,6 +92,21 @@ int main(void) { assert(llama_dart_tts_start_with_voice(NULL, &request, NULL) == LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); assert(llama_dart_tts_start_with_voice(NULL, &request, "male") == LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); + const uint32_t all_types = qwen3 | lfm3 | soprano | chatterbox | pocket; + int32_t voice_count = -1; + assert(llama_dart_tts_get_voice_count(NULL, all_types, &voice_count) == LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); + assert(voice_count == -1); + assert(llama_dart_tts_get_voice_count(NULL, all_types, NULL) == LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); + char voice_name[16] = "unchanged"; + size_t voice_length = 7; + assert(llama_dart_tts_get_voice_name(NULL, all_types, 0, voice_name, sizeof(voice_name), &voice_length) == + LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); + assert(llama_dart_tts_get_voice_name(NULL, all_types, 0, NULL, 0, &voice_length) == + LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); + assert(llama_dart_tts_get_voice_name(NULL, all_types, 0, voice_name, sizeof(voice_name), NULL) == + LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT); + assert(voice_length == 7 && strcmp(voice_name, "unchanged") == 0); + // A failure that is not a caught exception leaves no last error. assert(llama_dart_last_error() == NULL); llama_dart_clear_last_error(); diff --git a/tests/tts_types_test.cpp b/tests/tts_types_test.cpp index 9d3dee08..04f9671d 100644 --- a/tests/tts_types_test.cpp +++ b/tests/tts_types_test.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace { @@ -15,6 +16,10 @@ constexpr uint32_t kLfm3 = llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO); constexpr uint32_t kSoprano = llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_SOPRANO); +constexpr uint32_t kChatterbox = + llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX); +constexpr uint32_t kPocket = + llama_dart_tts_model_type_bit(LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS); void legacy_mask_keeps_the_qwen3_only_contract() { assert(llama_dart_tts_legacy_model_types == kQwen3); @@ -83,69 +88,166 @@ void soprano_follows_the_build_and_the_mask() { #endif } +void chatterbox_and_pocket_follow_the_build_and_the_mask() { +#if LLAMADART_MTMD_HAS_CHATTERBOX && LLAMADART_MTMD_HAS_GEN_VOICES + assert((llama_dart_tts_build_model_types & kChatterbox) != 0); + assert(llama_dart_tts_accepted_model_type(MTMD_GEN_AUDIO_TYPE_CHATTERBOX, + kQwen3 | kChatterbox) == + LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX); + assert(llama_dart_tts_accepted_model_type(MTMD_GEN_AUDIO_TYPE_CHATTERBOX, + kQwen3 | kLfm3 | kSoprano | + kPocket) == + LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN); +#else + assert((llama_dart_tts_build_model_types & kChatterbox) == 0); +#endif +#if LLAMADART_MTMD_HAS_GEN_VOICES + assert((llama_dart_tts_build_model_types & kPocket) != 0); + assert(llama_dart_tts_accepted_model_type(MTMD_GEN_AUDIO_TYPE_POCKETTTS, + kQwen3 | kPocket) == + LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS); + assert(llama_dart_tts_accepted_model_type(MTMD_GEN_AUDIO_TYPE_POCKETTTS, + kQwen3 | kLfm3 | kSoprano | + kChatterbox) == + LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN); +#else + // Without voice bitmaps Pocket TTS keeps the refusal it had before. + assert((llama_dart_tts_build_model_types & kPocket) == 0); + assert(llama_dart_tts_accepted_model_type(MTMD_GEN_AUDIO_TYPE_POCKETTTS, + ~0u) == + LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN); +#endif +} + void family_behaviour() { const auto qwen3 = LLAMA_DART_TTS_MODEL_TYPE_QWEN3; const auto lfm3 = LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO; const auto soprano = LLAMA_DART_TTS_MODEL_TYPE_SOPRANO; + const auto chatterbox = LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; + const auto pocket = LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS; + constexpr uint32_t kSpeaker = LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE; assert(llama_dart_tts_primes_code_predictor(qwen3)); - assert(!llama_dart_tts_primes_code_predictor(lfm3)); - assert(!llama_dart_tts_primes_code_predictor(soprano)); + for (const auto type : {lfm3, soprano, chatterbox, pocket}) { + assert(!llama_dart_tts_primes_code_predictor(type)); + } assert(llama_dart_tts_samples_backbone_token(qwen3)); assert(!llama_dart_tts_samples_backbone_token(lfm3)); assert(llama_dart_tts_samples_backbone_token(soprano)); - assert(!llama_dart_tts_rejects_speaker_reference(qwen3)); - assert(llama_dart_tts_rejects_speaker_reference(lfm3)); - assert(llama_dart_tts_rejects_speaker_reference(soprano)); - assert(llama_dart_tts_voice_supported(soprano, nullptr)); - assert(!llama_dart_tts_voice_supported(soprano, "female")); + assert(llama_dart_tts_samples_backbone_token(chatterbox)); + assert(!llama_dart_tts_samples_backbone_token(pocket)); + // Qwen3-TTS keeps failing an undecodable reference at decode time. + assert(llama_dart_tts_accepts_speaker_reference(qwen3, 0)); + assert(!llama_dart_tts_accepts_speaker_reference(lfm3, kSpeaker)); + assert(!llama_dart_tts_accepts_speaker_reference(soprano, kSpeaker)); + for (const auto type : {chatterbox, pocket}) { + assert(llama_dart_tts_accepts_speaker_reference(type, kSpeaker)); + assert(!llama_dart_tts_accepts_speaker_reference(type, 0)); + } + assert(!llama_dart_tts_accepts_speaker_reference( + LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN, kSpeaker)); + assert(llama_dart_tts_voice_is_conditioning(chatterbox)); + assert(llama_dart_tts_voice_is_conditioning(pocket)); + for (const auto type : {qwen3, lfm3, soprano}) { + assert(!llama_dart_tts_voice_is_conditioning(type)); + } + assert(llama_dart_tts_requires_conditioning(chatterbox)); + for (const auto type : {qwen3, lfm3, soprano, pocket}) { + assert(!llama_dart_tts_requires_conditioning(type)); + } } void voices() { - const auto lfm3 = LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO; - assert(llama_dart_tts_voice_supported(lfm3, nullptr)); - assert(llama_dart_tts_voice_supported(lfm3, "female")); - assert(llama_dart_tts_voice_supported(lfm3, "male")); - assert(llama_dart_tts_voice_supported(lfm3, "MALE")); - assert(llama_dart_tts_voice_supported(lfm3, "Female")); - assert(!llama_dart_tts_voice_supported(lfm3, "")); - assert(!llama_dart_tts_voice_supported(lfm3, "mal")); - assert(!llama_dart_tts_voice_supported(lfm3, "males")); - assert(!llama_dart_tts_voice_supported(lfm3, "femalee")); - assert(!llama_dart_tts_voice_supported(lfm3, "child")); - assert(llama_dart_tts_voice_supported(LLAMA_DART_TTS_MODEL_TYPE_QWEN3, - nullptr)); - assert(!llama_dart_tts_voice_supported(LLAMA_DART_TTS_MODEL_TYPE_QWEN3, - "male")); + assert(llama_dart_tts_voice_name_equal("female", "female")); + assert(llama_dart_tts_voice_name_equal("female", "Female")); + assert(llama_dart_tts_voice_name_equal("male", "MALE")); + assert(llama_dart_tts_voice_name_equal("bill_boerst", "Bill_Boerst")); + assert(!llama_dart_tts_voice_name_equal("female", "")); + assert(!llama_dart_tts_voice_name_equal("male", "mal")); + assert(!llama_dart_tts_voice_name_equal("male", "males")); + assert(!llama_dart_tts_voice_name_equal("female", "femalee")); + assert(!llama_dart_tts_voice_name_equal("female", "child")); + assert(!llama_dart_tts_voice_name_equal(nullptr, "male")); + assert(!llama_dart_tts_voice_name_equal("male", nullptr)); + assert(std::strcmp(llama_dart_tts_lfm3_voice_name(0), "female") == 0); + assert(std::strcmp(llama_dart_tts_lfm3_voice_name(1), "male") == 0); + assert(llama_dart_tts_lfm3_voice_name(2) == nullptr); + assert(llama_dart_tts_lfm3_voice_name(-1) == nullptr); +} + +void cfg_sequence_is_half_the_context_away() { + // Upstream pairs sequence s with n_seq_max / 2 + s. + assert(llama_dart_tts_cfg_sequence(2, 0) == 1); + assert(llama_dart_tts_cfg_sequence(4, 1) == 3); + assert(llama_dart_tts_cfg_sequence(5, 1) == 3); + assert(llama_dart_tts_cfg_sequence(4, 2) == -1); + assert(llama_dart_tts_cfg_sequence(5, 2) == -1); + assert(llama_dart_tts_cfg_sequence(1, 0) == -1); + assert(llama_dart_tts_cfg_sequence(0, 0) == -1); + assert(llama_dart_tts_cfg_sequence(4, -1) == -1); + assert(llama_dart_tts_cfg_sequence(UINT32_MAX, INT32_MAX) == -1); } void capabilities_are_exact_per_model_type() { constexpr uint32_t kLanguage = LLAMA_DART_TTS_CAPABILITY_LANGUAGE; constexpr uint32_t kSpeaker = LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE; constexpr uint32_t kVoice = LLAMA_DART_TTS_CAPABILITY_VOICE; + llama_dart_tts_model_traits none; + llama_dart_tts_model_traits all; + all.speaker_encoder = true; + all.predefined_voices = true; + all.multilingual = true; + llama_dart_tts_model_traits encoder; + encoder.speaker_encoder = true; + llama_dart_tts_model_traits voices; + voices.predefined_voices = true; const auto qwen3 = LLAMA_DART_TTS_MODEL_TYPE_QWEN3; - assert(llama_dart_tts_model_capabilities(qwen3, true) == (kLanguage | kSpeaker)); - assert(llama_dart_tts_model_capabilities(qwen3, false) == kLanguage); + assert(llama_dart_tts_model_capabilities(qwen3, encoder) == + (kLanguage | kSpeaker)); + assert(llama_dart_tts_model_capabilities(qwen3, none) == kLanguage); // A voice is not selectable on Qwen3-TTS, so start_with_voice is UNSUPPORTED. - assert((llama_dart_tts_model_capabilities(qwen3, true) & kVoice) == 0); - assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO, - true) == (kLanguage | kVoice)); - assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_SOPRANO, - true) == 0); - assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_NONE, - true) == 0); - assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN, - true) == 0); + assert((llama_dart_tts_model_capabilities(qwen3, all) & kVoice) == 0); + for (const auto &traits : {none, all}) { + assert(llama_dart_tts_model_capabilities( + LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO, traits) == + (kLanguage | kVoice)); + assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_SOPRANO, + traits) == 0); + assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_NONE, + traits) == 0); + assert(llama_dart_tts_model_capabilities(LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN, + traits) == 0); + } + const auto chatterbox = LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; + assert(llama_dart_tts_model_capabilities(chatterbox, all) == + (kLanguage | kSpeaker | kVoice)); + // Turbo: a speaker encoder and the shipped voice, no language. + llama_dart_tts_model_traits turbo = all; + turbo.multilingual = false; + assert(llama_dart_tts_model_capabilities(chatterbox, turbo) == + (kSpeaker | kVoice)); + assert(llama_dart_tts_model_capabilities(chatterbox, encoder) == kSpeaker); + assert(llama_dart_tts_model_capabilities(chatterbox, voices) == kVoice); + const auto pocket = LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS; + // The language of Pocket TTS is that of its weights. + assert(llama_dart_tts_model_capabilities(pocket, all) == (kSpeaker | kVoice)); + assert(llama_dart_tts_model_capabilities(pocket, voices) == kVoice); + assert(llama_dart_tts_model_capabilities(pocket, encoder) == kSpeaker); + assert(llama_dart_tts_model_capabilities(pocket, none) == 0); } void a_generator_the_caller_did_not_accept_has_no_capabilities() { - // Legacy llama_dart_tts_get_info on an LFM3 or Soprano model. + // Legacy llama_dart_tts_get_info on any generator but Qwen3-TTS. for (int upstream = MTMD_GEN_AUDIO_TYPE_QWEN3TTS + 1; upstream < 64; ++upstream) { const auto type = llama_dart_tts_accepted_model_type( static_cast(upstream), llama_dart_tts_legacy_model_types); assert(type == LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN); - assert(llama_dart_tts_model_capabilities(type, true) == 0); + llama_dart_tts_model_traits all; + all.speaker_encoder = true; + all.predefined_voices = true; + all.multilingual = true; + assert(llama_dart_tts_model_capabilities(type, all) == 0); } } @@ -166,8 +268,10 @@ int main() { a_type_outside_the_mask_is_unknown(); lfm3_audio_follows_the_build(); soprano_follows_the_build_and_the_mask(); + chatterbox_and_pocket_follow_the_build_and_the_mask(); family_behaviour(); voices(); + cfg_sequence_is_half_the_context_away(); capabilities_are_exact_per_model_type(); a_generator_the_caller_did_not_accept_has_no_capabilities(); language_is_checked_against_the_capability(); diff --git a/tools/expected_tts_model_types.py b/tools/expected_tts_model_types.py index 2f35de00..ca4b2a5c 100644 --- a/tools/expected_tts_model_types.py +++ b/tools/expected_tts_model_types.py @@ -24,6 +24,21 @@ ("common/chat.h", r"\bcommon_chat_get_tts_prompt\b"), ), ), + ( + "CHATTERBOX", + ( + ("tools/mtmd/mtmd.h", r"^\s*MTMD_GEN_AUDIO_TYPE_CHATTERBOX\s*[,=]"), + ("tools/mtmd/mtmd.h", r"\bmtmd_gen_audio_read_tensor\b"), + ("tools/mtmd/mtmd.h", r"\bmtmd_gen_audio_get_voice\b"), + ), + ), + ( + "POCKET_TTS", + ( + ("tools/mtmd/mtmd.h", r"^\s*MTMD_GEN_AUDIO_TYPE_POCKETTTS\s*[,=]"), + ("tools/mtmd/mtmd.h", r"\bmtmd_gen_audio_get_voice\b"), + ), + ), ) diff --git a/tools/tts_voice_smoke.cpp b/tools/tts_voice_smoke.cpp new file mode 100644 index 00000000..3c05393d --- /dev/null +++ b/tools/tts_voice_smoke.cpp @@ -0,0 +1,492 @@ +// Local check of the opt-in Chatterbox and Pocket TTS generators and their +// predefined voices against real weights; see docs/tts_voices.md. +#include "llama_dart_wrapper.h" + +#include "llama.h" +#include "mtmd.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *const speech_text = "Hello from Llama Dart. How are you today?"; +static const char *const french_text = "Bonjour, comment allez-vous aujourd'hui ?"; + +static constexpr uint32_t qwen3_bit = 1u << LLAMA_DART_TTS_MODEL_TYPE_QWEN3; +static constexpr uint32_t chatterbox_bit = 1u << LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; +static constexpr uint32_t pocket_bit = 1u << LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS; +static constexpr uint32_t all_bits = qwen3_bit | (1u << LLAMA_DART_TTS_MODEL_TYPE_LFM3_AUDIO) | + (1u << LLAMA_DART_TTS_MODEL_TYPE_SOPRANO) | chatterbox_bit | + pocket_bit; + +struct llama_backend_guard { + llama_backend_guard() { llama_backend_init(); } + ~llama_backend_guard() { llama_backend_free(); } +}; + +using context_ptr = std::unique_ptr; +using tts_ptr = std::unique_ptr; + +static bool fail(const char *message) { + std::fprintf(stderr, "%s\n", message); + return false; +} + +static int die(const char *message) { + fail(message); + return 1; +} + +static void append_u16(std::vector &out, uint16_t value) { + out.push_back(static_cast(value)); + out.push_back(static_cast(value >> 8)); +} + +static void append_u32(std::vector &out, uint32_t value) { + for (int shift = 0; shift < 32; shift += 8) { + out.push_back(static_cast(value >> shift)); + } +} + +static std::vector wav16(const std::vector &pcm, int32_t sample_rate) { + std::vector out; + const uint32_t data_size = static_cast(pcm.size() * 2); + const char *riff = "RIFF"; + out.insert(out.end(), riff, riff + 4); + append_u32(out, 36 + data_size); + const char *fmt = "WAVEfmt "; + out.insert(out.end(), fmt, fmt + 8); + append_u32(out, 16); + append_u16(out, 1); + append_u16(out, 1); + append_u32(out, static_cast(sample_rate)); + append_u32(out, static_cast(sample_rate * 2)); + append_u16(out, 2); + append_u16(out, 16); + const char *data = "data"; + out.insert(out.end(), data, data + 4); + append_u32(out, data_size); + for (float sample : pcm) { + const float clipped = std::max(-1.0f, std::min(1.0f, sample)); + append_u16(out, static_cast(static_cast(std::lrintf(clipped * 32767.0f)))); + } + return out; +} + +static bool write_file(const std::string &path, const std::vector &bytes) { + std::ofstream out(path, std::ios::binary); + out.write(reinterpret_cast(bytes.data()), static_cast(bytes.size())); + return static_cast(out); +} + +static double finite_rms(const std::vector &pcm) { + double energy = 0.0; + for (float sample : pcm) { + if (!std::isfinite(sample)) { + return -1.0; + } + energy += static_cast(sample) * sample; + } + return pcm.empty() ? 0.0 : std::sqrt(energy / pcm.size()); +} + +static bool same_pcm(const std::vector &a, const std::vector &b) { + return a.size() == b.size() && std::memcmp(a.data(), b.data(), a.size() * sizeof(float)) == 0; +} + +static bool sequence_empty(llama_context *context, llama_seq_id sequence) { + return llama_memory_seq_pos_max(llama_get_memory(context), sequence) < 0; +} + +static context_ptr make_context(llama_model *model, uint32_t n_seq_max) { + llama_context_params params = llama_context_default_params(); + params.n_ctx = 8192; + params.n_batch = 512; + params.n_ubatch = 512; + params.n_seq_max = n_seq_max; + // As upstream llama-tts does for Chatterbox Multilingual's paired sequence. + params.kv_unified = true; + params.embeddings = true; + params.n_threads = 4; + params.n_threads_batch = 4; + return context_ptr(llama_init_from_model(model, params), llama_free); +} + +struct synthesis { + std::vector pcm; + llama_dart_tts_progress progress{}; +}; + +static bool synthesize(llama_dart_tts *tts, const llama_dart_tts_request &request, const char *voice, + int32_t sample_rate, synthesis *out) { + if (llama_dart_tts_start_with_voice(tts, &request, voice) != LLAMA_DART_TTS_STATUS_OK) { + std::fprintf(stderr, "failed to start TTS: %s\n", llama_dart_tts_last_error(tts)); + return false; + } + do { + out->progress.struct_size = sizeof(out->progress); + if (llama_dart_tts_step(tts, &out->progress) != LLAMA_DART_TTS_STATUS_OK) { + std::fprintf(stderr, "TTS step failed after %d frames: %s\n", out->progress.frames_generated, + llama_dart_tts_last_error(tts)); + return false; + } + } while (out->progress.state != LLAMA_DART_TTS_STATE_COMPLETED); + llama_dart_tts_output_info output{}; + output.struct_size = sizeof(output); + if (llama_dart_tts_get_output_info(tts, &output) != LLAMA_DART_TTS_STATUS_OK || + output.sample_rate != sample_rate || output.channels != 1 || output.sample_count <= 0) { + return die("invalid TTS output metadata"); + } + out->pcm.resize(static_cast(output.sample_count)); + size_t read = 0; + if (llama_dart_tts_read_pcm(tts, 0, out->pcm.data(), out->pcm.size(), &read) != LLAMA_DART_TTS_STATUS_OK || + read != out->pcm.size()) { + return fail("failed to read PCM"); + } + const double rms = finite_rms(out->pcm); + if (rms < 1e-4) { + std::fprintf(stderr, "PCM is non-finite or silent (rms %.6f)\n", rms); + return false; + } + return true; +} + +static bool list_voices(mtmd_context *mtmd, uint32_t bit, std::vector *voices) { + int32_t count = -1; + if (llama_dart_tts_get_voice_count(mtmd, qwen3_bit, &count) != LLAMA_DART_TTS_STATUS_UNSUPPORTED || count != 0) { + return fail("a mask without the generator listed its voices"); + } + if (llama_dart_tts_get_voice_count(mtmd, bit, &count) != LLAMA_DART_TTS_STATUS_OK || count <= 0) { + return fail("the projector lists no predefined voice"); + } + for (int32_t i = 0; i < count; ++i) { + size_t length = 0; + if (llama_dart_tts_get_voice_name(mtmd, bit, i, nullptr, 0, &length) != LLAMA_DART_TTS_STATUS_OK || + length == 0) { + return fail("voice name length query failed"); + } + std::string name(length + 1, '\0'); + size_t short_length = 0; + if (llama_dart_tts_get_voice_name(mtmd, bit, i, name.data(), length, &short_length) != + LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT || + short_length != length) { + return fail("a buffer without room for the NUL was accepted"); + } + if (llama_dart_tts_get_voice_name(mtmd, bit, i, name.data(), name.size(), &length) != + LLAMA_DART_TTS_STATUS_OK || + name[length] != '\0') { + return fail("voice name copy failed"); + } + name.resize(length); + voices->push_back(name); + } + size_t length = 0; + if (llama_dart_tts_get_voice_name(mtmd, bit, count, nullptr, 0, &length) != + LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT || + llama_dart_tts_get_voice_name(mtmd, bit, -1, nullptr, 0, &length) != + LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT) { + return fail("an out-of-range voice index was accepted"); + } + return true; +} + +static std::string upper(std::string text) { + std::transform(text.begin(), text.end(), text.begin(), + [](unsigned char c) { return static_cast(std::toupper(c)); }); + return text; +} + +static bool cancel_in_generation(llama_dart_tts *tts, const llama_dart_tts_request &request, + int *cancel_frames) { + std::atomic flag{0}; + static_assert(sizeof(std::atomic) == sizeof(int8_t), "the cancel flag must be a plain byte"); + if (llama_dart_tts_start(tts, &request) != LLAMA_DART_TTS_STATUS_OK || + llama_dart_tts_set_cancel_flag(tts, reinterpret_cast(&flag)) != + LLAMA_DART_TTS_STATUS_OK) { + return fail("failed to start the in-generation cancel probe"); + } + llama_dart_tts_progress progress{}; + for (;;) { + progress.struct_size = sizeof(progress); + const llama_dart_tts_status step = llama_dart_tts_step(tts, &progress); + if (step == LLAMA_DART_TTS_STATUS_CANCELLED) { + *cancel_frames = progress.frames_generated; + return true; + } + if (step != LLAMA_DART_TTS_STATUS_OK || progress.state == LLAMA_DART_TTS_STATE_COMPLETED) { + return fail("the in-generation cancel did not land"); + } + if (progress.frames_generated == 3) { + flag.store(1); + } + } +} + +int main(int argc, char **argv) { + bool use_gpu = false; + const char *speaker_path = nullptr; + std::vector positional; + for (int i = 1; i < argc; ++i) { + if (std::strcmp(argv[i], "--gpu") == 0) { + use_gpu = true; + } else if (std::strcmp(argv[i], "--speaker") == 0 && i + 1 < argc) { + speaker_path = argv[++i]; + } else { + positional.push_back(argv[i]); + } + } + if (positional.size() != 3) { + std::fprintf(stderr, "usage: %s MODEL MMPROJ OUTPUT_PREFIX [--speaker WAV] [--gpu]\n", argv[0]); + return 2; + } + const std::string output_prefix = positional[2]; + std::vector speaker_wav; + if (speaker_path != nullptr) { + std::ifstream in(speaker_path, std::ios::binary); + speaker_wav.assign(std::istreambuf_iterator(in), std::istreambuf_iterator()); + if (speaker_wav.empty()) { + return fail("failed to read the speaker reference"); + } + } + + const llama_backend_guard backend; + llama_dart_set_log_level(4); + llama_model_params model_params = llama_model_default_params(); + model_params.n_gpu_layers = use_gpu ? 99 : 0; + std::unique_ptr model( + llama_model_load_from_file(positional[0], model_params), llama_model_free); + if (model == nullptr) { + return die("failed to load model"); + } + context_ptr context = make_context(model.get(), 4); + if (context == nullptr) { + return die("failed to create context"); + } + mtmd_context_params mtmd_params = mtmd_context_params_default(); + mtmd_params.use_gpu = use_gpu; + mtmd_params.cb_eval = llama_dart_tts_eval_callback; + std::unique_ptr mtmd( + mtmd_init_from_file(positional[1], model.get(), mtmd_params), mtmd_free); + if (mtmd == nullptr) { + return die("failed to load mmproj"); + } + + llama_dart_tts_info info{}; + info.struct_size = sizeof(info); + if (llama_dart_tts_get_info_ext(mtmd.get(), all_bits, &info) != LLAMA_DART_TTS_STATUS_OK || + (info.model_type != LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX && + info.model_type != LLAMA_DART_TTS_MODEL_TYPE_POCKET_TTS)) { + return die("the projector is neither Chatterbox nor Pocket TTS, or this build cannot drive it"); + } + const bool chatterbox = info.model_type == LLAMA_DART_TTS_MODEL_TYPE_CHATTERBOX; + const uint32_t bit = chatterbox ? chatterbox_bit : pocket_bit; + const bool takes_language = (info.capabilities & LLAMA_DART_TTS_CAPABILITY_LANGUAGE) != 0; + const bool takes_speaker = (info.capabilities & LLAMA_DART_TTS_CAPABILITY_SPEAKER_REFERENCE) != 0; + if ((info.capabilities & LLAMA_DART_TTS_CAPABILITY_VOICE) == 0 || info.channels != 1 || + info.sample_rate <= 0 || (!chatterbox && takes_language)) { + return die("invalid capability metadata"); + } + + // Callers that did not opt in keep seeing UNKNOWN. + llama_dart_tts_info legacy{}; + legacy.struct_size = sizeof(legacy); + llama_dart_tts_status status = LLAMA_DART_TTS_STATUS_OK; + if (llama_dart_tts_get_info(mtmd.get(), &legacy) != LLAMA_DART_TTS_STATUS_UNSUPPORTED || + legacy.model_type != LLAMA_DART_TTS_MODEL_TYPE_UNKNOWN || + llama_dart_tts_init(context.get(), mtmd.get(), &status) != nullptr || + status != LLAMA_DART_TTS_STATUS_UNSUPPORTED || + llama_dart_tts_get_info_ext(mtmd.get(), all_bits & ~bit, &legacy) != LLAMA_DART_TTS_STATUS_UNSUPPORTED || + llama_dart_tts_init_ext(context.get(), mtmd.get(), all_bits & ~bit, &status) != nullptr || + status != LLAMA_DART_TTS_STATUS_UNSUPPORTED) { + return die("an export accepted a generator outside its mask"); + } + + std::vector voices; + if (!list_voices(mtmd.get(), bit, &voices)) { + return 1; + } + + if (takes_language) { + // The unconditional sequence needs a second sequence in the context. + context_ptr single = make_context(model.get(), 1); + status = LLAMA_DART_TTS_STATUS_OK; + if (single == nullptr || llama_dart_tts_init_ext(single.get(), mtmd.get(), bit, &status) != nullptr || + status != LLAMA_DART_TTS_STATUS_UNSUPPORTED) { + return die("Chatterbox Multilingual accepted a context without a paired sequence"); + } + } + + tts_ptr tts(llama_dart_tts_init_ext(context.get(), mtmd.get(), bit, &status), llama_dart_tts_free); + if (tts == nullptr || status != LLAMA_DART_TTS_STATUS_OK) { + std::fprintf(stderr, "failed to initialize TTS: %d\n", static_cast(status)); + return 1; + } + + llama_dart_tts_request request = llama_dart_tts_request_default(); + request.text = speech_text; + request.text_length = std::strlen(speech_text); + request.language = takes_language ? "en" : nullptr; + request.seed = 1; + + const unsigned char junk[] = {0}; + llama_dart_tts_request with_speaker = request; + with_speaker.speaker_audio = junk; + with_speaker.speaker_audio_length = sizeof(junk); + llama_dart_tts_request out_of_range = request; + out_of_range.sequence_id = 2; + llama_dart_tts_request with_language = request; + with_language.language = "fr"; + if (llama_dart_tts_start_with_voice(tts.get(), &request, "nobody") != LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT || + llama_dart_tts_start_with_voice(tts.get(), &request, "") != LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT || + llama_dart_tts_start_with_voice(tts.get(), &with_speaker, voices[0].c_str()) != + (takes_speaker ? LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT : LLAMA_DART_TTS_STATUS_UNSUPPORTED) || + (!takes_speaker && llama_dart_tts_start(tts.get(), &with_speaker) != LLAMA_DART_TTS_STATUS_UNSUPPORTED) || + (!takes_language && + llama_dart_tts_start(tts.get(), &with_language) != LLAMA_DART_TTS_STATUS_UNSUPPORTED) || + (takes_language && + llama_dart_tts_start(tts.get(), &out_of_range) != LLAMA_DART_TTS_STATUS_INVALID_ARGUMENT)) { + return die("request validation failed"); + } + + llama_dart_tts_progress progress{}; + progress.struct_size = sizeof(progress); + if (llama_dart_tts_start(tts.get(), &request) != LLAMA_DART_TTS_STATUS_OK) { + return die("failed to start the cancellation probe"); + } + llama_dart_tts_cancel(tts.get()); + if (llama_dart_tts_step(tts.get(), &progress) != LLAMA_DART_TTS_STATUS_CANCELLED || + progress.state != LLAMA_DART_TTS_STATE_CANCELLED || + llama_dart_tts_reset(tts.get()) != LLAMA_DART_TTS_STATUS_OK) { + return die("cancel before the first step failed"); + } + + synthesis first; + if (!synthesize(tts.get(), request, nullptr, info.sample_rate, &first)) { + return 1; + } + if (first.progress.truncated || first.progress.frames_generated <= 0) { + std::fprintf(stderr, "speech did not end on its own within %d frames\n", request.max_frames); + return 1; + } + // The task owns both sequences only while it runs. + if (!sequence_empty(context.get(), 0) || !sequence_empty(context.get(), 2)) { + return die("a completed task left its sequences in the context"); + } + + int cancel_frames = -1; + if (!cancel_in_generation(tts.get(), request, &cancel_frames)) { + return 1; + } + if (cancel_frames != 3 || !sequence_empty(context.get(), 0) || !sequence_empty(context.get(), 2) || + llama_dart_tts_reset(tts.get()) != LLAMA_DART_TTS_STATUS_OK) { + std::fprintf(stderr, "the in-generation cancel landed after %d frames or left its sequences\n", + cancel_frames); + return 1; + } + + // NULL is the first listed voice, and a voice matches in any case. + synthesis named; + llama_dart_tts_request reuse = request; + reuse.sequence_id = 1; + const std::string first_voice = upper(voices[0]); + if (!synthesize(tts.get(), reuse, first_voice.c_str(), info.sample_rate, &named)) { + return 1; + } + if (!same_pcm(first.pcm, named.pcm)) { + return die("the default voice is not the first listed voice, or reuse changed the PCM"); + } + if (!sequence_empty(context.get(), 1) || !sequence_empty(context.get(), 3)) { + return die("a completed task left its sequences in the context"); + } + + synthesis other; + if (voices.size() > 1) { + if (!synthesize(tts.get(), request, voices.back().c_str(), info.sample_rate, &other)) { + return 1; + } + if (same_pcm(first.pcm, other.pcm)) { + return die("the voice did not reach the generator"); + } + } + + synthesis reseeded; + llama_dart_tts_request seed_request = request; + seed_request.seed = request.seed + 1; + if (!synthesize(tts.get(), seed_request, nullptr, info.sample_rate, &reseeded)) { + return 1; + } + if (same_pcm(first.pcm, reseeded.pcm)) { + return die("the seed did not reach the generator"); + } + + synthesis cloned; + if (takes_speaker && !speaker_wav.empty()) { + llama_dart_tts_request clone = request; + clone.speaker_audio = speaker_wav.data(); + clone.speaker_audio_length = speaker_wav.size(); + if (!synthesize(tts.get(), clone, nullptr, info.sample_rate, &cloned)) { + return 1; + } + if (cloned.progress.truncated || same_pcm(first.pcm, cloned.pcm)) { + return die("the speaker reference did not condition the speech, or it did not end"); + } + } else if (!speaker_wav.empty()) { + llama_dart_tts_request clone = request; + clone.speaker_audio = speaker_wav.data(); + clone.speaker_audio_length = speaker_wav.size(); + if (llama_dart_tts_start(tts.get(), &clone) != LLAMA_DART_TTS_STATUS_UNSUPPORTED) { + return die("a projector without a speaker encoder accepted a speaker reference"); + } + } + + synthesis french; + if (takes_language) { + llama_dart_tts_request french_request = request; + french_request.text = french_text; + french_request.text_length = std::strlen(french_text); + french_request.language = "fr"; + if (!synthesize(tts.get(), french_request, nullptr, info.sample_rate, &french)) { + return 1; + } + if (french.progress.truncated) { + return die("the French speech did not end"); + } + } + + llama_dart_tts_request short_request = request; + short_request.max_frames = 4; + synthesis truncated; + if (!synthesize(tts.get(), short_request, nullptr, info.sample_rate, &truncated) || + !truncated.progress.truncated || truncated.progress.frames_generated != 4) { + return die("max_frames did not truncate the speech"); + } + if (llama_dart_tts_reset(tts.get()) != LLAMA_DART_TTS_STATUS_OK) { + return die("final reset failed"); + } + + if (!write_file(output_prefix + "-default.wav", wav16(first.pcm, info.sample_rate)) || + (!other.pcm.empty() && + !write_file(output_prefix + "-" + voices.back() + ".wav", wav16(other.pcm, info.sample_rate))) || + (!cloned.pcm.empty() && !write_file(output_prefix + "-cloned.wav", wav16(cloned.pcm, info.sample_rate))) || + (!french.pcm.empty() && !write_file(output_prefix + "-fr.wav", wav16(french.pcm, info.sample_rate)))) { + return die("failed to write WAV output"); + } + std::printf("PASS type=%s backend=%s capabilities=0x%x voices=%zu first_voice=%s last_voice=%s " + "sample_rate=%d frames=%d samples=%zu rms=%.6f last_voice_frames=%d cloned_frames=%d " + "cancel_frames=%d\n", + chatterbox ? (takes_language ? "chatterbox-multilingual" : "chatterbox-turbo") : "pocket-tts", + use_gpu ? "gpu" : "cpu", info.capabilities, voices.size(), voices.front().c_str(), + voices.back().c_str(), info.sample_rate, first.progress.frames_generated, first.pcm.size(), + finite_rms(first.pcm), other.progress.frames_generated, cloned.progress.frames_generated, + cancel_frames); + return 0; +} diff --git a/tools/validate_exports.py b/tools/validate_exports.py index a14f4c46..6cf34c93 100644 --- a/tools/validate_exports.py +++ b/tools/validate_exports.py @@ -92,6 +92,8 @@ "llama_dart_tts_get_info_ext", "llama_dart_tts_init_ext", "llama_dart_tts_start_with_voice", + "llama_dart_tts_get_voice_count", + "llama_dart_tts_get_voice_name", "llama_dart_cancel_flag_abort_callback", "llama_dart_mtmd_eval_callback", "llama_dart_mtmd_encode_chunk_cancellable", From 3c763c522ced3155ec391702e7a7f62f4b1a2788 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Sat, 7 Nov 2026 11:23:39 -0500 Subject: [PATCH 5/5] Move the suppress-token sampler change to its own PR The talker sampler fix is #180; Chatterbox depends on it. --- docs/tts_voices.md | 15 +++++++-------- src/llama_dart_wrapper.cpp | 24 ++---------------------- src/llama_dart_wrapper.h | 4 ++-- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/docs/tts_voices.md b/docs/tts_voices.md index 47b2f5fb..218a2cc4 100644 --- a/docs/tts_voices.md +++ b/docs/tts_voices.md @@ -80,15 +80,14 @@ move this check with it. ## Sampling and suppress tokens -The wrapper's TTS sampler now applies the GGUF's +Chatterbox needs the talker sampler to apply the GGUF's `tokenizer.ggml.suppress_tokens` as `-inf` logit biases, as upstream -`common_sampler` does. Without it Chatterbox draws text tokens: with seeds 2, -3 and 5 its first token was GPT-2 `<|endoftext|>` (an end-of-generation token), -which ends the utterance with no audio. Upstream `llama-tts` gave 61 to 72 -frames for seeds 1 to 8 with the same settings. The Qwen3-TTS converter also -suppresses 1023 codec control tokens, so Qwen3-TTS now samples as upstream does -too; its smoke and transcription still pass, but a fixed seed may not repeat -the PCM of earlier wrappers. Soprano writes no suppress tokens. +`common_sampler` does; [#180](https://github.com/leehack/llamadart-native/pull/180) +adds that. Its converter suppresses every text token. Without the bias +Chatterbox draws them: with seeds 2, 3 and 5 its first token was GPT-2 +`<|endoftext|>` (an end-of-generation token), which ends the utterance with no +audio. Upstream `llama-tts` gave 61 to 72 frames for seeds 1 to 8 with the same +settings. The Chatterbox GGUFs embed upstream's defaults in `general.sampling.*`: Turbo `top_k 1000`, `top_p 0.95`, `min_p 0`, `temp 0.8`; Multilingual `top_k 0`, diff --git a/src/llama_dart_wrapper.cpp b/src/llama_dart_wrapper.cpp index 654346da..2bec77ef 100644 --- a/src/llama_dart_wrapper.cpp +++ b/src/llama_dart_wrapper.cpp @@ -179,32 +179,13 @@ static const char *llama_dart_tts_find_voice(const llama_dart_tts *tts, } static llama_sampler * -llama_dart_tts_sampler_init(const llama_vocab *vocab, - const llama_dart_tts_request &request, +llama_dart_tts_sampler_init(const llama_dart_tts_request &request, uint32_t seed) { llama_sampler *sampler = llama_sampler_chain_init(llama_sampler_chain_default_params()); if (sampler == nullptr) { return nullptr; } - // The GGUF's suppress tokens, which upstream common_sampler applies: the - // Chatterbox converter suppresses every text token, so that the backbone - // samples speech tokens only, and the Qwen3-TTS one the codec's control - // tokens. - int32_t n_suppress = 0; - const llama_token *suppress = - llama_vocab_get_suppress_tokens(vocab, &n_suppress); - if (suppress != nullptr && n_suppress > 0) { - std::vector bias; - bias.reserve(static_cast(n_suppress)); - for (int32_t i = 0; i < n_suppress; ++i) { - bias.push_back({suppress[i], -INFINITY}); - } - llama_sampler_chain_add( - sampler, llama_sampler_init_logit_bias(llama_vocab_n_tokens(vocab), - static_cast(bias.size()), - bias.data())); - } llama_sampler_chain_add(sampler, llama_sampler_init_top_k(request.top_k)); llama_sampler_chain_add(sampler, llama_sampler_init_top_p(request.top_p, 1)); @@ -2367,8 +2348,7 @@ static enum llama_dart_tts_status llama_dart_tts_start_impl( std::random_device random_seed; const uint32_t seed = llama_dart_tts_resolve_seed(request->seed, [&] { return random_seed(); }); - tts->sampler = llama_dart_tts_sampler_init( - llama_model_get_vocab(llama_get_model(tts->llama)), *request, seed); + tts->sampler = llama_dart_tts_sampler_init(*request, seed); if (tts->sampler == nullptr) { return llama_dart_tts_fail(tts, LLAMA_DART_TTS_STATUS_UPSTREAM_ERROR, "sampler initialization failed"); diff --git a/src/llama_dart_wrapper.h b/src/llama_dart_wrapper.h index 2a9bb676..2885ee37 100644 --- a/src/llama_dart_wrapper.h +++ b/src/llama_dart_wrapper.h @@ -994,8 +994,8 @@ LLAMADART_API const char * llama_dart_tts_last_error( // sequence_id is not below n_seq_max / 2 is INVALID_ARGUMENT. Without // kv_unified each of the two sequences holds n_ctx / n_seq_max positions. // -// All backbone samplers apply the GGUF's tokenizer.ggml.suppress_tokens, as -// upstream common_sampler does: Chatterbox suppresses its text tokens. +// Chatterbox relies on the talker sampler's GGUF suppress tokens to exclude +// its text tokens. // // POCKET_TTS generates from the hidden state with the sampling settings of // its weights: request top_k, top_p, min_p and temperature are validated but