Skip to content

Commit 70bd378

Browse files
authored
add vlm notebook to default branch (#4755)
1 parent 4f75b60 commit 70bd378

File tree

1 file changed

+281
-0
lines changed

1 file changed

+281
-0
lines changed
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "caac7a72",
6+
"metadata": {},
7+
"source": [
8+
"# SageMaker JumpStart - deploy llama 3.2 vision language model\n",
9+
"\n",
10+
"This notebook demonstrates how to use the SageMaker Python SDK to deploy a SageMaker JumpStart vision language model and invoke the endpoint."
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "c1027fd6",
16+
"metadata": {},
17+
"source": [
18+
"---\n",
19+
"\n",
20+
"This notebook's CI test result for us-west-2 is as follows. CI test results in other regions can be found at the end of the notebook. \n",
21+
"\n",
22+
"![This us-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-west-2/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
23+
"\n",
24+
"---"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "c9d34879-bf56-4aeb-8a67-fa85c7b7a092",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"from sagemaker.jumpstart.model import JumpStartModel"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"id": "c1f55ea3-025d-4f77-83de-69ea3fe46cd5",
40+
"metadata": {},
41+
"source": [
42+
"Select your desired model ID. You can search for available models in the [Built-in Algorithms with pre-trained Model Table](https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html)."
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "7d458cf0-02e2-4066-927b-25fa5ef2a07e",
48+
"metadata": {},
49+
"source": [
50+
"***\n",
51+
"You can continue with the default model or choose a different model: this notebook will run with the following model IDs :\n",
52+
"- `meta-vlm-llama-3-2-11b-vision`\n",
53+
"- `meta-vlm-llama-3-2-11b-vision-instruct`\n",
54+
"- `meta-vlm-llama-3-2-90b-vision`\n",
55+
"- `meta-vlm-llama-3-2-90b-vision-instruct`\n",
56+
"- `meta-vlm-llama-guard-3-11b-vision`\n",
57+
"***"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"id": "3763cc4c",
64+
"metadata": {
65+
"jumpStartAlterations": [
66+
"modelIdOnly"
67+
],
68+
"tags": []
69+
},
70+
"outputs": [],
71+
"source": [
72+
"model_id = \"meta-vlm-llama-3-2-11b-vision\""
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"id": "a1af4672-93b5-4746-963f-c40cdd0ccb4d",
78+
"metadata": {},
79+
"source": [
80+
"If your selected model is gated, you will need to set `accept_eula` to True to accept the model end-user license agreement (EULA)."
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "439bc3a3-15bc-4551-8c5d-8b592d298678",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"accept_eula = False"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"id": "2bc40011-51f3-4787-ae1b-6b50a594cdf4",
96+
"metadata": {},
97+
"source": [
98+
"## Deploy model"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"id": "76d26926-152e-456c-8bc0-5d671fd61dac",
104+
"metadata": {},
105+
"source": [
106+
"Using the model ID, define your model as a JumpStart model. You can deploy the model on other instance types by passing `instance_type` to `JumpStartModel`. See [Deploy publicly available foundation models with the JumpStartModel class](https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-foundation-models-use-python-sdk.html#jumpstart-foundation-models-use-python-sdk-model-class) for more configuration options."
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"id": "85a2a8e5-789f-4041-9927-221257126653",
113+
"metadata": {
114+
"tags": []
115+
},
116+
"outputs": [],
117+
"source": [
118+
"model = JumpStartModel(model_id=model_id)"
119+
]
120+
},
121+
{
122+
"cell_type": "markdown",
123+
"id": "d314544f-e62e-4dfb-981c-659ee991791c",
124+
"metadata": {},
125+
"source": [
126+
"You can now deploy your JumpStart model. The deployment might take few minutes."
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"id": "56c7462a",
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"predictor = model.deploy(accept_eula=accept_eula)"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"id": "a97bd778-5c62-4757-80ce-38c29275fa2a",
142+
"metadata": {},
143+
"source": [
144+
"## Invoke endpoint"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"id": "8ba7c729",
150+
"metadata": {},
151+
"source": [
152+
"Programmatically retrieve example playloads from the `JumpStartModel` object."
153+
]
154+
},
155+
{
156+
"cell_type": "code",
157+
"execution_count": null,
158+
"id": "7077afc0",
159+
"metadata": {},
160+
"outputs": [],
161+
"source": [
162+
"example_payloads = model.retrieve_all_examples()"
163+
]
164+
},
165+
{
166+
"cell_type": "markdown",
167+
"id": "7ee929ec-7707-4c5c-8530-a3ad20f2b2c2",
168+
"metadata": {},
169+
"source": [
170+
"Now you can invoke the endpoint for each retrieved example payload."
171+
]
172+
},
173+
{
174+
"cell_type": "code",
175+
"execution_count": null,
176+
"id": "bf5899c8",
177+
"metadata": {},
178+
"outputs": [],
179+
"source": [
180+
"for payload in example_payloads:\n",
181+
" response = predictor.predict(payload)\n",
182+
" response = response[0] if isinstance(response, list) else response\n",
183+
" print(\"Input:\\n\", payload.body, end=\"\\n\\n\")\n",
184+
" print(\"Output:\\n\", response[\"choices\"][0][\"message\"][\"content\"], end=\"\\n\\n\\n\")"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"id": "4c63a4d6",
190+
"metadata": {},
191+
"source": [
192+
"This model supports the following payload parameters. You may specify any subset of these parameters when invoking an endpoint.\n",
193+
"\n",
194+
"* **max_tokens:** Maximum number of generated tokens. If specified, it must be a positive integer.\n",
195+
"* **temperature:** Controls the randomness in the output. Higher temperature results in output sequence with low-probability words and lower temperature results in output sequence with high-probability words. If `temperature` -> 0, it results in greedy decoding. If specified, it must be a positive float.\n",
196+
"* **top_p:** In each step of text generation, sample from the smallest possible set of words with cumulative probability `top_p`. If specified, it must be a float between 0 and 1.\n",
197+
"* **logprobs:** Log probabilities represent how likely each token is relative to the others based on the model's prediction. This is useful if you want to understand the confidence level of the model in its token choices or analyze the generation process at a finer level. If `logprobs` -> True, it tells the model to return the log probabilities of each token it generates.\n"
198+
]
199+
},
200+
{
201+
"cell_type": "markdown",
202+
"id": "adb5db3d",
203+
"metadata": {},
204+
"source": [
205+
"## Clean up"
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"id": "b2d027be",
212+
"metadata": {},
213+
"outputs": [],
214+
"source": [
215+
"predictor.delete_predictor()"
216+
]
217+
},
218+
{
219+
"cell_type": "markdown",
220+
"id": "1b1d70fc",
221+
"metadata": {},
222+
"source": [
223+
"## Notebook CI Test Results\n",
224+
"\n",
225+
"This notebook was tested in multiple regions. The test results are as follows, except for us-west-2 which is shown at the top of the notebook.\n",
226+
"\n",
227+
"![This us-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-east-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
228+
"\n",
229+
"![This us-east-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-east-2/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
230+
"\n",
231+
"![This us-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/us-west-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
232+
"\n",
233+
"![This ca-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ca-central-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
234+
"\n",
235+
"![This sa-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/sa-east-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
236+
"\n",
237+
"![This eu-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-west-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
238+
"\n",
239+
"![This eu-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-west-2/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
240+
"\n",
241+
"![This eu-west-3 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-west-3/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
242+
"\n",
243+
"![This eu-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-central-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
244+
"\n",
245+
"![This eu-north-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/eu-north-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
246+
"\n",
247+
"![This ap-southeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-southeast-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
248+
"\n",
249+
"![This ap-southeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-southeast-2/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
250+
"\n",
251+
"![This ap-northeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-northeast-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
252+
"\n",
253+
"![This ap-northeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-northeast-2/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n",
254+
"\n",
255+
"![This ap-south-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable](https://prod.us-west-2.tcx-beacon.docs.aws.dev/sagemaker-nb/ap-south-1/generative_ai|sm-jumpstart-llama_3_vision_language_model_deployment.ipynb)\n"
256+
]
257+
}
258+
],
259+
"metadata": {
260+
"instance_type": "ml.t3.medium",
261+
"kernelspec": {
262+
"display_name": "Python 3 (ipykernel)",
263+
"language": "python",
264+
"name": "python3"
265+
},
266+
"language_info": {
267+
"codemirror_mode": {
268+
"name": "ipython",
269+
"version": 3
270+
},
271+
"file_extension": ".py",
272+
"mimetype": "text/x-python",
273+
"name": "python",
274+
"nbconvert_exporter": "python",
275+
"pygments_lexer": "ipython3",
276+
"version": "3.10.13"
277+
}
278+
},
279+
"nbformat": 4,
280+
"nbformat_minor": 5
281+
}

0 commit comments

Comments
 (0)