liltom-eth
commited on
Commit
·
00d4dcc
1
Parent(s):
bd82dd7
Upload deploy_llava.ipynb with huggingface_hub
Browse files- deploy_llava.ipynb +52 -81
deploy_llava.ipynb
CHANGED
@@ -32,7 +32,7 @@
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
-
"execution_count":
|
36 |
"metadata": {},
|
37 |
"outputs": [],
|
38 |
"source": [
|
@@ -51,9 +51,40 @@
|
|
51 |
},
|
52 |
{
|
53 |
"cell_type": "code",
|
54 |
-
"execution_count":
|
55 |
"metadata": {},
|
56 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
"source": [
|
58 |
"import sagemaker\n",
|
59 |
"import boto3\n",
|
@@ -88,9 +119,19 @@
|
|
88 |
},
|
89 |
{
|
90 |
"cell_type": "code",
|
91 |
-
"execution_count":
|
92 |
"metadata": {},
|
93 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
"source": [
|
95 |
"from sagemaker.s3 import S3Uploader\n",
|
96 |
"\n",
|
@@ -109,7 +150,7 @@
|
|
109 |
},
|
110 |
{
|
111 |
"cell_type": "code",
|
112 |
-
"execution_count":
|
113 |
"metadata": {},
|
114 |
"outputs": [
|
115 |
{
|
@@ -120,7 +161,7 @@
|
|
120 |
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
121 |
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
122 |
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
123 |
-
"
|
124 |
]
|
125 |
}
|
126 |
],
|
@@ -156,14 +197,14 @@
|
|
156 |
},
|
157 |
{
|
158 |
"cell_type": "code",
|
159 |
-
"execution_count":
|
160 |
"metadata": {},
|
161 |
"outputs": [
|
162 |
{
|
163 |
"name": "stdout",
|
164 |
"output_type": "stream",
|
165 |
"text": [
|
166 |
-
"The image
|
167 |
]
|
168 |
}
|
169 |
],
|
@@ -173,7 +214,7 @@
|
|
173 |
" \"question\" : \"Describe the image and color details.\",\n",
|
174 |
" # \"max_new_tokens\" : 1024,\n",
|
175 |
" # \"temperature\" : 0.2,\n",
|
176 |
-
" # \"
|
177 |
"}\n",
|
178 |
"\n",
|
179 |
"# request\n",
|
@@ -181,55 +222,6 @@
|
|
181 |
"print(output)"
|
182 |
]
|
183 |
},
|
184 |
-
{
|
185 |
-
"cell_type": "markdown",
|
186 |
-
"metadata": {},
|
187 |
-
"source": [
|
188 |
-
"To run inference with `llava` special token:"
|
189 |
-
]
|
190 |
-
},
|
191 |
-
{
|
192 |
-
"cell_type": "code",
|
193 |
-
"execution_count": 11,
|
194 |
-
"metadata": {},
|
195 |
-
"outputs": [
|
196 |
-
{
|
197 |
-
"name": "stdout",
|
198 |
-
"output_type": "stream",
|
199 |
-
"text": [
|
200 |
-
"The image features a red toy animal, possibly a horse or a donkey, with a pair of glasses on its face. The toy is made of plastic and has a fire-like appearance, giving it a unique and eye-catching look. The red color of the toy and the glasses on its face create a striking contrast against the background, making it the main focus of the image.\n"
|
201 |
-
]
|
202 |
-
}
|
203 |
-
],
|
204 |
-
"source": [
|
205 |
-
"from llava.conversation import conv_templates, SeparatorStyle\n",
|
206 |
-
"from llava.constants import (\n",
|
207 |
-
"DEFAULT_IMAGE_TOKEN,\n",
|
208 |
-
"DEFAULT_IM_START_TOKEN,\n",
|
209 |
-
"DEFAULT_IM_END_TOKEN,\n",
|
210 |
-
")\n",
|
211 |
-
"def get_prompt(raw_prompt):\n",
|
212 |
-
" conv_mode = \"llava_v1\"\n",
|
213 |
-
" conv = conv_templates[conv_mode].copy()\n",
|
214 |
-
" roles = conv.roles\n",
|
215 |
-
" inp = f\"{roles[0]}: {raw_prompt}\"\n",
|
216 |
-
" inp = (\n",
|
217 |
-
" DEFAULT_IM_START_TOKEN + DEFAULT_IMAGE_TOKEN + DEFAULT_IM_END_TOKEN + \"\\n\" + inp\n",
|
218 |
-
" )\n",
|
219 |
-
" conv.append_message(conv.roles[0], inp)\n",
|
220 |
-
" conv.append_message(conv.roles[1], None)\n",
|
221 |
-
" prompt = conv.get_prompt()\n",
|
222 |
-
" stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2\n",
|
223 |
-
" return prompt, stop_str\n",
|
224 |
-
"\n",
|
225 |
-
"raw_prompt = \"Describe the image and color details.\"\n",
|
226 |
-
"prompt, stop_str = get_prompt(raw_prompt)\n",
|
227 |
-
"image_path = \"https://raw.githubusercontent.com/haotian-liu/LLaVA/main/images/llava_logo.png\"\n",
|
228 |
-
"data = {\"image\" : image_path, \"question\" : prompt, \"stop_str\" : stop_str}\n",
|
229 |
-
"output = predictor.predict(data)\n",
|
230 |
-
"print(output)"
|
231 |
-
]
|
232 |
-
},
|
233 |
{
|
234 |
"cell_type": "markdown",
|
235 |
"metadata": {},
|
@@ -279,28 +271,6 @@
|
|
279 |
")"
|
280 |
]
|
281 |
},
|
282 |
-
{
|
283 |
-
"cell_type": "code",
|
284 |
-
"execution_count": 15,
|
285 |
-
"metadata": {},
|
286 |
-
"outputs": [
|
287 |
-
{
|
288 |
-
"name": "stdout",
|
289 |
-
"output_type": "stream",
|
290 |
-
"text": [
|
291 |
-
"The image features a small toy animal, resembling a horse or a donkey, with a red and orange color scheme. The toy has a pair of glasses on its face, giving it a unique and quirky appearance. The toy is standing on a gray surface, which provides a contrasting background for the vibrant colors of the toy. The combination of red, orange, and gray creates a visually striking scene.\n"
|
292 |
-
]
|
293 |
-
}
|
294 |
-
],
|
295 |
-
"source": [
|
296 |
-
"raw_prompt = \"Describe the image and color details.\"\n",
|
297 |
-
"prompt, stop_str = get_prompt(raw_prompt)\n",
|
298 |
-
"image_path = \"https://raw.githubusercontent.com/haotian-liu/LLaVA/main/images/llava_logo.png\"\n",
|
299 |
-
"data = {\"image\" : image_path, \"question\" : prompt, \"stop_str\" : stop_str}\n",
|
300 |
-
"output = predictor2.predict(data)\n",
|
301 |
-
"print(output)"
|
302 |
-
]
|
303 |
-
},
|
304 |
{
|
305 |
"cell_type": "markdown",
|
306 |
"metadata": {},
|
@@ -315,6 +285,7 @@
|
|
315 |
"outputs": [],
|
316 |
"source": [
|
317 |
"# delete sagemaker endpoint\n",
|
|
|
318 |
"predictor.delete_endpoint()"
|
319 |
]
|
320 |
}
|
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
+
"execution_count": 1,
|
36 |
"metadata": {},
|
37 |
"outputs": [],
|
38 |
"source": [
|
|
|
51 |
},
|
52 |
{
|
53 |
"cell_type": "code",
|
54 |
+
"execution_count": 2,
|
55 |
"metadata": {},
|
56 |
+
"outputs": [
|
57 |
+
{
|
58 |
+
"name": "stdout",
|
59 |
+
"output_type": "stream",
|
60 |
+
"text": [
|
61 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
62 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
63 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
64 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
65 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
66 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n"
|
67 |
+
]
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"name": "stderr",
|
71 |
+
"output_type": "stream",
|
72 |
+
"text": [
|
73 |
+
"Couldn't call 'get_role' to get Role ARN from role name arn:aws:iam::297308036828:root to get Role path.\n"
|
74 |
+
]
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"name": "stdout",
|
78 |
+
"output_type": "stream",
|
79 |
+
"text": [
|
80 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
81 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
82 |
+
"sagemaker role arn: arn:aws:iam::297308036828:role/service-role/AmazonSageMaker-ExecutionRole-20231008T201275\n",
|
83 |
+
"sagemaker bucket: sagemaker-us-west-2-297308036828\n",
|
84 |
+
"sagemaker session region: us-west-2\n"
|
85 |
+
]
|
86 |
+
}
|
87 |
+
],
|
88 |
"source": [
|
89 |
"import sagemaker\n",
|
90 |
"import boto3\n",
|
|
|
119 |
},
|
120 |
{
|
121 |
"cell_type": "code",
|
122 |
+
"execution_count": 3,
|
123 |
"metadata": {},
|
124 |
+
"outputs": [
|
125 |
+
{
|
126 |
+
"name": "stdout",
|
127 |
+
"output_type": "stream",
|
128 |
+
"text": [
|
129 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
130 |
+
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
131 |
+
"model uploaded to: s3://sagemaker-us-west-2-297308036828/llava-v1.5-7b/model.tar.gz\n"
|
132 |
+
]
|
133 |
+
}
|
134 |
+
],
|
135 |
"source": [
|
136 |
"from sagemaker.s3 import S3Uploader\n",
|
137 |
"\n",
|
|
|
150 |
},
|
151 |
{
|
152 |
"cell_type": "code",
|
153 |
+
"execution_count": 4,
|
154 |
"metadata": {},
|
155 |
"outputs": [
|
156 |
{
|
|
|
161 |
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
162 |
"sagemaker.config INFO - Not applying SDK defaults from location: /Library/Application Support/sagemaker/config.yaml\n",
|
163 |
"sagemaker.config INFO - Not applying SDK defaults from location: /Users/tom/Library/Application Support/sagemaker/config.yaml\n",
|
164 |
+
"-----------------!"
|
165 |
]
|
166 |
}
|
167 |
],
|
|
|
197 |
},
|
198 |
{
|
199 |
"cell_type": "code",
|
200 |
+
"execution_count": 5,
|
201 |
"metadata": {},
|
202 |
"outputs": [
|
203 |
{
|
204 |
"name": "stdout",
|
205 |
"output_type": "stream",
|
206 |
"text": [
|
207 |
+
"The image features a red and black toy horse with a pair of glasses on its face. The horse is wearing a pair of red glasses, which adds a unique and quirky touch to the toy. The horse's legs are also painted in red and black colors, further enhancing its appearance. The toy horse is standing on a grey surface, which serves as a backdrop for the scene.\n"
|
208 |
]
|
209 |
}
|
210 |
],
|
|
|
214 |
" \"question\" : \"Describe the image and color details.\",\n",
|
215 |
" # \"max_new_tokens\" : 1024,\n",
|
216 |
" # \"temperature\" : 0.2,\n",
|
217 |
+
" # \"conv_mode\" : \"llava_v1\"\n",
|
218 |
"}\n",
|
219 |
"\n",
|
220 |
"# request\n",
|
|
|
222 |
"print(output)"
|
223 |
]
|
224 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
{
|
226 |
"cell_type": "markdown",
|
227 |
"metadata": {},
|
|
|
271 |
")"
|
272 |
]
|
273 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
{
|
275 |
"cell_type": "markdown",
|
276 |
"metadata": {},
|
|
|
285 |
"outputs": [],
|
286 |
"source": [
|
287 |
"# delete sagemaker endpoint\n",
|
288 |
+
"predictor.delete_model()\n",
|
289 |
"predictor.delete_endpoint()"
|
290 |
]
|
291 |
}
|