diff --git a/codes/models/gpt_voice/unet_diffusion_tts5.py b/codes/models/gpt_voice/unet_diffusion_tts5.py index 66654ff1..924118b9 100644 --- a/codes/models/gpt_voice/unet_diffusion_tts5.py +++ b/codes/models/gpt_voice/unet_diffusion_tts5.py @@ -178,6 +178,7 @@ class DiffusionTts(nn.Module): scale_factor=2, conditioning_inputs_provided=True, time_embed_dim_multiplier=4, + transformer_depths=8, nil_guidance_fwd_proportion=.3, ): super().__init__() @@ -220,7 +221,7 @@ class DiffusionTts(nn.Module): use_pos_emb=False, attn_layers=Encoder( dim=embedding_dim, - depth=8, + depth=transformer_depths, heads=num_heads, ff_dropout=dropout, attn_dropout=dropout, @@ -292,7 +293,7 @@ class DiffusionTts(nn.Module): use_pos_emb=False, attn_layers=Encoder( dim=ch, - depth=8, + depth=transformer_depths, heads=num_heads, ff_dropout=dropout, attn_dropout=dropout, @@ -301,8 +302,6 @@ class DiffusionTts(nn.Module): rotary_pos_emb=True, ) ) - - self.middle_block = TimestepEmbedSequential( ResBlock( ch, diff --git a/codes/scripts/audio/gen/speech_synthesis_utils.py b/codes/scripts/audio/gen/speech_synthesis_utils.py index 6fc2ad31..1003e790 100644 --- a/codes/scripts/audio/gen/speech_synthesis_utils.py +++ b/codes/scripts/audio/gen/speech_synthesis_utils.py @@ -46,12 +46,12 @@ def load_gpt_conditioning_inputs_from_directory(path, num_candidates=3, sample_r return torch.stack(related_mels, dim=0) -def load_discrete_vocoder_diffuser(trained_diffusion_steps=4000, desired_diffusion_steps=200): +def load_discrete_vocoder_diffuser(trained_diffusion_steps=4000, desired_diffusion_steps=200, schedule='linear'): """ Helper function to load a GaussianDiffusion instance configured for use as a vocoder. """ return SpacedDiffusion(use_timesteps=space_timesteps(trained_diffusion_steps, [desired_diffusion_steps]), model_mean_type='epsilon', - model_var_type='learned_range', loss_type='mse', betas=get_named_beta_schedule('linear', trained_diffusion_steps)) + model_var_type='learned_range', loss_type='mse', betas=get_named_beta_schedule(schedule, trained_diffusion_steps)) def do_spectrogram_diffusion(diffusion_model, dvae_model, diffuser, mel_codes, conditioning_input, spectrogram_compression_factor=128, plt_spec=False): diff --git a/codes/scripts/audio/gen/use_diffuse_tts.py b/codes/scripts/audio/gen/use_diffuse_tts.py index 1be19b79..16535ef2 100644 --- a/codes/scripts/audio/gen/use_diffuse_tts.py +++ b/codes/scripts/audio/gen/use_diffuse_tts.py @@ -19,19 +19,32 @@ def ceil_multiple(base, multiple): if __name__ == '__main__': + conditioning_clips = { + # Male + 'simmons': 'Y:\\clips\\books1\\754_Dan Simmons - The Rise Of Endymion 356 of 450\\00026.wav', + 'carlin': 'Y:\\clips\\books1\\12_dchha13 Bubonic Nukes\\00097.wav', + 'entangled': 'Y:\\clips\\books1\\3857_25_The_Entangled_Bank__000000000\\00123.wav', + 'snowden': 'Y:\\clips\\books1\\7658_Edward_Snowden_-_Permanent_Record__000000004\\00027.wav', + # Female + 'the_doctor': 'Y:\\clips\\books2\\37062___The_Doctor__000000003\\00206.wav', + 'puppy': 'Y:\\clips\\books2\\17830___3_Puppy_Kisses__000000002\\00046.wav', + 'adrift': 'Y:\\clips\\books2\\5608_Gear__W_Michael_-_Donovan_1-5_(2018-2021)_(book_4_Gear__W_Michael_-_Donovan_5_-_Adrift_(2021)_Gear__W_Michael_-_Adrift_(Donovan_5)_—_82__000000000\\00019.wav', + } + parser = argparse.ArgumentParser() - parser.add_argument('-opt', type=str, help='Path to options YAML file used to train the diffusion model', default='X:\\dlas\\experiments\\train_diffusion_tts_medium\\train_diffusion_tts_medium.yml') + parser.add_argument('-opt', type=str, help='Path to options YAML file used to train the diffusion model', default='X:\\dlas\\experiments\\train_diffusion_tts5_medium.yml') parser.add_argument('-diffusion_model_name', type=str, help='Name of the diffusion model in opt.', default='generator') - parser.add_argument('-diffusion_model_path', type=str, help='Path to saved model weights', default='X:\\dlas\\experiments\\train_diffusion_tts_medium\\models\\38500_generator_ema.pth') + parser.add_argument('-diffusion_model_path', type=str, help='Path to saved model weights', default='X:\\dlas\\experiments\\train_diffusion_tts5_medium\\models\\14500_generator_ema.pth') parser.add_argument('-aligned_codes', type=str, help='Comma-delimited list of integer codes that defines text & prosody. Get this by apply W2V to an existing audio clip or from a bespoke generator.', default='0,0,0,0,10,10,0,4,0,7,0,17,4,4,0,25,5,0,13,13,0,22,4,4,0,21,15,15,7,0,0,14,4,4,6,8,4,4,0,0,12,5,0,0,5,0,4,4,22,22,8,16,16,0,4,4,4,0,0,0,0,0,0,0') # Default: 'i am very glad to see you', libritts/train-clean-100/103/1241/103_1241_000017_000001.wav. # -cond "Y:\libritts/train-clean-100/103/1241/103_1241_000017_000001.wav" - parser.add_argument('-cond', type=str, help='Path to the conditioning input audio file.', default='Y:\\clips\\books1\\754_Dan Simmons - The Rise Of Endymion 356 of 450\\00026.wav') + parser.add_argument('-cond', type=str, help='Type of conditioning voice', default='adrift') parser.add_argument('-diffusion_steps', type=int, help='Number of diffusion steps to perform to create the generate. Lower steps reduces quality, but >40 is generally pretty good.', default=100) + parser.add_argument('-diffusion_schedule', type=str, help='Type of diffusion schedule that was used', default='cosine') parser.add_argument('-output_path', type=str, help='Where to store outputs.', default='../results/use_diffuse_tts') - parser.add_argument('-sample_rate', type=int, help='Model sample rate', default=11025) - parser.add_argument('-cond_sample_rate', type=int, help='Model sample rate', default=22050) - parser.add_argument('-device', type=str, help='Device to run on', default='cpu') + parser.add_argument('-sample_rate', type=int, help='Model sample rate', default=5500) + parser.add_argument('-cond_sample_rate', type=int, help='Conditioning sample rate', default=5500) + parser.add_argument('-device', type=str, help='Device to run on', default='cuda') args = parser.parse_args() os.makedirs(args.output_path, exist_ok=True) @@ -42,8 +55,8 @@ if __name__ == '__main__': print("Loading data..") aligned_codes = torch.tensor([int(s) for s in args.aligned_codes.split(',')]).to(args.device) - diffuser = load_discrete_vocoder_diffuser(desired_diffusion_steps=args.diffusion_steps) - cond = load_audio(args.cond, args.cond_sample_rate).to(args.device) + diffuser = load_discrete_vocoder_diffuser(desired_diffusion_steps=args.diffusion_steps, schedule=args.diffusion_schedule) + cond = load_audio(conditioning_clips[args.cond], args.cond_sample_rate).to(args.device) if cond.shape[-1] > 88000: cond = cond[:,:88000] diff --git a/codes/train.py b/codes/train.py index 0a159119..a3c4edd2 100644 --- a/codes/train.py +++ b/codes/train.py @@ -299,7 +299,7 @@ class Trainer: if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('-opt', type=str, help='Path to option YAML file.', default='../options/train_diffusion_tts5_medium.yml') + parser.add_argument('-opt', type=str, help='Path to option YAML file.', default='../experiments/train_diffusion_tts_experimental_fp16/train_diffusion_tts.yml') parser.add_argument('--launcher', choices=['none', 'pytorch'], default='none', help='job launcher') parser.add_argument('--local_rank', type=int, default=0) args = parser.parse_args() diff --git a/codes/trainer/steps.py b/codes/trainer/steps.py index 9fecdff3..92b08b01 100644 --- a/codes/trainer/steps.py +++ b/codes/trainer/steps.py @@ -145,6 +145,7 @@ class ConfigurableStep(Module): opt = ZeroRedundancyOptimizer(params_weights, optimizer_class=torch.optim.AdamW, lr=opt_config['lr'], weight_decay=opt_get(opt_config, ['weight_decay'], 1e-2), betas=(opt_get(opt_config, ['beta1'], .9), opt_get(opt_config, ['beta2'], .999))) + opt.param_groups[0]['initial_lr'] = opt_config['lr'] opt._group_names = [] elif self.step_opt['optimizer'] == 'lars': from trainer.optimizers.larc import LARC