Upload insert_symbol.ipynb
Browse files- insert_symbol.ipynb +61 -0
insert_symbol.ipynb
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import torch\n",
|
10 |
+
"#### 迁移gpt模型的embedding层,插入两个新的token\n",
|
11 |
+
"dict = torch.load(r\"D:\\pyprojs\\GPT-SoVITSs\\fork\\GPT-SoVITS\\GPT_SoVITS\\pretrained_models\\s1bert25hz-2kh-longer-epoch=68e-step=50232-2.ckpt\",map_location=torch.device('cpu'))\n",
|
12 |
+
"dict[\"weight\"][\"model.ar_text_embedding.word_embeddings.weight\"].shape\n",
|
13 |
+
"# 0~94保持不动,95~向后移动两位,新的95 96随机初始化\n",
|
14 |
+
"# 一共512列,embedding_dim=5\n",
|
15 |
+
"first_part = dict[\"weight\"][\"model.ar_text_embedding.word_embeddings.weight\"][:95,:]\n",
|
16 |
+
"second_part = dict[\"weight\"][\"model.ar_text_embedding.word_embeddings.weight\"][95:-2,:]\n",
|
17 |
+
"new_weight = torch.cat([first_part,second_part, torch.randn(2, 512)],dim=0)\n",
|
18 |
+
"dict[\"weight\"][\"model.ar_text_embedding.word_embeddings.weight\"] = new_weight\n",
|
19 |
+
"torch.save(dict,r\"D:\\pyprojs\\GPT-SoVITSs\\fork\\GPT-SoVITS\\GPT_SoVITS\\pretrained_models\\s1bert25hz-hs_model.ckpt\")"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 1,
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [],
|
27 |
+
"source": [
|
28 |
+
"import torch\n",
|
29 |
+
"dict2 = torch.load(r\"D:\\pyprojs\\GPT-SoVITSs\\fork\\GPT-SoVITS\\GPT_SoVITS\\pretrained_models\\s2G488k-legacy.pth\",map_location=torch.device('cpu'))\n",
|
30 |
+
"dict2[\"weight\"][\"enc_p.text_embedding.weight\"].shape\n",
|
31 |
+
"# 0~94保持不动,95~向后移动两位,新的95 96随机初始化\n",
|
32 |
+
"first_part = dict2[\"weight\"][\"enc_p.text_embedding.weight\"][:95,:]\n",
|
33 |
+
"second_part = dict2[\"weight\"][\"enc_p.text_embedding.weight\"][95:,:]\n",
|
34 |
+
"new_weight = torch.cat([first_part,torch.zeros(2,192),second_part],dim=0)\n",
|
35 |
+
"dict2[\"weight\"][\"enc_p.text_embedding.weight\"] = new_weight\n",
|
36 |
+
"torch.save(dict2,r\"D:\\pyprojs\\GPT-SoVITSs\\fork\\GPT-SoVITS\\GPT_SoVITS\\pretrained_models\\s2G488k.pth\")"
|
37 |
+
]
|
38 |
+
}
|
39 |
+
],
|
40 |
+
"metadata": {
|
41 |
+
"kernelspec": {
|
42 |
+
"display_name": "vits",
|
43 |
+
"language": "python",
|
44 |
+
"name": "python3"
|
45 |
+
},
|
46 |
+
"language_info": {
|
47 |
+
"codemirror_mode": {
|
48 |
+
"name": "ipython",
|
49 |
+
"version": 3
|
50 |
+
},
|
51 |
+
"file_extension": ".py",
|
52 |
+
"mimetype": "text/x-python",
|
53 |
+
"name": "python",
|
54 |
+
"nbconvert_exporter": "python",
|
55 |
+
"pygments_lexer": "ipython3",
|
56 |
+
"version": "3.10.0"
|
57 |
+
}
|
58 |
+
},
|
59 |
+
"nbformat": 4,
|
60 |
+
"nbformat_minor": 2
|
61 |
+
}
|