Spaces:
Running
Running
File size: 5,560 Bytes
9d61c9b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Install env deps"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "268d87b8-54a2-4e09-bbef-ed28f93719f3",
"metadata": {},
"outputs": [],
"source": [
"!pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip3 install numba numpy scikit-learn tqdm pynini datasets deep-phonemizer nemo-text-processing piq soundfile transformers unidecode tensorboard librosa gpustat chardet"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0662705-c8a6-4588-9435-07aecb004825",
"metadata": {},
"outputs": [],
"source": [
"!pip install lightning"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add tensorboard to track the basic metrics and outputs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "089094c9-4b03-47a8-a500-50f15d9a8ff7",
"metadata": {},
"outputs": [],
"source": [
"%load_ext tensorboard"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "34c26745-47fd-4ad8-9bfc-d3952a406b2a",
"metadata": {},
"outputs": [],
"source": [
"default_root_dir=\"logs/acoustic\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de8ed1db-2d23-4f34-abad-43d287a2ffd9",
"metadata": {},
"outputs": [],
"source": [
"%tensorboard --logdir {default_root_dir}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9d26af70-b7ea-4e64-888c-106a984a3fdd",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from lightning.pytorch import Trainer\n",
"from lightning.pytorch.callbacks import StochasticWeightAveraging\n",
"from lightning.pytorch.loggers import TensorBoardLogger\n",
"from lightning.pytorch.tuner.tuning import Tuner\n",
"\n",
"from training.modules import AcousticModule, VocoderModule, AcousticDataModule\n",
"\n",
"os.environ[\"CUDA_LAUNCH_BLOCKING\"]=\"1\"\n",
"CUDA_LAUNCH_BLOCKING=1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9fdbeb42-0158-4c77-874b-6fd3f72e1219",
"metadata": {},
"outputs": [],
"source": [
"accelerator=\"cuda\"\n",
"ckpt_acoustic=\"./checkpoints/am_pitche_stats_with_vocoder.ckpt\"\n",
"ckpt_vocoder=\"./checkpoints/vocoder.ckpt\"\n",
"\n",
"# Control Validation Frequency\n",
"check_val_every_n_epoch=10\n",
"# Accumulate gradients\n",
"accumulate_grad_batches=5\n",
"# SWA learning rate\n",
"swa_lrs=1e-2\n",
"\n",
"# Stochastic Weight Averaging (SWA) can make your models generalize\n",
"# better at virtually no additional cost.\n",
"# This can be used with both non-trained and trained models.\n",
"# The SWA procedure smooths the loss landscape thus making it\n",
"# harder to end up in a local minimum during optimization.\n",
"callbacks = [\n",
" StochasticWeightAveraging(swa_lrs=swa_lrs),\n",
" # TODO: Add EarlyStopping Callback\n",
"]\n",
"\n",
"tensorboard = TensorBoardLogger(save_dir=default_root_dir)\n",
"\n",
"trainer = Trainer(\n",
" logger=tensorboard,\n",
" # Save checkpoints to the `default_root_dir` directory\n",
" default_root_dir=default_root_dir,\n",
" accelerator=accelerator,\n",
" check_val_every_n_epoch=check_val_every_n_epoch,\n",
" accumulate_grad_batches=accumulate_grad_batches,\n",
" max_epochs=-1,\n",
" callbacks=callbacks,\n",
" devices=2,\n",
")\n",
"\n",
"# Load the pretrained weights for the vocoder\n",
"vocoder_module = VocoderModule.load_from_checkpoint(\n",
" ckpt_vocoder,\n",
")\n",
"\n",
"module = AcousticModule.load_from_checkpoint(\n",
" ckpt_acoustic,\n",
" vocoder_module=vocoder_module,\n",
")\n",
"\n",
"datamodule = AcousticDataModule(batch_size=module.train_config.batch_size)\n",
"\n",
"# Create a Tuner\n",
"tuner = Tuner(trainer)\n",
"\n",
"# finds learning rate automatically\n",
"# sets hparams.lr or hparams.learning_rate to that learning rate\n",
"tuner.lr_find(module)\n",
"\n",
"tuner.scale_batch_size(module, datamodule=datamodule)\n",
"\n",
"# vocoder_module = VocoderModule()\n",
"# module = AcousticModule()\n",
"\n",
"# train_dataloader = module.train_dataloader()\n",
"\n",
"trainer.fit(model=module) #, train_dataloaders=train_dataloader)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16370731-72bb-497a-a1cc-00b0a5d1496f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"environment": {
"kernel": "conda-env-tts_framework-py",
"name": "workbench-notebooks.m111",
"type": "gcloud",
"uri": "gcr.io/deeplearning-platform-release/workbench-notebooks:m111"
},
"kernelspec": {
"display_name": "tts_framework",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|