-
Notifications
You must be signed in to change notification settings - Fork 17
Add support for framestacking - v2607 magpie tts #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anand-nv
wants to merge
31
commits into
NVIDIA:main
Choose a base branch
from
anand-nv:add_lang_ar_kr_po
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bddd0f8
Enable frame stacking to support magpie tts v2607
anand-nv e80bcd8
Add preempt option for tts
anand-nv 82ed851
Add support for AR, KO, PT
anand-nv ad6aba2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 830db79
refactor(tts): migrate MagpieTTS decoder to the common GGML runtime
pskrunner14 675b8bd
perf(tts): optimize magpie decoding with cached attention
pskrunner14 fe5850e
perf(tts): enable optimized magpie streaming default
pskrunner14 f7e17e8
Merge pull request #1 from pskrunner14/migrate-tts-to-ggml-runtime
anand-nv 44f46b2
Tokenizer fixes
anand-nv e757307
Merge pull request #3 from anand-nv/tokenizer_changes
anand-nv 84f38d8
Merge branch 'main' into add_lang_ar_kr_po
pskrunner14 3c48ea2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a898c78
Fix Arabic terminal punctuation
anand-nv cedbeb2
Update documentation for language config
anand-nv 28b7d0c
Fixes for frame stacking
anand-nv 5e90dc9
Merge branch 'add_lang_ar_kr_po' into tokenizer_changes
anand-nv 3efcf04
Merge pull request #4 from anand-nv/tokenizer_changes
anand-nv a8b2366
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1e83b0e
Gate preempt checks on TTS support.
anand-nv 98f97f5
Validate sequential tensor indexes.
anand-nv 344eb87
Merge pull request #5 from anand-nv/tokenizer_changes
anand-nv ca4769c
Decoder fixes
anand-nv fc4a2ec
Magpie fixes
anand-nv 9cffd5b
More Magpie fixes
anand-nv 8aecf3d
Merge pull request #6 from anand-nv/tokenizer_changes
anand-nv ab1d933
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5ece278
CR Review fixes
anand-nv b37395d
Resolve conflict
anand-nv 653ee44
Merge branch 'add_lang_ar_kr_po' into tokenizer_changes
anand-nv 3a0740b
Merge pull request #8 from anand-nv/tokenizer_changes
anand-nv a3718bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Known MagpieTTS tokenizer layouts shared by conversion checks.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| TOKENIZER_ORDERS = { | ||
| "v2602": ( | ||
| "english_phoneme", | ||
| "spanish_phoneme", | ||
| "german_phoneme", | ||
| "mandarin_phoneme", | ||
| "japanese_phoneme", | ||
| "french_chartokenizer", | ||
| "hindi_chartokenizer", | ||
| "italian_phoneme", | ||
| "vietnamese_phoneme", | ||
| "text_ce_tokenizer", | ||
| ), | ||
| "v2607": ( | ||
| "english_phoneme", | ||
| "text_ce_tokenizer", | ||
| "spanish_phoneme", | ||
| "german_phoneme", | ||
| "mandarin_phoneme", | ||
| "japanese_phoneme", | ||
| "portuguese_Brazilian_phoneme", | ||
| "hindi_phoneme", | ||
| "arabic_AE_chartokenizer", | ||
| "arabic_SA_chartokenizer", | ||
| "arabic_MSA_chartokenizer", | ||
| "french_chartokenizer", | ||
| "italian_chartokenizer", | ||
| "vietnamese_chartokenizer", | ||
| "korean_chartokenizer", | ||
| ), | ||
| } | ||
|
|
||
| TOKENIZER_PROFILE_DIMENSIONS = { | ||
| "v2602": (2362, 1), | ||
| "v2607": (3359, 2), | ||
| } | ||
|
|
||
| TOKENIZER_PROFILE_NEMO_VERSIONS = { | ||
| "v2602": "2.6.0rc0", | ||
| "v2607": "2.8.0rc0", | ||
| } | ||
|
|
||
| IPA_TARGET = "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers.IPATokenizer" | ||
| BYT5_TARGET = "AutoTokenizer" | ||
| TOKENIZER_TARGETS = { | ||
| "v2602": { | ||
| "english_phoneme": IPA_TARGET, | ||
| "spanish_phoneme": IPA_TARGET, | ||
| "german_phoneme": IPA_TARGET, | ||
| "mandarin_phoneme": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "ChinesePhonemesTokenizer" | ||
| ), | ||
| "japanese_phoneme": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "JapanesePhonemeTokenizer" | ||
| ), | ||
| "french_chartokenizer": BYT5_TARGET, | ||
| "hindi_chartokenizer": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "HindiCharsTokenizer" | ||
| ), | ||
| "italian_phoneme": BYT5_TARGET, | ||
| "vietnamese_phoneme": BYT5_TARGET, | ||
| "text_ce_tokenizer": BYT5_TARGET, | ||
| }, | ||
| "v2607": { | ||
| "english_phoneme": IPA_TARGET, | ||
| "text_ce_tokenizer": BYT5_TARGET, | ||
| "spanish_phoneme": IPA_TARGET, | ||
| "german_phoneme": IPA_TARGET, | ||
| "mandarin_phoneme": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "ChinesePhonemesTokenizer" | ||
| ), | ||
| "japanese_phoneme": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "JapanesePhonemeTokenizer" | ||
| ), | ||
| "portuguese_Brazilian_phoneme": IPA_TARGET, | ||
| "hindi_phoneme": IPA_TARGET, | ||
| "arabic_AE_chartokenizer": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "ArabicCharsTokenizer" | ||
| ), | ||
| "arabic_SA_chartokenizer": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "ArabicCharsTokenizer" | ||
| ), | ||
| "arabic_MSA_chartokenizer": ( | ||
| "nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers." | ||
| "ArabicCharsTokenizer" | ||
| ), | ||
| "french_chartokenizer": BYT5_TARGET, | ||
| "italian_chartokenizer": BYT5_TARGET, | ||
| "vietnamese_chartokenizer": BYT5_TARGET, | ||
| "korean_chartokenizer": BYT5_TARGET, | ||
| }, | ||
| } | ||
|
|
||
| V2607_LANGUAGE_MAPPING = { | ||
| "en": ["english_phoneme"], | ||
| "de": ["german_phoneme"], | ||
| "es": ["spanish_phoneme"], | ||
| "fr": ["french_chartokenizer"], | ||
| "it": ["italian_chartokenizer"], | ||
| "vi": ["vietnamese_chartokenizer"], | ||
| "zh": ["mandarin_phoneme"], | ||
| "hi": ["hindi_phoneme"], | ||
| "ja": ["japanese_phoneme"], | ||
| "pt-BR": ["portuguese_Brazilian_phoneme"], | ||
| "ko": ["korean_chartokenizer"], | ||
| "ar-AE": ["arabic_AE_chartokenizer"], | ||
| "ar-SA": ["arabic_SA_chartokenizer"], | ||
| "ar-MSA": ["arabic_MSA_chartokenizer"], | ||
| } | ||
|
|
||
|
|
||
| def tokenizer_profile(cfg: dict[str, Any], text_vocab: int, frame_stacking: int) -> str: | ||
| tokenizers = cfg.get("text_tokenizers") | ||
| if not isinstance(tokenizers, dict): | ||
| raise ValueError("Magpie config has no text_tokenizers mapping") | ||
| order = tuple(tokenizers) | ||
| matches = [name for name, expected in TOKENIZER_ORDERS.items() if order == expected] | ||
| if len(matches) != 1: | ||
| raise ValueError(f"unsupported Magpie tokenizer layout: {list(order)}") | ||
| profile = matches[0] | ||
| if str(cfg.get("nemo_version", "")) != TOKENIZER_PROFILE_NEMO_VERSIONS[profile]: | ||
| raise ValueError(f"unsupported {profile} nemo_version: {cfg.get('nemo_version')!r}") | ||
| for name, target in TOKENIZER_TARGETS[profile].items(): | ||
| tokenizer = tokenizers.get(name) | ||
| actual_target = tokenizer.get("_target_") if isinstance(tokenizer, dict) else None | ||
| if actual_target != target: | ||
| raise ValueError( | ||
| f"unsupported {profile} tokenizer target for {name}: " f"{actual_target!r}" | ||
| ) | ||
| expected_japanese_case = "upper" if profile == "v2602" else "lower" | ||
| japanese_g2p = tokenizers["japanese_phoneme"].get("g2p") | ||
| japanese_case = ( | ||
| japanese_g2p.get("ascii_letter_case") if isinstance(japanese_g2p, dict) else None | ||
| ) | ||
| if japanese_case != expected_japanese_case: | ||
| raise ValueError(f"unsupported {profile} Japanese ascii_letter_case: {japanese_case!r}") | ||
| if profile == "v2607": | ||
| hindi = tokenizers["hindi_phoneme"] | ||
| hindi_g2p = hindi.get("g2p") | ||
| hindi_g2p_locale = hindi_g2p.get("locale") if isinstance(hindi_g2p, dict) else None | ||
| if hindi.get("locale") != "hi-IN" or hindi_g2p_locale != "hi-IN": | ||
| raise ValueError("unsupported v2607 Hindi IPA locale") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if tokenizers["portuguese_Brazilian_phoneme"].get("locale_specific_punct") is not False: | ||
| raise ValueError("unsupported v2607 Portuguese punctuation mode") | ||
| if cfg.get("language_to_tokenizer_mapping") != V2607_LANGUAGE_MAPPING: | ||
| raise ValueError("unsupported v2607 language_to_tokenizer_mapping") | ||
| expected_vocab, expected_stacking = TOKENIZER_PROFILE_DIMENSIONS[profile] | ||
| if (text_vocab, frame_stacking) != (expected_vocab, expected_stacking): | ||
| raise ValueError( | ||
| f"Magpie tokenizer profile {profile} requires text_vocab_size={expected_vocab} " | ||
| f"and frame_stacking_factor={expected_stacking}, got " | ||
| f"text_vocab_size={text_vocab} and frame_stacking_factor={frame_stacking}" | ||
| ) | ||
| return profile | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.