Repository navigation
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
CI failure just because we haven't merged modeling files in. |
|
Hi @xenova, thanks for all the export work here! I pushed three commits on top, here's what changed and where it now differs from the description. What I did
Different from the description
|
| // Match the Phonon checkpoint's generation_config.json, not Python's generic Pocket TTS defaults. | ||
| do_sample: true, | ||
| temperature: 0.3, | ||
| num_flow_steps: 1, | ||
| eos_threshold: config.eos_threshold, | ||
| min_frames_before_eos: 0, | ||
| ...this.generation_config, |
There was a problem hiding this comment.
if we match the generation_config.json, and we always load the generation config and set it, then I'd say these extra parameters aren't needed.
| if (options.num_flow_steps !== 1) { | ||
| throw new Error('This ONNX export supports num_flow_steps=1; other values require re-export.'); | ||
| } | ||
| if (input_ids.dims.length !== 2 || input_ids.dims[0] !== 1) { | ||
| throw new Error('Phonon generate() accepts one prompt per call.'); | ||
| } | ||
| if ( | ||
| attention_mask.dims.length !== 2 || | ||
| attention_mask.dims[0] !== 1 || | ||
| attention_mask.dims[1] !== input_ids.dims[1] | ||
| ) { | ||
| throw new Error('attention_mask must match the shape of input_ids.'); | ||
| } | ||
| if ( | ||
| !(audio_prompt_latents instanceof Tensor) || | ||
| audio_prompt_latents.type !== 'float32' || | ||
| audio_prompt_latents.dims.length !== 3 || | ||
| audio_prompt_latents.dims[0] !== 1 || | ||
| audio_prompt_latents.dims[2] !== config.audio_prompt_dim | ||
| ) { | ||
| throw new Error('audio_prompt_latents must be a float32 tensor of shape [1, frames, audio_prompt_dim].'); | ||
| } | ||
| const voice_length = audio_prompt_latents.dims[1]; | ||
| if ( | ||
| audio_prompt_latents_mask !== undefined && | ||
| (audio_prompt_latents_mask.dims.length !== 2 || | ||
| audio_prompt_latents_mask.dims[0] !== 1 || | ||
| audio_prompt_latents_mask.dims[1] !== voice_length || | ||
| audio_prompt_latents_mask.data.some((value) => Number(value) !== 1)) | ||
| ) { | ||
| throw new Error('Phonon requires an unpadded voice prompt with a matching audio_prompt_latents_mask.'); |
There was a problem hiding this comment.
imo this is overly defensive. we don't really do this for other models. We get a clear enough error back from ONNX Runtime.
| ...Object.fromEntries(Object.entries(kwargs).filter(([, value]) => value != null)), | ||
| }; | ||
| const { model, mimi_decoder } = this.sessions; | ||
| const block_size = model.inputMetadata.find(({ name }) => name === 'noise').shape[1]; |
There was a problem hiding this comment.
i assume this should be a config value we can extract?
| while (num_frames < Math.min(stop_frame ?? max_frames, max_frames)) { | ||
| const prefill = num_frames === 0; | ||
| // The KV cache includes voice and text positions, unlike the audio latent cache. | ||
| const past_length = cache['past_key_values.0.key'].dims.at(-2); |
There was a problem hiding this comment.
if this is of type DynamicCache, then I think there is a class method which does the same thing as this
|
|
||
| // Until tokenizers.js implements Unigram byte fallback, expand unknown pieces | ||
| // before they are converted to IDs. Limit the workaround to this processor. | ||
| // TODO: remove this adapter once https://github.com/huggingface/tokenizers.js/issues/26 is fixed. |
There was a problem hiding this comment.
with all the recent tokenizers.js PRs users have submitted, maybe this is a good one to tackle to include in our next release.
| const boundary_ids = (pieces) => | ||
| new Set( | ||
| /** @type {number[]} */ (this.tokenizer.convert_tokens_to_ids(pieces)).filter( | ||
| (id) => Number.isInteger(id) && id !== this.tokenizer.unk_token_id, | ||
| ), | ||
| ); | ||
| const sentence_ends = boundary_ids(['.', '!', '...', '?']); | ||
| const clause_ends = boundary_ids([',', ';', ':']); |
There was a problem hiding this comment.
worth moving to constructor or not?
There was a problem hiding this comment.
this file is so complex -- we can probably simplify a lot
There was a problem hiding this comment.
not ideal to recreate tokenizer logic here. better to use official tokenizer imo
Following on from #1811, with more improvements. Associated model files can be found at https://huggingface.co/onnx-community/phonon-31m-en-ONNX/discussions/1, awaiting @nico-martin's review.
vs. #1811:
For q4f16, representative total times went from 166 → 78 ms and 640 → 305 ms.
Possibly more importantly, we also made various correctness fixes:
Model graph size improvements too:
Beyond the speedup and correctness, we improved memory use, decoder correctness, export reproducibility, and the JS generation API.
On the model/export side:
For the Transformers.js integration: