PHASE 0 audit (PERF_ANALYSIS.md + cette commit):
- BigVGAN = 95% du decoder (3.24s sur 3.36s), confirmé via KZTTS_DECODER_PROFILE=1
- 26 conv1d (63.7 Gops) + 4 conv_transpose_1d (51.6 Gops) + 30 snake (0.4 Gops)
- channels par block : 1024->1536->768->384->192->96->1
- T_cur évolution : 124->992->4960->19840->59520
- poids decoder TOUS en F16 déjà (110 MB F16 conv + 215 MB F32 snake α/β)
- ggml_conv_1d = im2col + mul_mat en interne, le graphe expose déjà MUL_MAT
- ggml-hexagon ql/ggml supporte : MUL_MAT (HMX fp16), UNARY (exp/silu/etc),
SOFT_MAX, ROPE, ADD, MUL, NORM, PAD, etc.
PAS supporté : IM2COL, CONV_1D, CONV_TRANSPOSE_1D, SIN
- opt_hostbuf=1 default -> HTP buffer CPU-mappable via ION
- budget RAM HTP session: 2 GB sur 3.5 GB plafond, ~1.5 GB marge
PHASE 2a (chaîne load HTP, sans gain HMX):
- Refactor decoder.h + gguf_loader.cpp : load_with_backends(path, devs)
crée le sched optionnellement (gated KZTTS_DECODER_SCHED).
- tts_engine.cpp : KZTTS_DECODER_HTP=1 -> initialise backend HTP +
backend CPU (sched), passe les deux à load_with_backends.
- Mode KZTTS_DECODER_HTP=1 sans SCHED : poids 325 MB sur HTP, compute
CPU pur lit via opt_hostbuf=1. WAV produit correct, ~baseline perf.
- Mode SCHED=1 : sched créé mais sched_alloc_graph plante (buffer_id>=0)
car les stages utilisent ggml_init(no_alloc=false) + memset, incompatible
avec sched. Refactor stages requis pour activer.
Snapshots des modifs decoder dans dist/decoder_patches/ (le repo decoder
est externe /opt/Kazeia, fichiers untracked).
PHASE 2b à faire prochaine session (~1 session):
- stage_bigvgan en pattern sched-friendly:
* no_alloc=true + ggml_set_input/output
* memset zeros -> ggml_pad_ext
* precompute_snake host -> ggml_exp + ggml_div in-graph
* sched_reset + alloc + tensor_set + compute + tensor_get
- Cible: decoder 3.2s -> 0.5-0.8s (×4-6 sur MUL_MAT HMX)
- Snake sin reste CPU (fallback sched), borné à 0.4 Gops/115 total
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| decoder_patches | ||
| include | ||
| jni | ||
| lib | ||
| CMakeLists.txt | ||
| HANDOFF.md | ||
| INTEGRATION.md | ||
| MODELS.md | ||
| PERF.md | ||
| PERF_ANALYSIS.md | ||
| PITFALLS.md | ||
| README.md | ||
| STATUS.md | ||
| TTS.md | ||
| build_kazeia_tts.sh | ||
| build_test_engine_2calls.sh | ||
| build_test_tokenizer.sh | ||
| build_tts_pipeline.sh | ||
| llama-cli | ||
| package.sh | ||
| system_fr.txt | ||
| test_native | ||
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)
lib/*.so→kazeia-android/app/src/main/jniLibs/arm64-v8a/jni/kazeia_engine_jni.cpp→app/src/main/jni/,include/*.hà côtéEngineLlmEngine.kt→com/kazeia/llm/,System.loadLibrary("kazeia_engine")- CMake: lib avec libllama+libggml+libggml-base,
-march=armv8.6-a+dotprod+fp16+i8mm+bf16 - 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.