vall-e/vall_e/models/__init__.py

59 lines
1.3 KiB
Python
Raw Normal View History

2023-08-02 21:53:35 +00:00
def get_model(config, training=True):
name = config.name
2023-08-04 01:26:36 +00:00
2024-06-12 04:59:28 +00:00
if "len" in config.capabilities:
from .nar import NAR
model = NAR(
n_text_tokens=config.text_tokens,
n_audio_tokens=config.audio_tokens,
d_model=config.dim,
n_heads=config.heads,
n_layers=config.layers,
n_experts=config.experts,
2024-06-04 02:28:49 +00:00
p_dropout=config.dropout,
2024-06-04 02:28:49 +00:00
l_padding = config.input_alignment,
2024-06-04 02:28:49 +00:00
2024-06-09 01:30:15 +00:00
training = training,
config = config,
)
elif config.experimental.hf:
2024-06-12 04:59:28 +00:00
from .experimental import Model as Experimental
model = Experimental(
2024-06-09 01:30:15 +00:00
n_text_tokens=config.text_tokens,
n_audio_tokens=config.audio_tokens,
2024-06-12 04:59:28 +00:00
2024-06-09 01:30:15 +00:00
d_model=config.dim,
n_layers=config.layers,
2024-06-12 04:59:28 +00:00
n_heads=config.heads,
2024-06-09 01:30:15 +00:00
p_dropout=config.dropout,
2024-06-12 04:59:28 +00:00
config = config,
2024-06-04 02:28:49 +00:00
)
else:
2024-06-12 04:59:28 +00:00
from .ar_nar import AR_NAR
model = AR_NAR(
n_text_tokens=config.text_tokens,
n_audio_tokens=config.audio_tokens,
d_model=config.dim,
n_heads=config.heads,
2024-06-12 04:59:28 +00:00
n_layers=config.layers,
n_experts=config.experts,
p_dropout=config.dropout,
2024-06-12 04:59:28 +00:00
l_padding = config.input_alignment,
training = training,
config = config,
2024-06-04 02:28:49 +00:00
)
2023-08-02 21:53:35 +00:00
print(f"{name} ({next(model.parameters()).dtype}): {sum(p.numel() for p in model.parameters() if p.requires_grad)} parameters")
2023-08-02 21:53:35 +00:00
return model
def get_models(models, training=True):
return { model.full_name: get_model(model, training=training) for model in models }