Skip to content

fix(server): start a Kokoro TTS server without a tokenizer file - #2871

Merged
inureyes merged 3 commits into
lablup:mainfrom
pjw81226:fix/kokoro-server-chat-tokenizer
Nov 9, 2026
Merged

inureyes merged 3 commits into
lablup:mainfrom
pjw81226:fix/kokoro-server-chat-tokenizer

Conversation

@pjw81226

@pjw81226 pjw81226 commented Nov 6, 2026

Copy link
Copy Markdown

Summary

mlxcel-server -m <kokoro checkpoint> exits at startup with No tokenizer found, so the documented way to serve /v1/audio/speech never reaches the Kokoro TTS wiring. This PR lets a Kokoro server start without the chat tokenizer, the same way image-only serving already does.

Related issues

None filed. Found while reading the audio startup path. docs/audio-api.md documents -m <kokoro checkpoint> as the way to serve /v1/audio/speech, and the bug dates from the Kokoro landing in #374.

Type of change

  • fix — bug fix
  • refactor — internal restructuring without behavior change (first commit only)

Cause

start_server calls load_chat_front (src/server/startup.rs) before it detects a Kokoro checkpoint and wires KokoroTtsProvider. load_chat_front requires a tokenizer file, and every public Kokoro checkpoint (hexgrad/Kokoro-82M, prince-canuma/Kokoro-82M, mlx-community/Kokoro-82M-bf16) ships none: Kokoro reads phonemes from the vocab in its own config.json. The ? on that load ends the process before the TTS branch runs.

Change

Two commits:

  1. refactor(server): move the existing if image_only skip into chat_front_unused(model_path, image_only), with tests pinning the current answers. No behavior change.
  2. fix(server): list Kokoro in chat_front_unused, with a test that failed before the fix.

chat_front_unused is deliberately a list of verified cases, not a rule such as "every model whose registry runtimes lack Serve". The chat tokenizer load is currently the only startup check that stops a checkpoint without a tokenizer, because a failed -m side-model load (embedding, Whisper) only logs and leaves its routes answering 501. Under the broader rule, mlx-community/whisper-large-v3-turbo (which ships no tokenizer.json) would start, log one error, and answer 501 with /health not ready, instead of failing at startup with a clear message. The tests pin that a Whisper checkpoint and an undetectable model keep loading the chat front.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --features metal,accelerate -- -D warnings
  • cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1: 184 test binaries, 15065 passed, 0 failed, 493 ignored (M5 Pro, macOS)
  • cargo deny check: not run; this PR touches no dependency manifest, lockfile or deny.toml.
  • Validated with a real checkpoint: prince-canuma/Kokoro-82M (config, kokoro-v1_0.safetensors, voices/af_heart.safetensors, no tokenizer file), release build on M5 Pro:
    • before: Error: No tokenizer found in ".../kokoro-full" (tried tokenizer.json, ...), exit 1
    • after: /health 200; POST /v1/audio/speech 200 in 0.34 s, a 4.53 s 24 kHz mono 16-bit WAV (peak 12316, RMS 1477); /v1/chat/completions 501 as for any audio-only server
  • Unchanged fail-fast, same release build: a llama config and the mlx-community/whisper-large-v3-turbo config, each without a tokenizer file, still exit at startup with No tokenizer found.
  • New unit tests: cargo test --profile test-fast --features metal,accelerate -p mlxcel --lib chat_front_is (5 passed). chat_front_is_unused_by_a_kokoro_checkpoint failed before the fix commit.

Notes for reviewers

  • The skip is applied at the start_server call site, not inside load_chat_front, so mlxcel run (the in-process server, src/server/in_process/mod.rs) is unchanged.
  • Left out of scope, observed on the fixed server:
    • The chat worker still logs ERROR ... Failed to load model: Missing directory loader for model type: Kokoro at startup. It is harmless, but Whisper gets an explicit message at the same point (src/loading/mod.rs).
    • /tokenize and /detokenize answer with the empty tokenizer on a Kokoro server, where image-only serving returns a structured 501 through chat_not_available_image_only.
    • src/model_metadata.rs registers Kokoro as kind: Text, while src/models/registry.rs reports it as tts.

Checklist

  • PR title uses a Conventional Commits prefix
  • One logical change per PR
  • Updated docs/ if user-facing behavior or supported models changed: no change needed, docs/audio-api.md already describes the behavior this restores
  • Updated // Used by: ... comments on any shared function I modified: not applicable, no shared model function changed
  • No secrets, credentials, or .env files committed

🤖 Generated with Claude Code

@cla-assistant

cla-assistant Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 6, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

`start_server` skipped `load_chat_front` for image-only serving through a
bare `if image_only`. Move that decision into `chat_front_unused`, which
documents why a case may skip the chat tokenizer: the missing-tokenizer
error in `load_chat_front` is the only startup check that stops a
checkpoint without one, because a failed side-model load only logs.

No behavior change. The new tests pin the current answers: image-only
skips, while a chat checkpoint, a Whisper checkpoint and an undetectable
model still load the chat front.
`mlxcel-server -m <kokoro checkpoint>` exited at startup with "No
tokenizer found". `start_server` loads the chat tokenizer before it
detects the Kokoro checkpoint and wires `/v1/audio/speech`, and Kokoro
checkpoints ship no tokenizer file: the model reads phonemes from the
vocab in its own `config.json`.

`chat_front_unused` now lists Kokoro next to image-only serving. It stays
a list of verified cases rather than a rule like "every non-chat model",
because the chat tokenizer load is the only startup check that stops an
embedding or Whisper checkpoint without a tokenizer; their side-model
load failures only log.

Verified against prince-canuma/Kokoro-82M with no tokenizer file: /health
returns 200 and /v1/audio/speech returns a 4.5 s, 24 kHz WAV. A llama and
a Whisper checkpoint without a tokenizer still stop at startup.
@pjw81226
pjw81226 force-pushed the fix/kokoro-server-chat-tokenizer branch from 4f7fcc7 to 4d1a53d Compare November 6, 2026 12:58
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority modeltype:audio Audio or speech model labels Nov 9, 2026
Skipping the chat front removed the only startup check that stopped a checkpoint without a tokenizer, so several cases that used to fail now started a server with nothing behind it.

Keep the skip to a single-node server and to a config that does not name another architecture, since Kokoro detection also fires on a stray `kokoro-v1_0.safetensors` or `istftnet` block. A Kokoro TTS load failure now exits at startup instead of logging and answering 501 indefinitely. `/tokenize`, `/detokenize` and `/apply-template` return the structured 501 on a Kokoro server rather than answering from the empty tokenizer, and the text loader names `/v1/audio/speech` instead of reporting a missing directory loader.
@inureyes

inureyes commented Nov 9, 2026

Copy link
Copy Markdown
Member

Hardening review, pushed as f267a49a on top of 4d1a53dd. No linked issue.

Findings fixed

  • HIGH: with the tokenizer check skipped, a Kokoro checkpoint that failed to load left a server stuck at 503/501, because the load error was only logged. A load failure now exits at startup.
  • MEDIUM: Kokoro detection accepts a stray kokoro-v1_0.safetensors or istftnet block, so a chat checkpoint could lose its missing-tokenizer failure. The skip now also requires model_type to be absent or kokoro.
  • MEDIUM: router and disaggregated roles also took the skip. It now applies only to ServingMode::Hybrid.
  • MEDIUM: /tokenize, /detokenize and /apply-template answered from the empty tokenizer. They now return the structured 501 on a TTS server.
  • LOW: the text loader's error now points at /v1/audio/speech, and docs/audio-api.md records the behavior above.

Left as is: /v1/models still lists completion for Kokoro, and /props and /slots answer with chat defaults. Harmless and outside this PR.

Security and performance: the only new input is a local config path; one extra config read at startup.

Validation on GB10: fmt and clippy pass; 233 focused lib tests pass. On kokoro-82m, /health returned 200, /v1/audio/speech returned valid 24 kHz WAV, and generation and tokenizer routes returned JSON 501. A Kokoro config with no vocab and a llama config with a stray Kokoro weight both exit 1. New tests fail with the fixes reverted, except that the fatal-load call site is proven by the real binary (exit 1 fixed, still running when reverted), not a unit test.

Merge gate: first-time-contributor workflow runs wait for approval and were not started, so by maintainer decision the gate ran on GB10 against one tree integrating #2888, #2872, #2869, #2871 and #2870 on 98b92fb6: fmt, clippy with -D warnings (CUDA), env var docs and license checks pass, and the full CUDA lib suite passes (11405 passed, 0 failed). Python tooling is 213 of 214; the one failure is a ROCm guard timing test whose test and script this PR does not change. macOS, Windows and ROCm builds did not run.

@inureyes
inureyes merged commit 5e3000e into lablup:main Nov 9, 2026
1 check passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 9, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modeltype:audio Audio or speech model priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants