Skip to content

Commit f269714

Browse files
authored
Update model id for stable diffusion in jumpstart (#3669)
* Update model id for stable diffusion in jumpstart * changed model id to model- * dummy change to retrigger CI test
1 parent 95f5fa6 commit f269714

File tree

2 files changed

+28
-91
lines changed

2 files changed

+28
-91
lines changed

introduction_to_amazon_algorithms/jumpstart_text_to_image/Amazon_JumpStart_Text_To_Image.ipynb

Lines changed: 27 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"---\n",
1717
"Welcome to Amazon [SageMaker JumpStart](https://docs.aws.amazon.com/sagemaker/latest/dg/studio-jumpstart.html)! You can use JumpStart to solve many Machine Learning tasks through one-click in SageMaker Studio, or through [SageMaker JumpStart API](https://sagemaker.readthedocs.io/en/stable/overview.html#use-prebuilt-models-with-sagemaker-jumpstart). \n",
1818
"\n",
19-
"In this demo notebook, we demonstrate how to use the JumpStart API for Text-to-Image. Text-to-Image is the task of generating realistic image given any text input. Here, we show how to use state-of-the-art pre-trained Stable Diffusion models for generating image from text.\n",
19+
"In this demo notebook, we demonstrate how to use the JumpStart API for Text-to-Image. Text-to-Image is the task of generating realistic images given any text input. Here, we show how to use state-of-the-art pre-trained Stable Diffusion models for generating image from text.\n",
2020
"\n",
2121
"---"
2222
]
@@ -27,11 +27,10 @@
2727
"metadata": {},
2828
"source": [
2929
"1. [Set Up](#1.-Set-Up)\n",
30-
"2. [Select a model](#2.-Select-a-model)\n",
31-
"3. [Retrieve JumpStart Artifacts & Deploy an Endpoint](#3.-Retrieve-JumpStart-Artifacts-&-Deploy-an-Endpoint)\n",
32-
"4. [Query endpoint and parse response](#4.-Query-endpoint-and-parse-response)\n",
33-
"5. [Advanced features](#5.-Advanced-features)\n",
34-
"6. [Clean up the endpoint](#6.-Clean-up-the-endpoint)"
30+
"3. [Retrieve JumpStart Artifacts & Deploy an Endpoint](#2.-Retrieve-JumpStart-Artifacts-&-Deploy-an-Endpoint)\n",
31+
"4. [Query endpoint and parse response](#3.-Query-endpoint-and-parse-response)\n",
32+
"5. [Advanced features](#4.-Advanced-features)\n",
33+
"6. [Clean up the endpoint](#5.-Clean-up-the-endpoint)"
3534
]
3635
},
3736
{
@@ -65,7 +64,9 @@
6564
"cell_type": "code",
6665
"execution_count": null,
6766
"id": "25293522",
68-
"metadata": {},
67+
"metadata": {
68+
"tags": []
69+
},
6970
"outputs": [],
7071
"source": [
7172
"!pip install sagemaker ipywidgets --upgrade --quiet"
@@ -88,7 +89,9 @@
8889
"cell_type": "code",
8990
"execution_count": null,
9091
"id": "90518e45",
91-
"metadata": {},
92+
"metadata": {
93+
"tags": []
94+
},
9295
"outputs": [],
9396
"source": [
9497
"import sagemaker, boto3, json\n",
@@ -99,86 +102,12 @@
99102
"sess = sagemaker.Session()"
100103
]
101104
},
102-
{
103-
"cell_type": "markdown",
104-
"id": "d2c1a623",
105-
"metadata": {},
106-
"source": [
107-
"### 2. Select a model\n",
108-
"\n",
109-
"***\n",
110-
"Here, we download jumpstart model_manifest file from the jumpstart s3 bucket, filter-out all the Text Generation models and select a model for inference. \n",
111-
"***"
112-
]
113-
},
114-
{
115-
"cell_type": "code",
116-
"execution_count": null,
117-
"id": "deecb929",
118-
"metadata": {},
119-
"outputs": [],
120-
"source": [
121-
"from ipywidgets import Dropdown\n",
122-
"\n",
123-
"# download JumpStart model_manifest file.\n",
124-
"boto3.client(\"s3\").download_file(\n",
125-
" f\"jumpstart-cache-prod-{aws_region}\", \"models_manifest.json\", \"models_manifest.json\"\n",
126-
")\n",
127-
"with open(\"models_manifest.json\", \"rb\") as json_file:\n",
128-
" model_list = json.load(json_file)\n",
129-
"\n",
130-
"# filter-out all the Text Generation models from the manifest list.\n",
131-
"txt2img_models = []\n",
132-
"for model in model_list:\n",
133-
" model_id = model[\"model_id\"]\n",
134-
" if \"-txt2img-\" in model_id and model_id not in txt2img_models:\n",
135-
" txt2img_models.append(model_id)\n",
136-
"\n",
137-
"# display the model-ids in a dropdown to select a model for inference.\n",
138-
"model_dropdown = Dropdown(\n",
139-
" options=txt2img_models,\n",
140-
" value=\"huggingface-txt2img-stable-diffusion-v1-4\",\n",
141-
" description=\"Select a model\",\n",
142-
" style={\"description_width\": \"initial\"},\n",
143-
" layout={\"width\": \"max-content\"},\n",
144-
")"
145-
]
146-
},
147-
{
148-
"cell_type": "markdown",
149-
"id": "a821a4cf",
150-
"metadata": {},
151-
"source": [
152-
"#### Chose a model for Inference"
153-
]
154-
},
155-
{
156-
"cell_type": "code",
157-
"execution_count": null,
158-
"id": "01cc6c00",
159-
"metadata": {},
160-
"outputs": [],
161-
"source": [
162-
"display(model_dropdown)"
163-
]
164-
},
165-
{
166-
"cell_type": "code",
167-
"execution_count": null,
168-
"id": "2ff82d42",
169-
"metadata": {},
170-
"outputs": [],
171-
"source": [
172-
"# model_version=\"*\" fetches the latest version of the model\n",
173-
"model_id, model_version = model_dropdown.value, \"*\""
174-
]
175-
},
176105
{
177106
"cell_type": "markdown",
178107
"id": "8f3ab601",
179108
"metadata": {},
180109
"source": [
181-
"### 3. Retrieve JumpStart Artifacts & Deploy an Endpoint\n",
110+
"### 2. Retrieve JumpStart Artifacts & Deploy an Endpoint\n",
182111
"\n",
183112
"***\n",
184113
"\n",
@@ -191,14 +120,18 @@
191120
"cell_type": "code",
192121
"execution_count": null,
193122
"id": "a8a79ec9",
194-
"metadata": {},
123+
"metadata": {
124+
"tags": []
125+
},
195126
"outputs": [],
196127
"source": [
197128
"from sagemaker import image_uris, model_uris, script_uris, hyperparameters\n",
198129
"from sagemaker.model import Model\n",
199130
"from sagemaker.predictor import Predictor\n",
200131
"from sagemaker.utils import name_from_base\n",
201132
"\n",
133+
"# model_version=\"*\" fetches the latest version of the model\n",
134+
"model_id, model_version = \"model-txt2img-stabilityai-stable-diffusion-v1-4\", \"*\"\n",
202135
"\n",
203136
"endpoint_name = name_from_base(f\"jumpstart-example-infer-{model_id}\")\n",
204137
"\n",
@@ -252,7 +185,7 @@
252185
"id": "b2e0fd36",
253186
"metadata": {},
254187
"source": [
255-
"### 4. Query endpoint and parse response\n",
188+
"### 3. Query endpoint and parse response\n",
256189
"\n",
257190
"---\n",
258191
"Input to the endpoint is any string of text dumped in json and encoded in `utf-8` format. Output of the endpoint is a `json` with generated text.\n",
@@ -264,7 +197,9 @@
264197
"cell_type": "code",
265198
"execution_count": null,
266199
"id": "84fb30d0",
267-
"metadata": {},
200+
"metadata": {
201+
"tags": []
202+
},
268203
"outputs": [],
269204
"source": [
270205
"import matplotlib.pyplot as plt\n",
@@ -320,7 +255,8 @@
320255
"metadata": {
321256
"pycharm": {
322257
"is_executing": true
323-
}
258+
},
259+
"tags": []
324260
},
325261
"outputs": [],
326262
"source": [
@@ -339,7 +275,7 @@
339275
}
340276
},
341277
"source": [
342-
"### 5. Advanced features\n",
278+
"### 4. Advanced features\n",
343279
"\n",
344280
"***\n",
345281
"This model also supports many advanced parameters while performing inference. They include:\n",
@@ -362,7 +298,8 @@
362298
"metadata": {
363299
"pycharm": {
364300
"is_executing": true
365-
}
301+
},
302+
"tags": []
366303
},
367304
"outputs": [],
368305
"source": [
@@ -412,7 +349,7 @@
412349
"id": "870d1173",
413350
"metadata": {},
414351
"source": [
415-
"### 6. Clean up the endpoint"
352+
"### 5. Clean up the endpoint"
416353
]
417354
},
418355
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
### SageMaker JumpStart Text to Image
2-
This notebook `Amazon_JumpStart_Text_To_Image.ipynb` demos how to use JumpStart to generate image conditioned on text that appears indistinguishable from the real images.
2+
This notebook `Amazon_JumpStart_Text_To_Image.ipynb` demos how to use JumpStart to generate image conditioned on text that appears indistinguishable from a real images.

0 commit comments

Comments
 (0)