Files
qwentts.cpp/docker/tts-server/entrypoint.sh
T
enne2 7942e61b3a
Docker / build (cpu, cpu) (push) Canceled after 0s
Docker / build (nvidia/cuda:12.9.2-devel-ubuntu22.04, nvidia/cuda:12.9.2-runtime-ubuntu22.04, cuda, cuda12) (push) Canceled after 0s
Docker / build (nvidia/cuda:13.3.1-devel-ubuntu22.04, nvidia/cuda:13.3.1-runtime-ubuntu22.04, cuda, cuda13) (push) Canceled after 0s
Docker / build (vulkan, vulkan) (push) Canceled after 0s
feat: anti-loop guards + KV cache configurabile
Prevenzione allucinazioni/loop infiniti (Qwen3-TTS autoregressivo):
- block_repeated_ngrams: maschera i token che ricreerebbero un n-gram gia visto (n=4)
- has_repeating_cycle: ferma la generazione su cicli periodici (periodo 1-16, 4 ripetizioni)
- stuck detector: token dominante nella finestra recente (4 occorrenze in 8 token)
- fallback EOS quando tutti i logits sono mascherati (evita NaN)
- KV cache talker configurabile (--kv-cache, default 8192): 4096 overflowava con
  reference lunghe + testi lunghi ("decode would overflow cache")
- parametri esposti via API (no_repeat_ngram_size, loop_max_period, loop_repeats,
  loop_window) e CLI (--no-repeat-ngram, --loop-period, --loop-repeats, --loop-window)
- Docker: TTS_KV_CACHE env (default 8192)

Validato: testo 2788 char che prima degenerava in loop ora sintetizza pulito
(141s via API, nessuna ripetizione).
2026-08-18 15:10:02 +02:00

51 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# Entrypoint tts-server: avvia il server, attende /health, poi registra le
# voci clonate (.spk/.rvq) trovate in VOICE_DIR.
# Tutti i parametri sono configurabili via variabili d'ambiente.
# ============================================================================
set -e
MODEL=${MODEL_PATH:-/models/qwen-talker-1.7b-base-Q8_0.gguf}
CODEC=${CODEC_PATH:-/models/qwen-tokenizer-12hz-Q8_0.gguf}
LANG=${TTS_LANG:-auto}
HOST=${HOST:-0.0.0.0}
PORT=${PORT:-8881}
ALIAS=${MODEL_ALIAS:-}
VOICE_DIR=${VOICE_DIR:-/voices}
extra_args=()
[ -n "$ALIAS" ] && extra_args+=(--alias "$ALIAS")
[ -n "$CODEC_CHUNK_DUR" ] && extra_args+=(--codec-chunk-dur "$CODEC_CHUNK_DUR")
[ -n "$CODEC_LEFT_DUR" ] && extra_args+=(--codec-left-dur "$CODEC_LEFT_DUR")
[ -n "$MAX_BATCH" ] && extra_args+=(--max-batch "$MAX_BATCH")
[ -n "$TTS_KV_CACHE" ] && extra_args+=(--kv-cache "$TTS_KV_CACHE")
[ -n "$MAX_PREFILL_TOKENS" ] && extra_args+=(--max-prefill-tokens "$MAX_PREFILL_TOKENS")
[ "$NO_FA" = "1" ] && extra_args+=(--no-fa)
[ "$CLAMP_FP16" = "1" ] && extra_args+=(--clamp-fp16)
echo "[tts] avvio tts-server (model=$MODEL codec=$CODEC lang=$LANG port=$PORT)"
/app/tts-server \
--model "$MODEL" \
--codec "$CODEC" \
--lang "$LANG" \
--host "$HOST" \
--port "$PORT" \
"${extra_args[@]}" &
SERVER_PID=$!
until curl -sf "http://localhost:${PORT}/health" > /dev/null 2>&1; do
kill -0 "$SERVER_PID" 2>/dev/null || { echo "[tts] tts-server uscito prima di diventare healthy" >&2; wait "$SERVER_PID"; }
sleep 1
done
echo "[tts] server pronto su :${PORT}"
if [ -d "$VOICE_DIR" ] && [ -n "$(ls -A "$VOICE_DIR" 2>/dev/null)" ]; then
echo "[tts] registrazione voci da $VOICE_DIR ..."
VOICE_DIR="$VOICE_DIR" TTS_PORT="$PORT" python3 /app/register_voices.py || echo "[tts] registrazione voci fallita (il server continua)"
else
echo "[tts] nessuna voce in $VOICE_DIR, salto registrazione"
fi
wait $SERVER_PID