Update README.md
Browse files
README.md
CHANGED
@@ -1,200 +1,160 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
library_name: transformers
|
3 |
-
tags:
|
4 |
-
- unsloth
|
5 |
---
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
[
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
[
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
[
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
[
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
-
|
149 |
-
-
|
150 |
-
|
151 |
-
|
152 |
-
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
### Model Architecture and Objective
|
157 |
-
|
158 |
-
[More Information Needed]
|
159 |
-
|
160 |
-
### Compute Infrastructure
|
161 |
-
|
162 |
-
[More Information Needed]
|
163 |
-
|
164 |
-
#### Hardware
|
165 |
-
|
166 |
-
[More Information Needed]
|
167 |
-
|
168 |
-
#### Software
|
169 |
-
|
170 |
-
[More Information Needed]
|
171 |
-
|
172 |
-
## Citation [optional]
|
173 |
-
|
174 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
175 |
-
|
176 |
-
**BibTeX:**
|
177 |
-
|
178 |
-
[More Information Needed]
|
179 |
-
|
180 |
-
**APA:**
|
181 |
-
|
182 |
-
[More Information Needed]
|
183 |
-
|
184 |
-
## Glossary [optional]
|
185 |
-
|
186 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
187 |
-
|
188 |
-
[More Information Needed]
|
189 |
-
|
190 |
-
## More Information [optional]
|
191 |
-
|
192 |
-
[More Information Needed]
|
193 |
-
|
194 |
-
## Model Card Authors [optional]
|
195 |
-
|
196 |
-
[More Information Needed]
|
197 |
-
|
198 |
-
## Model Card Contact
|
199 |
-
|
200 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
+
license: cc-by-nc-4.0
|
3 |
+
datasets:
|
4 |
+
- amphion/Emilia-Dataset
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
base_model:
|
8 |
+
- LiquidAI/LFM2-350M
|
9 |
+
pipeline_tag: text-to-speech
|
10 |
library_name: transformers
|
|
|
|
|
11 |
---
|
12 |
+
## Overview
|
13 |
+
VyvoTTS-LFM2-350M is a Text-to-Speech model based on LFM2-350M, trained to produce natural-sounding English speech.
|
14 |
+
|
15 |
+
- **Type:** Text-to-Speech
|
16 |
+
- **Language:** English
|
17 |
+
- **License:** CC BY-NC 4.0
|
18 |
+
- **Params:** ~383M
|
19 |
+
|
20 |
+
## Usage
|
21 |
+
Below is an example of using the model with `unsloth` and `SNAC` for speech generation:
|
22 |
+
|
23 |
+
```python
|
24 |
+
from unsloth import FastLanguageModel
|
25 |
+
import torch
|
26 |
+
from snac import SNAC
|
27 |
+
|
28 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
29 |
+
model_name = "Vyvo/VyvoTTS-LFM2-Itto",
|
30 |
+
max_seq_length= 8192,
|
31 |
+
dtype = None,
|
32 |
+
load_in_4bit = False,
|
33 |
+
)
|
34 |
+
snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz")
|
35 |
+
tokeniser_length = 64400
|
36 |
+
start_of_text = 1
|
37 |
+
end_of_text = 7
|
38 |
+
|
39 |
+
start_of_speech = tokeniser_length + 1
|
40 |
+
end_of_speech = tokeniser_length + 2
|
41 |
+
start_of_human = tokeniser_length + 3
|
42 |
+
end_of_human = tokeniser_length + 4
|
43 |
+
pad_token = tokeniser_length + 7
|
44 |
+
|
45 |
+
audio_tokens_start = tokeniser_length + 10
|
46 |
+
prompts = ["Hey there my name is Elise, and I'm a speech generation model that can sound like a person."]
|
47 |
+
chosen_voice = None
|
48 |
+
|
49 |
+
FastLanguageModel.for_inference(model)
|
50 |
+
snac_model.to("cpu")
|
51 |
+
prompts_ = [(f"{chosen_voice}: " + p) if chosen_voice else p for p in prompts]
|
52 |
+
|
53 |
+
all_input_ids = []
|
54 |
+
for prompt in prompts_:
|
55 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
56 |
+
all_input_ids.append(input_ids)
|
57 |
+
|
58 |
+
start_token = torch.tensor([[start_of_human]], dtype=torch.int64)
|
59 |
+
end_tokens = torch.tensor([[end_of_text, end_of_human]], dtype=torch.int64)
|
60 |
+
|
61 |
+
all_modified_input_ids = []
|
62 |
+
for input_ids in all_input_ids:
|
63 |
+
modified_input_ids = torch.cat([start_token, input_ids, end_tokens], dim=1)
|
64 |
+
all_modified_input_ids.append(modified_input_ids)
|
65 |
+
|
66 |
+
all_padded_tensors, all_attention_masks = [], []
|
67 |
+
max_length = max([m.shape[1] for m in all_modified_input_ids])
|
68 |
+
for m in all_modified_input_ids:
|
69 |
+
padding = max_length - m.shape[1]
|
70 |
+
padded_tensor = torch.cat([torch.full((1, padding), pad_token, dtype=torch.int64), m], dim=1)
|
71 |
+
attention_mask = torch.cat([torch.zeros((1, padding), dtype=torch.int64), torch.ones((1, m.shape[1]), dtype=torch.int64)], dim=1)
|
72 |
+
all_padded_tensors.append(padded_tensor)
|
73 |
+
all_attention_masks.append(attention_mask)
|
74 |
+
|
75 |
+
input_ids = torch.cat(all_padded_tensors, dim=0).to("cuda")
|
76 |
+
attention_mask = torch.cat(all_attention_masks, dim=0).to("cuda")
|
77 |
+
|
78 |
+
generated_ids = model.generate(
|
79 |
+
input_ids=input_ids,
|
80 |
+
attention_mask=attention_mask,
|
81 |
+
max_new_tokens=1200,
|
82 |
+
do_sample=True,
|
83 |
+
temperature=0.6,
|
84 |
+
top_p=0.95,
|
85 |
+
repetition_penalty=1.1,
|
86 |
+
num_return_sequences=1,
|
87 |
+
eos_token_id=end_of_speech,
|
88 |
+
use_cache=True
|
89 |
+
)
|
90 |
+
|
91 |
+
token_to_find = start_of_speech
|
92 |
+
token_to_remove = end_of_speech
|
93 |
+
token_indices = (generated_ids == token_to_find).nonzero(as_tuple=True)
|
94 |
+
|
95 |
+
if len(token_indices[1]) > 0:
|
96 |
+
last_occurrence_idx = token_indices[1][-1].item()
|
97 |
+
cropped_tensor = generated_ids[:, last_occurrence_idx+1:]
|
98 |
+
else:
|
99 |
+
cropped_tensor = generated_ids
|
100 |
+
|
101 |
+
processed_rows = []
|
102 |
+
for row in cropped_tensor:
|
103 |
+
masked_row = row[row != token_to_remove]
|
104 |
+
processed_rows.append(masked_row)
|
105 |
+
|
106 |
+
code_lists = []
|
107 |
+
for row in processed_rows:
|
108 |
+
row_length = row.size(0)
|
109 |
+
new_length = (row_length // 7) * 7
|
110 |
+
trimmed_row = row[:new_length]
|
111 |
+
trimmed_row = [t - audio_tokens_start for t in trimmed_row]
|
112 |
+
code_lists.append(trimmed_row)
|
113 |
+
|
114 |
+
def redistribute_codes(code_list):
|
115 |
+
layer_1, layer_2, layer_3 = [], [], []
|
116 |
+
for i in range((len(code_list)+1)//7):
|
117 |
+
layer_1.append(code_list[7*i])
|
118 |
+
layer_2.append(code_list[7*i+1]-4096)
|
119 |
+
layer_3.append(code_list[7*i+2]-(2*4096))
|
120 |
+
layer_3.append(code_list[7*i+3]-(3*4096))
|
121 |
+
layer_2.append(code_list[7*i+4]-(4*4096))
|
122 |
+
layer_3.append(code_list[7*i+5]-(5*4096))
|
123 |
+
layer_3.append(code_list[7*i+6]-(6*4096))
|
124 |
+
codes = [
|
125 |
+
torch.tensor(layer_1).unsqueeze(0),
|
126 |
+
torch.tensor(layer_2).unsqueeze(0),
|
127 |
+
torch.tensor(layer_3).unsqueeze(0)
|
128 |
+
]
|
129 |
+
audio_hat = snac_model.decode(codes)
|
130 |
+
return audio_hat
|
131 |
+
|
132 |
+
my_samples = []
|
133 |
+
for code_list in code_lists:
|
134 |
+
samples = redistribute_codes(code_list)
|
135 |
+
my_samples.append(samples)
|
136 |
+
|
137 |
+
from IPython.display import display, Audio
|
138 |
+
if len(prompts) != len(my_samples):
|
139 |
+
raise Exception("Number of prompts and samples do not match")
|
140 |
+
else:
|
141 |
+
for i in range(len(my_samples)):
|
142 |
+
print(prompts[i])
|
143 |
+
samples = my_samples[i]
|
144 |
+
display(Audio(samples.detach().squeeze().to("cpu").numpy(), rate=24000))
|
145 |
+
|
146 |
+
del my_samples, samples
|
147 |
+
```
|
148 |
+
|
149 |
+
## Citation
|
150 |
+
|
151 |
+
If you use this model, please cite:
|
152 |
+
|
153 |
+
```bibtex
|
154 |
+
@misc{VyvoTTS-LFM2-350M,
|
155 |
+
title={VyvoTTS-LFM2-350M},
|
156 |
+
author={Vyvo},
|
157 |
+
year={2025},
|
158 |
+
howpublished={\url{https://huggingface.co/Vyvo/VyvoTTS-LFM2-350M}}
|
159 |
+
}
|
160 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|