Kazeia-engine/dist
Richard Loyer 7a998dec6b chantier B TTS #4: P3.1+P3.2 = x_vector + prefill_embeds depuis input_ids (bit-exact)
P3.1 - x_vector Damien dumpe offline : tts.model.extract_speaker_embedding(damien_15s_24k.wav)
-> f32[1024] = 4 KB. Embed dans l'app comme ressource. Pas de port du speaker
encoder Python (8.9M params), voix fixe = pre-calcul trivial.

P3.2 - reproduction C++ de la construction Python des talker_input_embeds.
Reference modeling_qwen3_tts.py:2124-2233 (mode x_vector_only + non_streaming).
Sequence prefill (19 positions pour 'Bonjour je m'appelle Kazeia', 8 tokens texte):
  0..2  : text_projection(text_embed[input_ids[:3]])                  role <im_start>assistant\n
  3..7  : tts_pad + tok_embd[think/think_bos/lang_fr/think_eos/x_vec]  5 positions codec prefix
  8     : tts_bos + tok_embd[codec_pad]                                 1 position
  9..N+8: text_projection(text_embed[input_ids[3:-5]]) + tok_embd[codec_pad]   text body
  N+9   : tts_eos + tok_embd[codec_pad]
  N+10  : tts_pad + tok_embd[codec_bos]
ou tts_*_embed = text_projection(text_embed[tts_bos/eos/pad_token_id]).chunk(3).

Composants : text_embed [151936, 2048] f32 (1.21 GB, a quantiser en P3.5),
text_projection ResizeMLP(2048->2048->1024, SiLU, bias=True), tok_embd talker
[3072, 1024], x_vector [1024], constants (special token ids).

Validation host (g++ -O2) sur phrase 'Bonjour je m'appelle Kazeia' :
  mean_rmse = 3.2e-8, max_abs = 1.8e-6 sur les 19 positions vs prefill_embeds
  capture du dump Python -> noise pure du f32 (eps ~1.2e-7).
Construction bit-exact.

Reste pour usage texte arbitraire : tokenizer BPE Qwen3 en C++ (llama_vocab
supporte cela en standard, a brancher en P3.4 quand on assemble la lib finale).
Pour l'instant input_ids dumpes depuis Python pour 1 phrase fixe = suffisant
pour P3.3 (integration CP) et P3.4 (assemblage).

Fixtures /opt/Kazeia/tts_talker_dump/ : text_embed.bin, tp_fc1_w/b.bin,
tp_fc2_w/b.bin, damien_xvector.bin, input_ids_full.bin, manifest_text.txt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 15:05:23 +02:00
..
include 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
jni chantier B TTS #4: P3.1+P3.2 = x_vector + prefill_embeds depuis input_ids (bit-exact) 2026-05-28 15:05:23 +02:00
lib chantier B TTS #2: fix M-RoPE positions en embeds-mode + validation bit-exact 2026-05-28 13:54:03 +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
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
PERF.md dist: prefill HTP corrigé (SSM_CONV gate backend), JNI option C sans OPFILTER 2026-05-27 10:39:08 +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
TTS.md Dist Kazeia-Engine: libs arm64+headers+JNI bridge+INTEGRATION/TTS doc; STT reste ORT 2026-05-24 21:55:01 +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.