Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/sie_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,15 @@ audio may last up to four minutes; a longer item fails alone with
number of phoneme ids the model read for the items that returned audio; a
refused item counts nothing. Items are synthesized one at a time.

Text becomes phonemes through misaki's English lexicon. A word outside it, such
as a rare name or an invented word, is read by the `cisco-ai/mini-bart-g2p`
letter-to-sound model (Apache-2.0, 16 MB), so it is spoken, though less reliably
than a dictionary word. Tokens with digits or symbols, such as `5:30`, `km/h` or
an e-mail address, are split and read piece by piece, and short words without
vowels, such as `mg`, are spelled. The model is loaded at a pinned revision
alongside the Kokoro checkpoint (loadtime options `g2p_model` and
`g2p_revision`), so a server without Hub access needs both in its cache.

### ModernBERT CUDA graphs

The ModernBERT flash-attention adapters, for dense embeddings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"unsafe-best-match"
],
"inputs": {
"requirements_sha256": "80006e6e0fb7d92e02da60e0c152752ec9b972782c6714218e9a4217e7f028a0",
"requirements_sha256": "9a6c8aad1198407cf99b917428d559547ba2d8e500b7651fc6759d6e7612ae4c",
"root_versions_sha256": "baaee3f4ed167d22897e99edc787077a74b2ce56dbbf986ebc4e1a80bdde6f24"
},
"lock_sha256": "d0fade75e5e3f71d905fd4b07bc5da0c7e6411df624aa76fe9b8b57110125e82",
"lock_sha256": "4ad5b63580b4ea239d7e4d6a70d69baa86bd1887bba3b75317c64118856891b3",
"policy_sha256": "63f7cb65d9bcfc5ce9d06397da86a90d8d50e05db0eb367824d599eba0459590",
"root_exclude_newer": "2026-11-06T20:00:00Z",
"schema_version": 1,
Expand Down
101 changes: 0 additions & 101 deletions packages/sie_server/bundle-locks/cpu-default-amd64/pylock.toml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"unsafe-best-match"
],
"inputs": {
"requirements_sha256": "80006e6e0fb7d92e02da60e0c152752ec9b972782c6714218e9a4217e7f028a0",
"requirements_sha256": "9a6c8aad1198407cf99b917428d559547ba2d8e500b7651fc6759d6e7612ae4c",
"root_versions_sha256": "baaee3f4ed167d22897e99edc787077a74b2ce56dbbf986ebc4e1a80bdde6f24"
},
"lock_sha256": "99c6d12fce6416bda3f5dcf291b50cb32390b9411e00480ffad1e5dddce56965",
"lock_sha256": "4dc791149e865e5b390c94cb02a18ea8ebfa49799019cce62fcf3260c0ee86d3",
"policy_sha256": "63f7cb65d9bcfc5ce9d06397da86a90d8d50e05db0eb367824d599eba0459590",
"root_exclude_newer": "2026-11-06T20:00:00Z",
"schema_version": 1,
Expand Down
101 changes: 0 additions & 101 deletions packages/sie_server/bundle-locks/cpu-default-arm64/pylock.toml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"https://pypi.org/simple"
],
"inputs": {
"requirements_sha256": "e46bcb3ad45115ff56a57ad4d24f291f7261c0103cd9b54aa1bcac187c209814",
"requirements_sha256": "eba8b999eca8b70028b11ece44dd8da256f24fcc5716b4c89a057e0f035cfad4",
"root_versions_sha256": "baaee3f4ed167d22897e99edc787077a74b2ce56dbbf986ebc4e1a80bdde6f24"
},
"lock_sha256": "5ea155772e3215dc92f85473be243daef8065ba56824e12297d70397c9446440",
"lock_sha256": "601bea17f9dbb7317f1186b7ad8f2e80c23a500f9c48ce4b1cbafa83269421e5",
"policy_sha256": "63f7cb65d9bcfc5ce9d06397da86a90d8d50e05db0eb367824d599eba0459590",
"root_exclude_newer": "2026-11-06T20:00:00Z",
"schema_version": 1,
Expand Down
101 changes: 0 additions & 101 deletions packages/sie_server/bundle-locks/cuda12-default-amd64/pylock.toml

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions packages/sie_server/bundles/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,10 @@ deps:
# Pinned to the compatibility pair of the immutable artifact revision in
# models/docling.yaml; see packages/sie_server/pyproject.toml (#2872).
docling: '>=2.99,<2.100'
# kokoro (Kokoro-82M text-to-speech). kokoro requires misaki[en]; the
# packages of that extra the adapter imports are listed with their own ranges.
kokoro: '==0.9.4'
# kokoro (Kokoro-82M text-to-speech). The adapter carries the model code and
# its own out-of-lexicon fallback, so it needs misaki's English G2P only:
# misaki without extras, plus the English packages misaki.en imports.
misaki: '==0.9.4'
# Ships the espeak-ng library and data that misaki's fallback G2P loads.
espeakng-loader: '>=0.2.4,<0.3'
phonemizer-fork: '>=3.3.2,<4'
num2words: '>=0.5.14,<1'
# 3.8.16 and later need click>=8.2.1, above the root lock's click.
spacy: '>=3.8,<3.8.16'
Expand Down
5 changes: 4 additions & 1 deletion packages/sie_server/models/hexgrad__Kokoro-82M.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ profiles:
compute_precision: float32
adapter_path: sie_server.adapters.kokoro.adapter:KokoroAdapter
adapter_options:
loadtime: {}
loadtime:
# Letter-to-sound model for words outside misaki's lexicon.
g2p_model: cisco-ai/mini-bart-g2p
g2p_revision: 0fbbf8c590f9db920939a2bc4befbaac26eebc4c
runtime: {}
39 changes: 39 additions & 0 deletions packages/sie_server/src/sie_server/adapters/kokoro/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
The Kokoro-82M model code in this directory (istftnet.py, modules.py, model.py,
pipeline.py) is adapted from kokoro 0.9.4 by hexgrad (Apache-2.0):
https://github.com/hexgrad/kokoro
https://pypi.org/project/kokoro/0.9.4/

Parts of that code (istftnet.py, modules.py) are in turn adapted from StyleTTS 2
(MIT): https://github.com/yl4579/StyleTTS2

Changes from the originals are described at the top of each file.

g2p_fallback.py runs the cisco-ai/mini-bart-g2p model (Apache-2.0), which the
adapter loads from the Hugging Face Hub at a pinned revision; its weights are
not part of this repository:
https://huggingface.co/cisco-ai/mini-bart-g2p

The Apache-2.0 license text is in the LICENSE file at the root of this
repository. The StyleTTS 2 license follows.

MIT License

Copyright (c) 2023 Aaron (Yinghao) Li

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 41 additions & 18 deletions packages/sie_server/src/sie_server/adapters/kokoro/adapter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Kokoro-82M text-to-speech adapter implemented on the native extract primitive.

``hexgrad/Kokoro-82M`` turns text into 24 kHz mono speech. Each text item is
one utterance: the ``kokoro`` pipeline converts it to phonemes with ``misaki``
(spaCy tagging plus a lexicon, with espeak-ng for out-of-lexicon words), splits
the phonemes into chunks of at most 510, and synthesizes each chunk with
``KModel``. The adapter joins the chunks' audio and returns, per item::
one utterance: ``misaki`` converts it to phonemes (spaCy tagging plus a
lexicon), the pipeline splits the phonemes into chunks of at most 510, and
``KModel`` synthesizes each chunk. Words outside the lexicon are read by
``g2p_fallback``: symbols and short consonant-only words are handled there, the
rest by the ``cisco-ai/mini-bart-g2p`` letter-to-sound model (Apache-2.0). The
model and pipeline code is adapted from the ``kokoro`` package (see ``NOTICE``).
The adapter joins the chunks' audio and returns, per item::

{"audio": <base64 PCM16 WAV>, "format": "wav", "sample_rate": 24000,
"duration_ms": ..., "voice": ...}
Expand All @@ -27,8 +30,11 @@
``INPUT_TOO_LONG``; the rest of the batch is synthesized. The defaults keep one
item under four minutes of audio, about 15 MB once base64-encoded.

Weights, config and voices come from one pinned snapshot; the adapter never
downloads anything after ``load()``.
Kokoro's weights, config and voices come from one pinned snapshot, and the
letter-to-sound model from a second one (loadtime options ``g2p_model`` and
``g2p_revision``). Both are resolved in ``load()`` under the server's cache
policy; the adapter never downloads anything after ``load()``. The
letter-to-sound model runs on CPU.
"""

from __future__ import annotations
Expand All @@ -47,6 +53,9 @@
from sie_server.adapters._checkpoint import resolve_checkpoint
from sie_server.adapters._spec import AdapterSpec
from sie_server.adapters._types import ERR_NOT_LOADED
from sie_server.adapters.kokoro.g2p_fallback import LetterToSound
from sie_server.adapters.kokoro.model import KModel
from sie_server.adapters.kokoro.pipeline import EnglishPipeline
from sie_server.core.inference_output import EncodeOutput, ExtractItemError, ExtractOutput
from sie_server.types.inputs import InvalidInputError
from sie_server.types.responses import ErrorCode
Expand All @@ -66,8 +75,18 @@

_CHECKPOINT_FILES = ("config.json", "kokoro-v1_0.pth", "voices/*.pt")
_WEIGHTS_FILE = "kokoro-v1_0.pth"
_REPO_ID = "hexgrad/Kokoro-82M"
# Kokoro language codes this adapter serves, with the aliases ``kokoro`` accepts.
DEFAULT_G2P_MODEL = "cisco-ai/mini-bart-g2p"
DEFAULT_G2P_REVISION = "0fbbf8c590f9db920939a2bc4befbaac26eebc4c"
_G2P_FILES = (
"config.json",
"generation_config.json",
"model.safetensors",
"special_tokens_map.json",
"tokenizer.json",
"tokenizer_config.json",
"vocab.json",
)
# Kokoro language codes this adapter serves, with their aliases.
_LANGS = {"a": "a", "b": "b", "en-us": "a", "en-gb": "b"}
_RUNTIME_OPTIONS = frozenset({"voice", "speed", "lang"})
# ``KModel.forward`` wraps every chunk's phoneme ids in one start and one end id.
Expand All @@ -92,6 +111,8 @@ def __init__(
revision: str | None = None,
max_chars_per_item: int = DEFAULT_MAX_CHARS_PER_ITEM,
max_audio_ms: int = DEFAULT_MAX_AUDIO_MS,
g2p_model: str = DEFAULT_G2P_MODEL,
g2p_revision: str | None = DEFAULT_G2P_REVISION,
**kwargs: Any,
) -> None:
del kwargs
Expand All @@ -105,35 +126,37 @@ def __init__(
self._revision = revision
self._max_chars_per_item = max_chars_per_item
self._max_audio_ms = max_audio_ms
self._g2p_model = g2p_model
self._g2p_revision = g2p_revision
self._model: Any = None
self._pipelines: dict[str, Any] | None = None
self._voices: dict[str, Path] | None = None
self._device: str | None = None

def load(self, device: str) -> None:
from kokoro import KModel, KPipeline # ty: ignore[unresolved-import]

directory = resolve_checkpoint(
self._model_name_or_path, revision=self._revision, allow_patterns=_CHECKPOINT_FILES
)
g2p_directory = resolve_checkpoint(self._g2p_model, revision=self._g2p_revision, allow_patterns=_G2P_FILES)
Comment thread
ShaiShmuel marked this conversation as resolved.
Resolved
voices = {path.stem: path for path in sorted((directory / "voices").glob("*.pt"))}
if DEFAULT_VOICE not in voices:
msg = f"Kokoro checkpoint {directory} has no voices/{DEFAULT_VOICE}.pt"
raise FileNotFoundError(msg)
logger.info(
"Loading Kokoro model %s on device=%s with %d voices", self._model_name_or_path, device, len(voices)
)
model = KModel(
repo_id=_REPO_ID,
config=str(directory / "config.json"),
model=str(directory / _WEIGHTS_FILE),
)
model = KModel(config=directory / "config.json", model=directory / _WEIGHTS_FILE)
self._model = model.to(device).eval()
self._device = device
self._voices = voices
# One G2P pipeline per language, sharing the model. Building one loads
# spaCy, so both are built here rather than on a first request.
self._pipelines = {code: KPipeline(lang_code=code, repo_id=_REPO_ID, model=self._model) for code in ("a", "b")}
# One G2P pipeline per language, sharing the model and the letter-to-sound
# model. Building one loads spaCy, so both are built here rather than on a
# first request.
letter_to_sound = LetterToSound(g2p_directory)
self._pipelines = {
code: EnglishPipeline(self._model, british=code == "b", letter_to_sound=letter_to_sound)
for code in ("a", "b")
}

def encode(
self,
Expand Down
Loading
Loading