From 2809b54943558503a182be7a9589ffbf86bf19ad Mon Sep 17 00:00:00 2001 From: Richard Loyer Date: Sat, 30 May 2026 12:38:47 +0200 Subject: [PATCH] CH chraac-llama : -18% RTF (2.43 -> 2.04) via swap ggml source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Découverte historique remise au jour : la mémoire 'TTS RTF<1 atteint via chraac-llama' (projet d'origine /opt/Kazeia, 02/05) documente que le décodeur TTS atteint RTF 0.96 avec ggml-cpu de chraac-llama (dev-refactoring commit 897501a) vs 1.47 avec llama-upstream (= notre ql/ggml actuel). Notre Kazeia-Engine builde contre ql/ggml = github.com/qualcomm/llama.cpp fork = essentiellement llama-upstream + hexagon backend. NEON heads optim sortie cette session a déjà compensé une partie mais pas tout. Validation reproductibilité : Bench historique decoder seul (T=56) sur Pad3 chargée : RTF 0.935 (legèrement mieux que 0.961 historique, batterie pleine + device froid). Build chraac variant : - libs runtime : copies de /opt/Kazeia/chraac-llama/build-android-kazeia/bin poussées dans /data/local/tmp/kz-engine/bin-chraac - libqwen3tts-decoder.a : rebuild fresh contre chraac/ggml dans /opt/Kazeia/kazeia-tts-decoder-ggml/build-android-chraac-fresh (code actuel avec load_with_backends + snake_consts) - tts_pipeline_chraac : linké contre ces libs, headers /opt/Kazeia/chraac-llama/include + ggml/include Mesure A/B Pad3 (KZTTS_THREADS=6 GGML_NUM_THREADS=8 seed=42) : Phrase 'Bonsoir, comment tu te sens ce soir ?' : Baseline ql/ggml : N=41 RTF 2.43 talker=31.5 cp=70.2 decoder/frame=98.1 ms chraac-llama : N=64 RTF 2.04 talker=31.2 cp=57.5 decoder/frame=76.9 ms Delta per-frame : -16% -1% -18% -22% Phrase 'Bonjour Kazeia' : Baseline : N=33 RTF 2.47 / Chraac : N=64 RTF 2.02 (Différence N = trajectoire diverge — précision f32 différente entre stacks fait que le sampler talker produit des codes différents et génère une phrase plus longue avant EOS) Gains : - Decoder -22% confirmé (cohérent avec ratio chraac 0.96 / llama-upstream 1.47) - CP -18 à -21% (ggml_graph_compute repack/sgemm ARM optimisé chraac) - Talker -1% (déjà au plafond NEON via llama.cpp) - RTF total -16 à -18% Bug découvert (à traiter plus tard) : Phrase historique 56 codes 'Bonjour, je m'appelle Kazeia, je suis encore en phase de développement' (= ~60 frames) crash ggml_sin chraac (GGML_ABORT 'unsupported types' probable). Phrases moyennes (<= 50 frames) passent OK. Sans doute incompat de types entre snake_consts (ctx_const dans Decoder) et le path ggml_sin de chraac (qui n'a peut-être pas la même variante f16/f32 que les ops récentes). Path actuel ql/ggml RESTE le défaut. Le chraac est build séparé tts_pipeline_chraac opt-in pour A/B. Libs chraac dans dist/lib-chraac/ (gitignored). À faire next : - Investiger crash ggml_sin chraac sur T>= ~50 frames - Décider : swap définitif Kazeia-Engine sur chraac (avec lib-chraac comme runtime principal) OU rester sur ql/ggml et patch chraac repack optims dedans Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitignore | 1 + dist/build_tts_pipeline_chraac.sh | 52 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 dist/build_tts_pipeline_chraac.sh diff --git a/.gitignore b/.gitignore index b35654b..d57120e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ b/ ql/ eval/out/ dist/b-vulkan/ +dist/lib-chraac/ diff --git a/dist/build_tts_pipeline_chraac.sh b/dist/build_tts_pipeline_chraac.sh new file mode 100755 index 0000000..a2317b0 --- /dev/null +++ b/dist/build_tts_pipeline_chraac.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Build tts_pipeline contre chraac-llama au lieu de ql/ggml (qualcomm fork). +# Cible : exploiter le ggml-cpu chraac qui a démontré RTF 0.96 sur decoder seul +# (vs 1.47 llama-upstream, cf /opt/Kazeia/kazeia-tts-perf-validated/). +# +# Diff vs build_tts_pipeline.sh : +# - headers depuis /opt/Kazeia/chraac-llama/{include,ggml/include} +# - link libs depuis dist/lib-chraac (copies de /opt/Kazeia/chraac-llama/build-android-kazeia/bin) +# - libqwen3tts-decoder.a depuis /opt/Kazeia/kazeia-tts-perf-validated (build chraac validé) +set -euo pipefail +HERE="$(cd "$(dirname "$0")" && pwd)" +NDK_ROOT="${ANDROID_NDK_ROOT:-/opt/Kazeia/android-ndk-r27d}" +CXX="$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android31-clang++" + +JNI="$HERE/jni" +INC_CHRAAC_LLAMA="/opt/Kazeia/chraac-llama/include" +INC_CHRAAC_GGML="/opt/Kazeia/chraac-llama/ggml/include" +LIB_CHRAAC="$HERE/lib-chraac" +OUT="$HERE/b-jni/tts_pipeline_chraac" +DECODER_DIR="/opt/Kazeia/kazeia-tts-decoder-ggml" +DECODER_INC="$DECODER_DIR/src" +# La lib decoder fresh chraac, code actuel (avec load_with_backends + snake_consts). +# Buildée 30/05 via la procédure docs/BUILD.md. +DECODER_A="/opt/Kazeia/kazeia-tts-decoder-ggml/build-android-chraac-fresh/libqwen3tts-decoder.a" + +[ -f "$DECODER_A" ] || { echo "libqwen3tts-decoder.a chraac absent: $DECODER_A"; exit 1; } +[ -d "$LIB_CHRAAC" ] || { echo "lib-chraac absent: $LIB_CHRAAC"; exit 1; } + +mkdir -p "$HERE/b-jni" + +CFLAGS=( + -std=c++17 -O3 -fPIE + -march=armv8.6-a+i8mm+bf16+dotprod+fp16 + -Wno-unused-parameter -Wno-unused-variable -Wno-sign-compare +) +INCS=( -I"$INC_CHRAAC_LLAMA" -I"$INC_CHRAAC_GGML" -I"$DECODER_INC" ) +LIBS=( + "$JNI/tts_pipeline.cpp" + "$JNI/tts_engine.cpp" + "$JNI/cp_inference.cpp" + "$JNI/sampler.cpp" + "$JNI/kazeia_text_tokenizer.cpp" + "$DECODER_A" + -L"$LIB_CHRAAC" -lllama -lggml -lggml-base -lggml-cpu + -Wl,-rpath,'$ORIGIN' + -llog -ldl -lm +) + +echo "== building tts_pipeline_chraac ==" +"$CXX" "${CFLAGS[@]}" "${INCS[@]}" "${LIBS[@]}" -o "$OUT" +echo "== built: $OUT ==" +ls -la "$OUT"