返回 F5-TTS
count_params_gflops.py
根目录 / src / f5_tts / scripts / count_params_gflops.py
1 import os
2 import sys
3
4
5 sys.path.append(os.getcwd())
6
7 import thop
8 import torch
9
10 from f5_tts.model import CFM, DiT
11
12
13 """ ~155M """
14 # transformer = UNetT(dim = 768, depth = 20, heads = 12, ff_mult = 4)
15 # transformer = UNetT(dim = 768, depth = 20, heads = 12, ff_mult = 4, text_dim = 512, conv_layers = 4)
16 # transformer = DiT(dim = 768, depth = 18, heads = 12, ff_mult = 2)
17 # transformer = DiT(dim = 768, depth = 18, heads = 12, ff_mult = 2, text_dim = 512, conv_layers = 4)
18 # transformer = DiT(dim = 768, depth = 18, heads = 12, ff_mult = 2, text_dim = 512, conv_layers = 4, long_skip_connection = True)
19 # transformer = MMDiT(dim = 512, depth = 16, heads = 16, ff_mult = 2)
20
21 """ ~335M """
22 # FLOPs: 622.1 G, Params: 333.2 M
23 # transformer = UNetT(dim = 1024, depth = 24, heads = 16, ff_mult = 4)
24 # FLOPs: 363.4 G, Params: 335.8 M
25 transformer = DiT(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)
26
27
28 model = CFM(transformer=transformer)
29 target_sample_rate = 24000
30 n_mel_channels = 100
31 hop_length = 256
32 duration = 20
33 frame_length = int(duration * target_sample_rate / hop_length)
34 text_length = 150
35
36 flops, params = thop.profile(
37 model, inputs=(torch.randn(1, frame_length, n_mel_channels), torch.zeros(1, text_length, dtype=torch.long))
38 )
39 print(f"FLOPs: {flops / 1e9} G")
40 print(f"Params: {params / 1e6} M")
41
41 lines PYTHON