3.4 KiB
Implementing a Model
-
Implement layers.
You can either implement the layers under
TTS/tts/layers/new_model.pyor in the model fileTTS/tts/model/new_model.py. You can also reuse layers already implemented. -
Test layers.
We keep tests under
testsfolder. You can addttslayers tests undertts_testsfolder. Basic tests are checking input-output tensor shapes and output values for a given input. Consider testing extreme cases that are more likely to cause problems likezerotensors. -
Implement loss function.
We keep loss functions under
TTS/tts/layers/losses.py. You can also mix-and-match implemented loss functions as you like.A loss function returns a dictionary in a format
{’loss’: loss, ‘loss1’:loss1 ...}and the dictionary must at least define thelosskey which is the actual value used by the optimizer. All the items in the dictionary are automatically logged on the terminal and the Tensorboard. -
Test the loss function.
As we do for the layers, you need to test the loss functions too. You need to check input/output tensor shapes, expected output values for a given input tensor. For instance, certain loss functions have upper and lower limits and it is a wise practice to test with the inputs that should produce these limits.
-
Implement
MyModel.In 🐸TTS, a model class is a self-sufficient implementation of a model directing all the interactions with the other components. It is enough to implement the API provided by the
BaseModelclass to comply.A model interacts with the
Trainer APIfor training,Synthesizer APIfor inference and testing.A 🐸TTS model must return a dictionary by the
forward()andinference()functions. This dictionary must also include themodel_outputskey that is considered as the main model output by theTrainerandSynthesizer.You can place your
ttsmodel implementation underTTS/tts/models/new_model.pythen inherit and implement theBaseTTS.There is also the
callbackinterface by which you can manipulate both the model and theTrainerstates. Callbacks give you the infinite flexibility to add custom behaviours for your model and training routines.For more details, see {ref}
BaseTTS <Base TTS Model>and :obj:TTS.utils.callbacks. -
Optionally, define
MyModelArgs.MyModelArgsis a 👨✈️Coqpit class that sets all the class arguments of theMyModel. It should be enough to pass anMyModelArgsinstance to initiate theMyModel. -
Test
MyModel.As the layers and the loss functions, it is recommended to test your model. One smart way for testing is that you create two models with the exact same weights. Then we run a training loop with one of these models and compare the weights with the other model. All the weights need to be different in a passing test. Otherwise, it is likely that a part of the model is malfunctioning or not even attached to the model's computational graph.
-
Define
MyModelConfig.Place
MyModelConfigfile underTTS/models/configs. It is enough to inherit theBaseTTSConfigto make your config compatible with theTrainer. You should also includeMyModelArgsas a field if defined. The rest of the fields should define the model specific values and parameters. -
Write Docstrings.
We love you more when you document your code. ❤️