Upload Token_Surgeon_Example.ipynb
Browse files
Example/Token_Surgeon_Example.ipynb
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"machine_shape": "hm",
|
8 |
+
"gpuType": "L4"
|
9 |
+
},
|
10 |
+
"kernelspec": {
|
11 |
+
"name": "python3",
|
12 |
+
"display_name": "Python 3"
|
13 |
+
},
|
14 |
+
"language_info": {
|
15 |
+
"name": "python"
|
16 |
+
},
|
17 |
+
"accelerator": "GPU"
|
18 |
+
},
|
19 |
+
"cells": [
|
20 |
+
{
|
21 |
+
"cell_type": "markdown",
|
22 |
+
"source": [
|
23 |
+
"# Download / install required dependencies."
|
24 |
+
],
|
25 |
+
"metadata": {
|
26 |
+
"id": "4nHRbUX16c0C"
|
27 |
+
}
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"cell_type": "code",
|
31 |
+
"source": [
|
32 |
+
"!git clone https://github.com/cg123/mergekit.git\n",
|
33 |
+
"!cd mergekit && pip install -q -e .\n",
|
34 |
+
"!pip install huggingface_hub"
|
35 |
+
],
|
36 |
+
"metadata": {
|
37 |
+
"id": "XQm5_Xtz09yE"
|
38 |
+
},
|
39 |
+
"execution_count": null,
|
40 |
+
"outputs": []
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"cell_type": "markdown",
|
44 |
+
"source": [
|
45 |
+
"#Start Merge-kit's Token-Surgeon with --barycentric -v -k 10 --cuda --low-cpu-memory\n",
|
46 |
+
"\n",
|
47 |
+
"Base model (model being modified), donor model (where you are taking the tokenizer embeddings from)."
|
48 |
+
],
|
49 |
+
"metadata": {
|
50 |
+
"id": "H6gBOEjA6VhN"
|
51 |
+
}
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"cell_type": "code",
|
55 |
+
"source": [
|
56 |
+
"!mergekit-tokensurgeon username/modelname username/modelname ./postop -v -k 10 --barycentric --cuda --low-cpu-memory"
|
57 |
+
],
|
58 |
+
"metadata": {
|
59 |
+
"id": "vfjXBAGV1qVr",
|
60 |
+
"collapsed": true
|
61 |
+
},
|
62 |
+
"execution_count": null,
|
63 |
+
"outputs": []
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "markdown",
|
67 |
+
"source": [
|
68 |
+
"# Login To Huggingface"
|
69 |
+
],
|
70 |
+
"metadata": {
|
71 |
+
"id": "RylFKYVrUKJk"
|
72 |
+
}
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"cell_type": "code",
|
76 |
+
"source": [
|
77 |
+
"!huggingface-cli login\n"
|
78 |
+
],
|
79 |
+
"metadata": {
|
80 |
+
"id": "EQUnrGAv4Q87"
|
81 |
+
},
|
82 |
+
"execution_count": null,
|
83 |
+
"outputs": []
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"cell_type": "markdown",
|
87 |
+
"source": [
|
88 |
+
"#Upload to Huggingface"
|
89 |
+
],
|
90 |
+
"metadata": {
|
91 |
+
"id": "JfYTwAzr6PR8"
|
92 |
+
}
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"cell_type": "code",
|
96 |
+
"source": [
|
97 |
+
"from huggingface_hub import HfApi\n",
|
98 |
+
"\n",
|
99 |
+
"api = HfApi()\n",
|
100 |
+
"repo_name = \"username/modelname\" # Replace with your desired model repo name on Hugging Face Hub\n",
|
101 |
+
"api.create_repo(repo_name, private=True) # Creates a private repo, set to False if you want it public\n",
|
102 |
+
"\n",
|
103 |
+
"# Upload the model directory to your Hugging Face repo\n",
|
104 |
+
"api.upload_folder(\n",
|
105 |
+
" folder_path=\"./postop\", # Path to your model\n",
|
106 |
+
" repo_id=repo_name,\n",
|
107 |
+
")"
|
108 |
+
],
|
109 |
+
"metadata": {
|
110 |
+
"id": "zKoL6Ouf4pLI"
|
111 |
+
},
|
112 |
+
"execution_count": null,
|
113 |
+
"outputs": []
|
114 |
+
}
|
115 |
+
]
|
116 |
+
}
|