Repository: NVIDIA/NeMo

Issue:
FastPitch fine-tunning using TDataset
The tutorial on FastPitch fine-tunning (`NeMo/tutorials/tts/`) is based on the `fastpitch_align.yaml` and `AudioToCharWithPriorAndPitchDataset`, which will soon be deprecated. Is there any guidance how to finetune a pretrained FastPitch model based on the `fastpitch_align_v1.05.yaml` and thus `TDataset`?


Discussion:

Resolving patch:
diff --git a/nemo/collections/tts/models/fastpitch.py b/nemo/collections/tts/models/fastpitch.py
--- a/nemo/collections/tts/models/fastpitch.py
+++ b/nemo/collections/tts/models/fastpitch.py
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from typing import Optional
+
 import torch
 from hydra.utils import instantiate
 from omegaconf import DictConfig, open_dict
@@ -217,7 +219,7 @@ def parse(self, str_input: str, normalize=True) -> torch.tensor:
             "text": NeuralType(('B', 'T_text'), TokenIndex()),
             "durs": NeuralType(('B', 'T_text'), TokenDurationType()),
             "pitch": NeuralType(('B', 'T_audio'), RegressionValuesType()),
-            "speaker": NeuralType(('B'), Index()),
+            "speaker": NeuralType(('B'), Index(), optional=True),
             "pace": NeuralType(optional=True),
             "spec": NeuralType(('B', 'D', 'T_spec'), MelSpectrogramType(), optional=True),
             "attn_prior": NeuralType(('B', 'T_spec', 'T_text'), ProbsType(), optional=True),
@@ -231,7 +233,7 @@ def forward(
         text,
         durs=None,
         pitch=None,
-        speaker=0,
+        speaker=None,
         pace=1.0,
         spec=None,
         attn_prior=None,
@@ -251,7 +253,9 @@ def forward(
         )
 
     @typecheck(output_types={"spect": NeuralType(('B', 'D', 'T_spec'), MelSpectrogramType())})
-    def generate_spectrogram(self, tokens: 'torch.tensor', speaker: int = 0, pace: float = 1.0) -> torch.tensor:
+    def generate_spectrogram(
+        self, tokens: 'torch.tensor', speaker: Optional[int] = None, pace: float = 1.0
+    ) -> torch.tensor:
         if self.training:
             logging.warning("generate_spectrogram() is meant to be called in eval mode.")
         if isinstance(speaker, int):
diff --git a/nemo/collections/tts/modules/fastpitch.py b/nemo/collections/tts/modules/fastpitch.py
--- a/nemo/collections/tts/modules/fastpitch.py
+++ b/nemo/collections/tts/modules/fastpitch.py
@@ -179,7 +179,7 @@ def input_types(self):
             "text": NeuralType(('B', 'T_text'), TokenIndex()),
             "durs": NeuralType(('B', 'T_text'), TokenDurationType()),
             "pitch": NeuralType(('B', 'T_audio'), RegressionValuesType()),
-            "speaker": NeuralType(('B'), Index()),
+            "speaker": NeuralType(('B'), Index(), optional=True),
             "pace": NeuralType(optional=True),
             "spec": NeuralType(('B', 'D', 'T_spec'), MelSpectrogramType(), optional=True),
             "attn_prior": NeuralType(('B', 'T_spec', 'T_text'), ProbsType(), optional=True),
diff --git a/nemo/collections/tts/torch/helpers.py b/nemo/collections/tts/torch/helpers.py
--- a/nemo/collections/tts/torch/helpers.py
+++ b/nemo/collections/tts/torch/helpers.py
@@ -26,10 +26,10 @@ class BetaBinomialInterpolator:
         The implementation is taken from https://github.com/NVIDIA/DeepLearningExamples.
     """
 
-    def __init__(self, round_mel_len_to=100, round_text_len_to=20):
+    def __init__(self, round_mel_len_to=50, round_text_len_to=10, cache_size=500):
         self.round_mel_len_to = round_mel_len_to
         self.round_text_len_to = round_text_len_to
-        self.bank = functools.lru_cache(beta_binomial_prior_distribution)
+        self.bank = functools.lru_cache(maxsize=cache_size)(beta_binomial_prior_distribution)
 
     def round(self, val, to):
         return max(1, int(np.round((val + 1) / to))) * to


Test patch: