Kazeia-engine/dist
Richard Loyer 8c1e83be18 chantier B unification #1 : engine 3/3 prêt pour intégration (STT + TTS + LLM)
Reproche du user juste : j'ai livré STT complet mais pas TTS ni LLM au même
niveau. Cette session corrige : 3 docs d'intégration équivalentes en qualité,
2 bugs in-app investigués et l'un fixé.

Investigation TTS "crashe au load in-app" :
 - DT_NEEDED de libkazeia_tts.so = libllama.so + libggml.so + libggml-base.so
   + libggml-cpu.so + libc++_shared.so + libdl/libm/libc
 - Test reproduction sur tablette : lib charge OK avec les 7 deps présentes,
   crash avec "library libllama.so not found" si une dep manque
 - Conclusion : c'est juste 7 libs à pousser dans jniLibs/arm64-v8a/, pas un
   bug code. Liste exhaustive donnée dans TTS_INTEGRATION.md §2.b

Investigation LLM "ne tient pas 8 threads in-app" :
 - kazeia_engine_jni.cpp ligne 117/120/124/131 : n_threads HARDCODE à 4
   pour le decode CPU. Pas exposé côté Kotlin.
 - Fix : ajouter param nThreads à load(), N_DECODE défaut 6 (sweet spot r3
   mesuré : Qwen3.5-4B 9.8 tok/s à t=6 vs 7.4 à t=8 contention)
 - Update EngineJni.load(model, ctx, nThreads) + EngineLlmEngine(ctx, nThreads=6)
 - Rebuild libkazeia_engine.so 60 KB

Docs livrées (format identique STT_INTEGRATION.md) :
 - TTS_INTEGRATION.md (10 KB) : libs à pousser, façade, clonage vocal,
   sampling, codes erreur, bench, checklist, pièges
 - LLM_INTEGRATION.md (10 KB) : option C HTP/CPU, n_threads sweet spot,
   modèles supportés (Qwen3 dense / Qwen3.5 hybride GDN), cascade
   Speaker+Thinker, piège affinity Android (decode 9.8 -> 0.32 tok/s in-app
   si scheduler pin sur 1 cœur)
 - KAZEIA_ENGINE_OVERVIEW.md actualisé : entrée unique pointant les 3 docs,
   pattern dispatch flag (mirror STT pour LLM+TTS), état réel 3/3 prêt

Reste côté dev (cf KAZEIA_ENGINE_OVERVIEW.md):
 1. Pousser les libs jniLibs (8 fichiers pour TTS/LLM, partagées entre eux)
 2. Copier les 3 façades Kotlin
 3. Câbler 2 flags dispatch supplémentaires (llmEngine + ttsEngine, mirror STT)
 4. Valider checklist §7 de chaque doc (System.loadLibrary + 1 call)
 5. Bench A/B prod vs lib sur audios/prompts fixtures

Le pattern STT a marché parce qu'il avait tout (lib + façade + doc + checklist).
Maintenant TTS et LLM aussi.
2026-06-01 15:46:20 +02:00
..
decoder_patches chantier BigVGAN HMX Phase 2b: refactor sched-friendly + limite backend découverte 2026-05-29 14:05:35 +02:00
include chantier B STT #1 : S1 unification engine (mel partagé + skeleton stt + VAD C++) 2026-05-31 19:19:28 +02:00
jni chantier B unification #1 : engine 3/3 prêt pour intégration (STT + TTS + LLM) 2026-06-01 15:46:20 +02:00
lib chantier B STT #2 : S2 + S3 livrés (stt_engine ORT QNN + JNI + façade Kotlin + doc) 2026-05-31 22:15:58 +02:00
patches chantier B STT #5 : Action 1 dev — patch QNN options pour la prod gelée 2026-06-01 09:42:27 +02:00
scripts SE.1+SE.2+SE.3 partiel : speaker encoder pipeline POC bout-en-bout 2026-05-31 11:37:14 +02:00
CMakeLists.txt JNI bridge complet: generate() prefill+decode, build arm64 OK (libkazeia_engine.so 209K) 2026-05-24 21:58:00 +02:00
HANDOFF.md dist: audit intégrabilité HANDOFF — corrige passages périmés 2026-05-27 18:55:16 +02:00
INTEGRATION.md dist: bandeau HANDOFF source de vérité sur README/INTEGRATION (9B historique) 2026-05-26 23:34:15 +02:00
KAZEIA_ENGINE_OVERVIEW.md chantier B unification #1 : engine 3/3 prêt pour intégration (STT + TTS + LLM) 2026-06-01 15:46:20 +02:00
LLM_INTEGRATION.md chantier B unification #1 : engine 3/3 prêt pour intégration (STT + TTS + LLM) 2026-06-01 15:46:20 +02:00
MODELS.md dist: handoff intégration aligné décisions 26/05 (modèle q35-lmq4, perf, prompt) 2026-05-26 23:33:41 +02:00
PATCH_QNN_PROD.md chantier B STT #5 : Action 1 dev — patch QNN options pour la prod gelée 2026-06-01 09:42:27 +02:00
PERF.md dist: prefill HTP corrigé (SSM_CONV gate backend), JNI option C sans OPFILTER 2026-05-27 10:39:08 +02:00
PERF_ANALYSIS.md doc: PERF_ANALYSIS.md — diagnostic post-session, leviers triés ROI 2026-05-28 22:43:23 +02:00
PERF_CPU_OPTIMS.md doc: PERF_CPU_OPTIMS.md — bilan optims CPU, RTF 2.93->2.45 2026-05-29 17:30:54 +02:00
PERF_INFRA_TESTS.md tests infra HTP/HMX : verdict, le HTP n'est pas le bon outil pour TTS 2026-05-29 16:40:56 +02:00
PERF_VULKAN_TESTS.md Vulkan Adreno 830 testé : neutre au mieux, régresse au pire (commit aussi le code opt-in) 2026-05-29 22:28:16 +02:00
PITFALLS.md Doc complete: README+MODELS+PERF+PITFALLS, build nettoye 2026-05-24 21:59:56 +02:00
README.md dist: bandeau HANDOFF source de vérité sur README/INTEGRATION (9B historique) 2026-05-26 23:34:15 +02:00
STATUS.md dist: audit intégrabilité HANDOFF — corrige passages périmés 2026-05-27 18:55:16 +02:00
STT_INTEGRATION.md chantier B STT #6 : 2 bugs critiques fixés grâce à l'A/B in-app du dev 2026-06-01 12:19:33 +02:00
TTS.md Dist Kazeia-Engine: libs arm64+headers+JNI bridge+INTEGRATION/TTS doc; STT reste ORT 2026-05-24 21:55:01 +02:00
TTS_INTEGRATION.md chantier B unification #1 : engine 3/3 prêt pour intégration (STT + TTS + LLM) 2026-06-01 15:46:20 +02:00
build_decoder_subproc.sh Decoder chraac en sous-process : -20% decoder, -9% pipeline, talker intact 2026-05-30 18:14:09 +02:00
build_ggml_vulkan.sh Vulkan Adreno 830 testé : neutre au mieux, régresse au pire (commit aussi le code opt-in) 2026-05-29 22:28:16 +02:00
build_kazeia_stt.sh chantier B STT #2 : S2 + S3 livrés (stt_engine ORT QNN + JNI + façade Kotlin + doc) 2026-05-31 22:15:58 +02:00
build_kazeia_tts.sh chantier B TTS #11: libkazeia_tts.so + Kotlin wrapper, JNI validé bout-en-bout 2026-05-28 21:54:21 +02:00
build_speaker_encoder.sh chantier B STT #1 : S1 unification engine (mel partagé + skeleton stt + VAD C++) 2026-05-31 19:19:28 +02:00
build_stt_cli.sh chantier B STT #2 : S2 + S3 livrés (stt_engine ORT QNN + JNI + façade Kotlin + doc) 2026-05-31 22:15:58 +02:00
build_stt_test.sh chantier B STT #1 : S1 unification engine (mel partagé + skeleton stt + VAD C++) 2026-05-31 19:19:28 +02:00
build_test_engine_2calls.sh chantier B TTS #11: libkazeia_tts.so + Kotlin wrapper, JNI validé bout-en-bout 2026-05-28 21:54:21 +02:00
build_test_tokenizer.sh chantier B TTS #10: tokenizer Qwen3 BPE via llama_tokenize, texte arbitraire 2026-05-28 21:21:53 +02:00
build_tts_pipeline.sh chantier B STT #1 : S1 unification engine (mel partagé + skeleton stt + VAD C++) 2026-05-31 19:19:28 +02:00
build_tts_pipeline_chraac.sh CH chraac-llama : -18% RTF (2.43 -> 2.04) via swap ggml source 2026-05-30 12:38:47 +02:00
llama-cli Dist Kazeia-Engine: libs arm64+headers+JNI bridge+INTEGRATION/TTS doc; STT reste ORT 2026-05-24 21:55:01 +02:00
package.sh dist: handoff intégration aligné décisions 26/05 (modèle q35-lmq4, perf, prompt) 2026-05-26 23:33:41 +02:00
system_fr.txt dist: handoff intégration aligné décisions 26/05 (modèle q35-lmq4, perf, prompt) 2026-05-26 23:33:41 +02:00
test_native Engine sur fork qualcomm: decode dense 15.5>pte, 3.5 ~11, KVq8+t4+fa+lm_head-Q4; prefill 93/285; RAG cross 24-28k 2026-05-26 15:53:14 +02:00

README.md

Source de vérité à jour = HANDOFF.md (26/05). Modèle tranché = q35-lmq4 (Qwen3.5-4B), 9B écarté. Les mentions de 9B/cascade ci-dessous sont historiques.

Kazeia-Engine — intégration kazeia-android

Moteur LLM (+ TTS) GGUF, sans .pte, fork llama.cpp upstream + backend Hexagon. Remplace ExecuTorch/Genie pour le LLM. STT reste ORT-QAIRT (inchangé). Prefill NPU / decode CPU. Modèle dense (Qwen3) plein NPU ; hybride (Qwen3.5 DDDA) GDN sur NPU corrigé.

0. Périmètre

Brique Avant Après
LLM Speaker/Thinker ExecuTorch .pte Kazeia-Engine GGUF
TTS Talker/CP ggml-cpu engine (Talker prefill HTP option.)
TTS Decoder libtts_decoder_ggml inchangé
STT Whisper ORT-QAIRT inchangé

1. Contenu du paquet

  • lib/ : libkazeia_engine.so (bridge JNI) + libllama.so + libggml{,-base,-cpu,-hexagon}.so + libggml-htp-v68/69/73/75/79/81.so (sélection auto = V79 sur Pad3). 168 MB.
  • jni/ : kazeia_engine_jni.cpp, EngineLlmEngine.kt. include/, CMakeLists.txt.
  • INTEGRATION.md (steps), TTS.md, MODELS.md, PERF.md, PITFALLS.md.

2. Build (5 étapes)

  1. lib/*.sokazeia-android/app/src/main/jniLibs/arm64-v8a/
  2. jni/kazeia_engine_jni.cppapp/src/main/jni/, include/*.h à côté
  3. EngineLlmEngine.ktcom/kazeia/llm/, System.loadLibrary("kazeia_engine")
  4. CMake: lib avec libllama+libggml+libggml-base, -march=armv8.6-a+dotprod+fp16+i8mm+bf16
  5. GGUF → external storage, paths via KazeiaApplication.LLM_DIR

3. Cascade — remplace LlmProcessor cascade

Thinker Guard-4B → 4 bullets ; Speaker 9B = SYS_KAZEIA+bullets. Mono-moteur, reset() entre tours. Prompts: voir RAPPORT_KAZEIA §8. --reasoning-budget 0 impératif (sinon ramble anglais) : EngineLlmEngine met thinking off. Mesuré: 9B>4B qualité, Speaker=9B.

→ MODELS.md (choix), PERF.md (chiffres), PITFALLS.md (params_fit, no tty, OOM 30B+), INTEGRATION.md (détail API). API: load/generate/reset/free.

VALIDÉ DEVICE 24/05

test_native (=logique generate bridge) sur Pad3: load 4B HTP+decode CPU+detok = OUT propre, exit0. Pipeline prefill-NPU/decode-CPU prouve end-to-end. dist/jni/test_native.cpp = harness reproductible. Bridge so: 4 symboles JNI + deps ok. Reste app: gradle+jniLibs+template chat.

v2 STATIC (collision libllama TTS resolue)

TTS Talker/CP linke vs son libllama.so -> conflit ABI. FIX: libkazeia_engine.so STATIC (llama+ggml+ggml-cpu+hexagon en .a, --whole-archive hexagon). NEEDED= libm/log/dl/c only, 42MB. Coexiste avec libllama TTS. Drop: libkazeia_engine.so + libggml-htp-v79.so. Valide device 4B HTP. Build: bstatic BUILD_SHARED_LIBS=OFF.

v3 utilisable: thinking-off bridge

generate(sys,usr,max): wrap ChatML + vide = stop reasoning, decode 4B 15tok/s ~5s/tour. test 4B: "Je suis desole..." 40s(load)+gen. signature 2-arg. cap maxTok 64. dist=libkazeia_engine.so static + htp-v79. #277 fix livre.

v4 USABLE: ngl0 CPU decode (vrai fix #277)

Hang in-app=0.21tok/s: ngl99 -> decode ping-pong NPU/GDN-CPU. FIX: n_gpu_layers=0 decode CPU pur 14tok/s. test 4B: reponse FR 4s/tour. dev avait raison: pas thinking. cap64 garde. Speaker=4B CPU ngl0. RAM 4.5G. dist=libkazeia_engine.so. utilisable, #277 debloque.