CoolFace
Apppublic

ThreadAbort/E2-F5-TTS

sourceHugging Faceupdated 1y agoView on Hugging Face
26likes
test_train.py92 linesDownload Raw Back to root
1from model import CFM, UNetT, DiT, MMDiT, Trainer2from model.utils import get_tokenizer3from model.dataset import load_dataset4 5 6# -------------------------- Dataset Settings --------------------------- #7 8target_sample_rate = 240009n_mel_channels = 10010hop_length = 25611 12tokenizer = "pinyin"13dataset_name = "Emilia_ZH_EN"14 15 16# -------------------------- Training Settings -------------------------- #17 18exp_name = "F5TTS_Base"  # F5TTS_Base | E2TTS_Base19 20learning_rate = 7.5e-521 22batch_size_per_gpu = 38400  # 8 GPUs, 8 * 38400 = 30720023batch_size_type = "frame"  # "frame" or "sample"24max_samples = 64  # max sequences per batch if use frame-wise batch_size. we set 32 for small models, 64 for base models25grad_accumulation_steps = 1  # note: updates = steps / grad_accumulation_steps26max_grad_norm = 1.27 28epochs = 11  # use linear decay, thus epochs control the slope29num_warmup_updates = 20000  # warmup steps30save_per_updates = 50000  # save checkpoint per steps31last_per_steps = 5000  # save last checkpoint per steps32 33# model params34if exp_name == "F5TTS_Base":35    wandb_resume_id = None36    model_cls = DiT37    model_cfg = dict(dim = 1024, depth = 22, heads = 16, ff_mult = 2, text_dim = 512, conv_layers = 4)38elif exp_name == "E2TTS_Base":39    wandb_resume_id = None40    model_cls = UNetT41    model_cfg = dict(dim = 1024, depth = 24, heads = 16, ff_mult = 4)42 43 44# ----------------------------------------------------------------------- #45 46def main():47 48    vocab_char_map, vocab_size = get_tokenizer(dataset_name, tokenizer)49 50    mel_spec_kwargs = dict(51            target_sample_rate = target_sample_rate, 52            n_mel_channels = n_mel_channels,53            hop_length = hop_length,54        )55    56    e2tts = CFM(57        transformer = model_cls(58            **model_cfg,59            text_num_embeds = vocab_size, 60            mel_dim = n_mel_channels61        ),62        mel_spec_kwargs = mel_spec_kwargs,63        vocab_char_map = vocab_char_map,64    )65 66    trainer = Trainer(67        e2tts,68        epochs, 69        learning_rate,70        num_warmup_updates = num_warmup_updates,71        save_per_updates = save_per_updates, 72        checkpoint_path = f'ckpts/{exp_name}',73        batch_size = batch_size_per_gpu, 74        batch_size_type = batch_size_type,75        max_samples = max_samples,76        grad_accumulation_steps = grad_accumulation_steps,77        max_grad_norm = max_grad_norm,78        wandb_project = "CFM-TTS",79        wandb_run_name = exp_name,80        wandb_resume_id = wandb_resume_id,81        last_per_steps = last_per_steps,82    )83 84    train_dataset = load_dataset(dataset_name, tokenizer, mel_spec_kwargs=mel_spec_kwargs)85    trainer.train(train_dataset, 86                  resumable_with_seed = 666 # seed for shuffling dataset87                  )88 89 90if __name__ == '__main__':91    main()92