diff --git a/vall_e/config.py b/vall_e/config.py
index 54c24e6..cb144b7 100755
--- a/vall_e/config.py
+++ b/vall_e/config.py
@@ -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()
diff --git a/vall_e/data.py b/vall_e/data.py
index 1153427..b217fee 100755
--- a/vall_e/data.py
+++ b/vall_e/data.py
@@ -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
diff --git a/vall_e/emb/qnt.py b/vall_e/emb/qnt.py
index 03f9983..7a2f9dc 100755
--- a/vall_e/emb/qnt.py
+++ b/vall_e/emb/qnt.py
@@ -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]
diff --git a/vall_e/models/ar.py b/vall_e/models/ar.py
index c8ac130..ec825ab 100755
--- a/vall_e/models/ar.py
+++ b/vall_e/models/ar.py
@@ -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
diff --git a/vall_e/models/base.py b/vall_e/models/base.py
index 3b3f7ff..c529ac7 100755
--- a/vall_e/models/base.py
+++ b/vall_e/models/base.py
@@ -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 = {'': 1, '': 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""] + [ " " if not p else p for p in split ] + [f""]
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
diff --git a/vall_e/models/nar.py b/vall_e/models/nar.py
index 953f419..0edefe5 100755
--- a/vall_e/models/nar.py
+++ b/vall_e/models/nar.py
@@ -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