Skip to content

Commit 4abe8c5

Browse files
xieyongliangatqy
andauthored
Generative fill demo for re'Invent2023 (#4477)
* add lab7-hosting-controlnet-models-on-sagemaker * remove stable-diffusion-webui-dreambooth-training.ipynb * update for controlnet extension upgrade * update Dockerfile.training and Dockerfile.inference and cleanup * update train.py and serve * update README.md * fix issues with subprocess and update Dockerfile for training and inference * cleanup * cleanup * cleanup * cleanup * remove training part * remove train.sh * cleanup * switch to use djl-inference:0.21.0-fastertransformer5.3.0-cu117 * revise the Dockerfile.inference to login the public ECR * update Dockerfile * update ipynb for shell script * revise shell script in ipynb * revise for Docker build * update ipynb * revise ipynb * update ipynb * update ipynb * cleanup * cleanup * remove --no-half --precision full * add docker comments * add docker comment * switch to docker testing * switch to docker * switch to docker * switch to docker * switch to docker * switch to docker * switch to docker * add CI build test information * change seed/subseed for Lora character * add disclaimers upon to legal requirement * add missing file - build_and_push.sh * change kernel * test * test * test * test * test * upgrade webui to v1.5.1 and pytorch to 2.0.1 * cleanup * minor cleanup * minor cleanup * update to v1.6.0 * cleanup * update for generative fill * update for generative fill * cleanup * cleanup && add badges * update the notebook to use different text prompt * cleanup * revise for docker build on sagemaker notebook and sagemaker studio * reformat for notebook * update README * cleanup * cleanup * add libtcmalloc-minimal4 in Dockerfile * clear all outputs * cleanup * update README --------- Co-authored-by: atqy <[email protected]> Co-authored-by: atqy <[email protected]>
1 parent 720198b commit 4abe8c5

File tree

7 files changed

+2182
-922
lines changed

7 files changed

+2182
-922
lines changed

inference/generativeai/llm-workshop/lab12-hosting-controlnet-models-on-sagemaker/Dockerfile.inference

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
ARG REGION
22
FROM 763104351884.dkr.ecr.$REGION.amazonaws.com/pytorch-inference:2.0.1-gpu-py310-cu118-ubuntu20.04-sagemaker
33

4-
RUN apt update && apt install wget git libgl1-mesa-glx libcairo2-dev -y
4+
RUN apt update && apt install wget git libgl1-mesa-glx libcairo2-dev libtcmalloc-minimal4 -y
55
RUN rm -rf /opt/conda/lib/python3.10/site-packages/opencv_python-4.6.0.dist-info/
66
RUN pip install opencv-python
7-
RUN pip install install -U -I --no-deps xformers==0.0.20
7+
RUN pip install xformers==0.0.22.post7 --extra-index-url https://download.pytorch.org/whl/cu118
88
RUN pip install boto3 huggingface_hub triton deepspeed accelerate
99

1010
RUN mkdir -p /opt/ml/code
1111
WORKDIR /opt/ml/code
1212

13-
ADD https://api.github.com/repos/xieyongliang/stable-diffusion-webui/git/refs/heads/api-v1.5.1 /opt/ml/webui.version.json
14-
RUN git clone https://github.com/xieyongliang/stable-diffusion-webui.git /opt/ml/code -b api-v1.5.1
13+
ADD https://api.github.com/repos/xieyongliang/stable-diffusion-webui/git/refs/heads/api /opt/ml/webui.version.json
14+
RUN git clone https://github.com/xieyongliang/stable-diffusion-webui.git /opt/ml/code -b api
1515

1616
ADD https://api.github.com/repos/Mikubill/sd-webui-controlnet/git/refs/heads/main /opt/ml/controlnet.version.json
1717
RUN git clone https://github.com/Mikubill/sd-webui-controlnet.git /opt/ml/code/extensions/sd-webui-controlnet
1818

19+
ADD https://api.github.com/repos/xieyongliang/inpaint-anything/git/refs/heads/main /opt/ml/inpaint-anything.version.json
20+
RUN git clone https://github.com/xieyongliang/inpaint-anything.git /opt/ml/code/extensions/inpaint-anything
21+
1922
RUN python launch.py -f --exit --skip-torch-cuda-test
20-
RUN pip install -U pytorch_lightning==1.6.5 pydantic==1.10.11
23+
RUN pip install -U pytorch_lightning==1.6.5 pydantic==1.10.11 httpx==0.24.1
24+
RUN pip install -U torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
25+
2126
RUN rm requirements.txt
2227

2328
COPY serve /opt/ml/code
Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,89 @@
11
# stable-diffusion-webui-api
22

3-
This repo shows how to use stable-diffusion-webui to build Amazon SageMaker Docker image for inference and training job and how to generate images based on the combination with Stable-diffusion models and ControlNet / Lora models.
3+
## Overview
44

5-
You will find 2 Jupyter Notebooks: 1 for sync ControlNet / Lora inference, and 1 for async ControlNet / Lora inference.
5+
In this notebook, we will explore how to build generative fill application and host Stable Diffusion/ ControlNet / segment anything models on SageMaker asynchronous endpoint using DLC container.
66

7-
Note: Amazon Web Services has no control or authority over the third-party generative AI service referenced in this Workshop, and does not make any representations or warranties that the third-party generative AI service is secure, virus-free, operational, or compatible with your production environment and standards. You are responsible for making your own independent assessment of the content provided in this Workshop, and take measures to ensure that you comply with your own specific quality control practices and standards, and the local rules, laws, regulations, licenses and terms of use that apply to you, your content, and the third-party generative AI service referenced in this Workshop. The content of this Workshop: (a) is for informational purposes only, (b) represents current Amazon Web Services product offerings and practices, which are subject to change without notice, and (c) does not create any commitments or assurances from Beijing Sinnet Technology Co., Ltd. (“Sinnet”), Ningxia Western Cloud Data Technology Co., Ltd. (“NWCD”), Amazon Connect Technology Services (Beijing) Co., Ltd. (“Amazon”), or their respective affiliates, suppliers or licensors. Amazon Web Services’ content, products or services are provided “as is” without warranties, representations, or conditions of any kind, whether express or implied. The responsibilities and liabilities of Sinnet, NWCD or Amazon to their respective customers are controlled by the applicable customer agreements.
7+
You will find 2 Jupyter Notebooks: 1 for running with Amazon SageMaker Studio and 1 for running with Amazon SageMaker Notebook.
8+
9+
## IAM role recommendations
10+
11+
1) Running with Amazon SageMaker Studio
12+
13+
* Permissions policies
14+
15+
```
16+
AmazonSageMakerFullAccess
17+
AmazonEC2ContainerRegistryFullAccess
18+
AWSCodeBuildAdminAccess
19+
IAMFullAccess
20+
```
21+
22+
* Trusted entities
23+
24+
```
25+
{
26+
"Version": "2012-10-17",
27+
"Statement": [
28+
{
29+
"Effect": "Allow",
30+
"Principal": {
31+
"Service": [
32+
"sagemaker.amazonaws.com",
33+
"codebuild.amazonaws.com"
34+
]
35+
},
36+
"Action": "sts:AssumeRole"
37+
}
38+
]
39+
}
40+
```
41+
42+
* Tested image, kernel, and instance:
43+
```
44+
image: Pytorch 2.0.1 Python 3.10 CPU Optimized
45+
kernel: Python 3
46+
instance: ml.m5.4xlarge
47+
48+
```
49+
50+
2) Running with Amazon SageMaker Notebook
51+
52+
* Permission Policies
53+
54+
```
55+
AmazonSageMakerFullAccess
56+
AmazonEC2ContainerRegistryFullAccess
57+
```
58+
59+
* Trusted entities
60+
61+
```
62+
{
63+
"Version": "2012-10-17",
64+
"Statement": [
65+
{
66+
"Effect": "Allow",
67+
"Principal": {
68+
"Service": [
69+
"ecs.amazonaws.com",
70+
"sagemaker.amazonaws.com"
71+
]
72+
},
73+
"Action": "sts:AssumeRole"
74+
}
75+
]
76+
}
77+
```
78+
79+
* Tested kernel:
80+
```
81+
kernel: conda_pytorch_p310
82+
83+
```
84+
85+
## Note
86+
87+
1. You may need to adjust IAM roles definition to achieve fine grained access control.
88+
89+
2. Amazon Web Services has no control or authority over the third-party generative AI service referenced in this Workshop, and does not make any representations or warranties that the third-party generative AI service is secure, virus-free, operational, or compatible with your production environment and standards. You are responsible for making your own independent assessment of the content provided in this Workshop, and take measures to ensure that you comply with your own specific quality control practices and standards, and the local rules, laws, regulations, licenses and terms of use that apply to you, your content, and the third-party generative AI service referenced in this Workshop. The content of this Workshop: (a) is for informational purposes only, (b) represents current Amazon Web Services product offerings and practices, which are subject to change without notice, and (c) does not create any commitments or assurances from Beijing Sinnet Technology Co., Ltd. (“Sinnet”), Ningxia Western Cloud Data Technology Co., Ltd. (“NWCD”), Amazon Connect Technology Services (Beijing) Co., Ltd. (“Amazon”), or their respective affiliates, suppliers or licensors. Amazon Web Services’ content, products or services are provided “as is” without warranties, representations, or conditions of any kind, whether express or implied. The responsibilities and liabilities of Sinnet, NWCD or Amazon to their respective customers are controlled by the applicable customer agreements.

0 commit comments

Comments
 (0)