Skip to content

Update model id for stable diffusion in jumpstart #3669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"---\n",
"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",
"\n",
"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",
"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",
"\n",
"---"
]
Expand All @@ -27,11 +27,10 @@
"metadata": {},
"source": [
"1. [Set Up](#1.-Set-Up)\n",
"2. [Select a model](#2.-Select-a-model)\n",
"3. [Retrieve JumpStart Artifacts & Deploy an Endpoint](#3.-Retrieve-JumpStart-Artifacts-&-Deploy-an-Endpoint)\n",
"4. [Query endpoint and parse response](#4.-Query-endpoint-and-parse-response)\n",
"5. [Advanced features](#5.-Advanced-features)\n",
"6. [Clean up the endpoint](#6.-Clean-up-the-endpoint)"
"3. [Retrieve JumpStart Artifacts & Deploy an Endpoint](#2.-Retrieve-JumpStart-Artifacts-&-Deploy-an-Endpoint)\n",
"4. [Query endpoint and parse response](#3.-Query-endpoint-and-parse-response)\n",
"5. [Advanced features](#4.-Advanced-features)\n",
"6. [Clean up the endpoint](#5.-Clean-up-the-endpoint)"
]
},
{
Expand Down Expand Up @@ -65,7 +64,9 @@
"cell_type": "code",
"execution_count": null,
"id": "25293522",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"!pip install sagemaker ipywidgets --upgrade --quiet"
Expand All @@ -88,7 +89,9 @@
"cell_type": "code",
"execution_count": null,
"id": "90518e45",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import sagemaker, boto3, json\n",
Expand All @@ -99,86 +102,12 @@
"sess = sagemaker.Session()"
]
},
{
"cell_type": "markdown",
"id": "d2c1a623",
"metadata": {},
"source": [
"### 2. Select a model\n",
"\n",
"***\n",
"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",
"***"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "deecb929",
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import Dropdown\n",
"\n",
"# download JumpStart model_manifest file.\n",
"boto3.client(\"s3\").download_file(\n",
" f\"jumpstart-cache-prod-{aws_region}\", \"models_manifest.json\", \"models_manifest.json\"\n",
")\n",
"with open(\"models_manifest.json\", \"rb\") as json_file:\n",
" model_list = json.load(json_file)\n",
"\n",
"# filter-out all the Text Generation models from the manifest list.\n",
"txt2img_models = []\n",
"for model in model_list:\n",
" model_id = model[\"model_id\"]\n",
" if \"-txt2img-\" in model_id and model_id not in txt2img_models:\n",
" txt2img_models.append(model_id)\n",
"\n",
"# display the model-ids in a dropdown to select a model for inference.\n",
"model_dropdown = Dropdown(\n",
" options=txt2img_models,\n",
" value=\"huggingface-txt2img-stable-diffusion-v1-4\",\n",
" description=\"Select a model\",\n",
" style={\"description_width\": \"initial\"},\n",
" layout={\"width\": \"max-content\"},\n",
")"
]
},
{
"cell_type": "markdown",
"id": "a821a4cf",
"metadata": {},
"source": [
"#### Chose a model for Inference"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "01cc6c00",
"metadata": {},
"outputs": [],
"source": [
"display(model_dropdown)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ff82d42",
"metadata": {},
"outputs": [],
"source": [
"# model_version=\"*\" fetches the latest version of the model\n",
"model_id, model_version = model_dropdown.value, \"*\""
]
},
{
"cell_type": "markdown",
"id": "8f3ab601",
"metadata": {},
"source": [
"### 3. Retrieve JumpStart Artifacts & Deploy an Endpoint\n",
"### 2. Retrieve JumpStart Artifacts & Deploy an Endpoint\n",
"\n",
"***\n",
"\n",
Expand All @@ -191,14 +120,18 @@
"cell_type": "code",
"execution_count": null,
"id": "a8a79ec9",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from sagemaker import image_uris, model_uris, script_uris, hyperparameters\n",
"from sagemaker.model import Model\n",
"from sagemaker.predictor import Predictor\n",
"from sagemaker.utils import name_from_base\n",
"\n",
"# model_version=\"*\" fetches the latest version of the model\n",
"model_id, model_version = \"model-txt2img-stabilityai-stable-diffusion-v1-4\", \"*\"\n",
"\n",
"endpoint_name = name_from_base(f\"jumpstart-example-infer-{model_id}\")\n",
"\n",
Expand Down Expand Up @@ -252,7 +185,7 @@
"id": "b2e0fd36",
"metadata": {},
"source": [
"### 4. Query endpoint and parse response\n",
"### 3. Query endpoint and parse response\n",
"\n",
"---\n",
"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",
Expand All @@ -264,7 +197,9 @@
"cell_type": "code",
"execution_count": null,
"id": "84fb30d0",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -320,7 +255,8 @@
"metadata": {
"pycharm": {
"is_executing": true
}
},
"tags": []
},
"outputs": [],
"source": [
Expand All @@ -339,7 +275,7 @@
}
},
"source": [
"### 5. Advanced features\n",
"### 4. Advanced features\n",
"\n",
"***\n",
"This model also supports many advanced parameters while performing inference. They include:\n",
Expand All @@ -362,7 +298,8 @@
"metadata": {
"pycharm": {
"is_executing": true
}
},
"tags": []
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -412,7 +349,7 @@
"id": "870d1173",
"metadata": {},
"source": [
"### 6. Clean up the endpoint"
"### 5. Clean up the endpoint"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### SageMaker JumpStart Text to Image
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.
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.