kokoro.js: forward session_options through KokoroTTS.from_pretrained - #361
Open
pieterbotes wants to merge 1 commit into
Open
kokoro.js: forward session_options through KokoroTTS.from_pretrained#361pieterbotes wants to merge 1 commit into
pieterbotes wants to merge 1 commit into
Conversation
Allows callers to pass ONNX Runtime session options (e.g. intraOpNumThreads) to the underlying StyleTextToSpeech2Model. Useful when running several KokoroTTS instances in parallel worker processes, where each session otherwise sizes its thread pool to the full core count and they contend. No behavior change when the option is omitted. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E6YJ48EqBVrYcZdP7JNpri
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional
session_optionsfield toKokoroTTS.from_pretrained(model_id, options)and forwards it toStyleTextToSpeech2Model.from_pretrained. transformers.js already acceptssession_optionsand passes it to the ONNX Runtime inference session — kokoro.js just doesn't expose it today.No defaults change; when the option is omitted, behavior is identical to today.
Why
When several
KokoroTTSinstances run in parallel worker processes (a TTS pool in a server), each ONNX session sizes its intra-op thread pool to the machine's full core count by default, and the workers thrash each other. Measured on a 16-logical-core machine (q8, CPU EP): 8 concurrent syntheses scaled only 1.89× over a single worker. Capping each worker tointraOpNumThreads: 1and running more workers yielded 1.91× more aggregate throughput than the default threading, with the same model and inputs.There is currently no clean way to do this from the public API:
env.backends.onnxglobal tweaks don't reach per-session options.new KokoroTTS(model, tokenizer)works forgenerate()but breaksstream()("Missing the following inputs: style, speed"), so it isn't a practical workaround.Notes
session_optionsis applied only when provided, so omitted callers see no change.🤖 Generated with Claude Code
https://claude.ai/code/session_01E6YJ48EqBVrYcZdP7JNpri