(need to verify) added modifying model size and config bool to align with VALL-E continuous' methodology
This commit is contained in:
parent
5c8694db8e
commit
2bc2d08b09
|
@ -140,6 +140,8 @@ class Dataset:
|
|||
|
||||
tasks_list: list[str] = field(default_factory=lambda: ["tts"])
|
||||
|
||||
continuous: bool = False # VALL-E continuous, as explained in the paper
|
||||
|
||||
@property
|
||||
def min_phones(self):
|
||||
return self.phones_range[0]
|
||||
|
@ -156,20 +158,13 @@ class Dataset:
|
|||
@dataclass()
|
||||
class Model:
|
||||
name: str = ""
|
||||
size: str = "full"
|
||||
size: str | float | dict = "full"
|
||||
resp_levels: int = 1
|
||||
prom_levels: int = 8
|
||||
tasks: int = 8 # ["tts", "ns", "sr", "tse", "cse", "nse"] and leaves two more for anything else I want (like "svc")
|
||||
arch_type: str = "transformer"
|
||||
training: bool = True
|
||||
|
||||
@property
|
||||
def scale(self):
|
||||
if self.size == "quarter":
|
||||
return 0.25
|
||||
if self.size == "half":
|
||||
return 0.5
|
||||
return 1.0
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
|
@ -187,30 +182,52 @@ class Model:
|
|||
|
||||
@property
|
||||
def tokens(self):
|
||||
if isinstance(self.size, dict) and hasattr(self.size, "tokens"):
|
||||
return self.size['tokens']
|
||||
|
||||
return 1024
|
||||
|
||||
@property
|
||||
def dim(self):
|
||||
if isinstance(self.size, dict) and hasattr(self.size, "dim"):
|
||||
return self.size['dim']
|
||||
|
||||
if isinstance(self.size, float):
|
||||
return math.floor(1024 * self.size)
|
||||
|
||||
if self.size == "quarter":
|
||||
return 256
|
||||
if self.size == "half":
|
||||
return 512
|
||||
if self.size == "full":
|
||||
return 1024
|
||||
if self.size == "double":
|
||||
return 2048
|
||||
raise ValueError
|
||||
|
||||
@property
|
||||
def heads(self):
|
||||
if isinstance(self.size, dict) and hasattr(self.size, "heads"):
|
||||
return self.size['heads']
|
||||
|
||||
if isinstance(self.size, float):
|
||||
return math.floor(16 * self.size)
|
||||
|
||||
if self.size == "quarter":
|
||||
return 4
|
||||
if self.size == "half":
|
||||
return 8
|
||||
if self.size == "full":
|
||||
return 16
|
||||
if self.size == "double":
|
||||
return 32
|
||||
raise ValueError
|
||||
|
||||
@property
|
||||
def layers(self):
|
||||
if isinstance(self.size, dict) and hasattr(self.size, "layers"):
|
||||
return self.size['layers']
|
||||
|
||||
return 12
|
||||
|
||||
@dataclass()
|
||||
|
|
|
@ -313,7 +313,15 @@ class Dataset(_Dataset):
|
|||
noise_scale = 0.25
|
||||
# text-to-speech
|
||||
if task == "tts":
|
||||
proms = self.sample_prompts(spkr_name, ignore=path) if random.random() < cfg.dataset.random_utterance else resps
|
||||
trim_length = int(cfg.dataset.prompt_duration * 75)
|
||||
# VALL-E continuous
|
||||
# ignore if target utterance is shorter than prompt duration
|
||||
# to-do: actually do this for the AR only as I don't think the paper trained the NAR for this
|
||||
if cfg.dataset.continuous and trim_length > resps.shape[0]:
|
||||
proms = resps[:trim_length, :]
|
||||
resps = resps[trim_length:, :]
|
||||
else:
|
||||
proms = self.sample_prompts(spkr_name, ignore=path) if random.random() < cfg.dataset.random_utterance else resps
|
||||
# noise suppression || speech removal
|
||||
elif task == "ns" or task == "sr":
|
||||
# sample random noise
|
||||
|
|
|
@ -185,11 +185,18 @@ def encode_from_file(path, device="cuda"):
|
|||
# trims from the start, up to `target`
|
||||
def trim( qnt, target ):
|
||||
length = max( qnt.shape[0], qnt.shape[1] )
|
||||
start = 0
|
||||
end = start + target
|
||||
if end >= length:
|
||||
start = length - target
|
||||
end = length
|
||||
if target > 0:
|
||||
start = 0
|
||||
end = start + target
|
||||
if end >= length:
|
||||
start = length - target
|
||||
end = length
|
||||
# negative length specified, trim from end
|
||||
else:
|
||||
start = length + target
|
||||
end = length
|
||||
if start < 0:
|
||||
start = 0
|
||||
|
||||
return qnt[start:end] if qnt.shape[0] > qnt.shape[1] else qnt[:, start:end]
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ class AR(Base):
|
|||
|
||||
@property
|
||||
def arch_type(self) -> bool:
|
||||
if hasattr(self, "_cfg"):
|
||||
return self._cfg.arch_type
|
||||
return cfg.models.ar.arch_type
|
||||
|
||||
@property
|
||||
|
@ -31,6 +33,8 @@ class AR(Base):
|
|||
|
||||
@property
|
||||
def n_resp_levels(self) -> int:
|
||||
if hasattr(self, "_cfg"):
|
||||
return self._cfg.resp_levels
|
||||
return cfg.models.ar.resp_levels
|
||||
|
||||
@property
|
||||
|
|
|
@ -387,6 +387,9 @@ def example_usage():
|
|||
from .ar import AR
|
||||
from .nar import NAR
|
||||
|
||||
from ..models import get_models
|
||||
from ..config import Model as ModelCfg
|
||||
|
||||
device = "cuda"
|
||||
x8 = partial(repeat, pattern="t -> t l", l=2)
|
||||
symmap = {'<s>': 1, '</s>': 2, ' ': 3, '.': 4, ',': 5, '!': 6, '?': 7, 'p': 7, 'iː': 8, 'ɚ': 9, 'ˌ': 10, 'dˌ': 11, 'mˌ': 12, 'd': 13, 'ɹ': 14, 'tˈ': 15, 'pˌ': 16, 'uː': 17, 'l': 18, 'æ': 19, 'ɛ': 20, 'ɪ': 21, 'j': 22, 'ʊ': 23, 't': 24, 'n': 25, 'v': 26, 'a': 27, 'o': 28, 'ŋ': 29, 'w': 30, 'ʌ': 31, 'hˈ': 32, 'ɡˈ': 33, 'ə': 34, 'θˈ': 35, 'dˈ': 36, 'wˌ': 37, 'h': 38, 'z': 39, 'k': 40, 'ð': 41, 'ɡˌ': 42, 'ˈ': 43, 'fˈ': 44, 'i': 45, 's': 46, 'ʃ': 47, 'wˈ': 48, 'ðˈ': 49, 'ɹˈ': 50, 'lˈ': 51, 'ɡ': 52, 'oː': 53, 'mˈ': 54, 'e': 55, 'ɑː': 56, 'nˈ': 57, 'm': 58, 'θˌ': 59, 'sˈ': 60, 'f': 61, 'ɔː': 62, 'hˌ': 63, 'b': 64, 'jˈ': 65, 'ɐ': 66, 'ʒˈ': 67, 'θ': 68, 'bˈ': 69, 'ɾ': 70, 'ɜː': 71, 'ʌˈ': 72, 'ʃˌ': 73, 'bˌ': 74, 'kˈ': 75, 'ɔ': 76, 'zˈ': 77, 'ᵻ': 78, 'kˌ': 79, 'vˈ': 80, 'fˌ': 81, 'ʒ': 82, 'ʃˈ': 83, 'ɹˌ': 84, 'tˌ': 85, 'pˈ': 86, 'ðˌ': 87, 'sˌ': 88, 'nˌ': 89, 'lˌ': 90, '̩': 91, 'ʔ': 92, 'vˌ': 93, 'ɪˈ': 94, '"': 95, 'ɪˌ': 96, 'ʒˌ': 97, 'uːˌ': 98, 'ʊˈ': 99, 'jˌ': 100, 'uːˈ': 101, 'iːˈ': 102, 'zˌ': 103, '.ˈ': 104, '…': 105, 'ŋˌ': 106, 'ɐˌ': 107, '—ˈ': 108, 'iˌ': 109, 'iːˌ': 110, 'ɛː': 111, ')': 112, ')ˈ': 113, '(': 114, 'u': 115, '-': 116, 'ɖˈ': 117, 'iˈ': 118, 'ʰˈ': 119, 'ɟˈ': 120, '̃': 121, 'eː': 122, 'ɾˈ': 123, 'r': 124, 'ʰ': 125, '-ˌ': 126, 'ɫ': 127, 'q': 128, '—': 129, 'ʊˌ': 130, 'aː': 131, 'cˈ': 132, '…ˈ': 133, 'c': 134, 'ɳ': 135, 'ɐˈ': 136, 'x': 137, 'ʔˌ': 138, '.ˌ': 139, 'ɑ': 140, '?ˈ': 141, '̩ˈ': 142, '"ˈ': 143, ',ˈ': 144, 'ŋˈ': 145, 'əˌ': 146, '!ˈ': 147, '"ˌ': 148, '?ˌ': 149, ',ˌ': 150, '—ˌ': 151, '̩ˌ': 152, 'əˈ': 153, '!ˌ': 154, 'ɬ': 155, 'ʲ': 156, '¡': 157, 'ɯ': 158, 'qˌ': 159, 'ʑ': 160, 'ʑˈ': 161, '¿': 162, 'ɑːˈ': 163, 'iːː': 164, 'ɛˈ': 165, '¡ˈ': 166, 'æˈ': 167, 'ç': 168, 'ɾˌ': 169, 'ᵻˈ': 170, 'xˈ': 171, 'ɔːˈ': 172, ';': 173, 'ɬˌ': 174, ':': 175, 'ʔˈ': 176, 'ɑːˌ': 177, 'ɬˈ': 178}
|
||||
|
@ -395,13 +398,20 @@ def example_usage():
|
|||
phones = [f"<s>"] + [ " " if not p else p for p in split ] + [f"</s>"]
|
||||
return torch.tensor([*map(symmap.get, phones)]).to()
|
||||
|
||||
models = get_models({
|
||||
"ar": Model(name="ar", resp_levels=1, prom_levels=8, tasks=8, training=True, size=1),
|
||||
"nar": Model(name="nar", resp_levels=7, prom_levels=8, tasks=8, training=True, size=1)}
|
||||
)
|
||||
"""
|
||||
model_cfg = ModelCfg()
|
||||
kwargs = {
|
||||
'n_tokens': 1024,
|
||||
'd_model': 1024,
|
||||
'n_heads': 16,
|
||||
'n_layers': 12,
|
||||
'n_tokens': model_cfg.tokens,
|
||||
'd_model': model_cfg.dim,
|
||||
'n_heads': model_cfg.heads,
|
||||
'n_layers': model_cfg.layers,
|
||||
}
|
||||
models = { "ar": AR(**kwargs).to(device), "nar": NAR(**kwargs).to(device) }
|
||||
"""
|
||||
engines = Engines({ name: Engine(model=model, optimizer=torch.optim.AdamW(model.parameters(), lr=1e-4)) for name, model in models.items() })
|
||||
|
||||
train = True
|
||||
|
|
|
@ -17,6 +17,8 @@ class NAR(Base):
|
|||
|
||||
@property
|
||||
def arch_type(self) -> bool:
|
||||
if hasattr(self, "_cfg"):
|
||||
return self._cfg.arch_type
|
||||
return cfg.models.nar.arch_type
|
||||
|
||||
@property
|
||||
|
@ -29,6 +31,8 @@ class NAR(Base):
|
|||
|
||||
@property
|
||||
def n_resp_levels(self) -> int:
|
||||
if hasattr(self, "_cfg"):
|
||||
return self._cfg.resp_levels
|
||||
return cfg.models.nar.resp_levels
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue
Block a user