Skip to content

Generative fill demo for re'Invent2023 #4477

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 79 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a56d67b
add lab7-hosting-controlnet-models-on-sagemaker
xieyongliang Apr 17, 2023
09669e5
remove stable-diffusion-webui-dreambooth-training.ipynb
xieyongliang Apr 17, 2023
a24e60a
update for controlnet extension upgrade
xieyongliang Apr 18, 2023
690d5b4
update Dockerfile.training and Dockerfile.inference and cleanup
xieyongliang Apr 19, 2023
f317ce1
Merge branch 'main' into main
xieyongliang Apr 19, 2023
47278df
update train.py and serve
xieyongliang Apr 19, 2023
61ce49e
Merge branch 'main' of https://github.com/xieyongliang/amazon-sagemak…
xieyongliang Apr 19, 2023
9bf6cd7
update README.md
xieyongliang Apr 19, 2023
37a0104
fix issues with subprocess and update Dockerfile for training and inf…
xieyongliang Apr 19, 2023
a7a1fb9
cleanup
xieyongliang Apr 19, 2023
0403341
cleanup
xieyongliang Apr 19, 2023
b126dc8
cleanup
xieyongliang Apr 19, 2023
f967b91
cleanup
xieyongliang Apr 19, 2023
0fde50c
remove training part
xieyongliang Apr 19, 2023
68fb6cf
remove train.sh
xieyongliang Apr 19, 2023
db078c4
cleanup
xieyongliang Apr 25, 2023
92b958a
switch to use djl-inference:0.21.0-fastertransformer5.3.0-cu117
xieyongliang Apr 27, 2023
536f3b0
revise the Dockerfile.inference to login the public ECR
xieyongliang May 5, 2023
2bb4203
update Dockerfile
xieyongliang May 7, 2023
965f2aa
update ipynb for shell script
xieyongliang May 10, 2023
9fbf050
Merge branch 'main' into main
xieyongliang May 10, 2023
7c4f385
revise shell script in ipynb
xieyongliang May 11, 2023
6745034
Merge branch 'main' of https://github.com/xieyongliang/amazon-sagemak…
xieyongliang May 11, 2023
b089203
revise for Docker build
xieyongliang May 12, 2023
deb2cd2
update ipynb
xieyongliang May 15, 2023
a7d595a
revise ipynb
xieyongliang May 15, 2023
ae7234b
update ipynb
xieyongliang May 17, 2023
7e5855c
update ipynb
xieyongliang May 17, 2023
1e6d98e
cleanup
xieyongliang May 17, 2023
156803d
cleanup
xieyongliang May 20, 2023
11746da
remove --no-half --precision full
xieyongliang May 24, 2023
a96dea2
add docker comments
atqy May 25, 2023
a6cf63e
add docker comment
atqy May 26, 2023
2c2e7f7
switch to docker testing
atqy May 30, 2023
73ab4b1
switch to docker
atqy May 30, 2023
d2feed0
switch to docker
atqy May 30, 2023
74495e3
switch to docker
atqy May 30, 2023
1759ccc
switch to docker
atqy May 30, 2023
c4376b5
switch to docker
atqy May 30, 2023
6fc8c71
switch to docker
atqy May 30, 2023
d46b032
add CI build test information
xieyongliang Jun 3, 2023
cf99cd1
change seed/subseed for Lora character
xieyongliang Jun 3, 2023
f89d7b8
add disclaimers upon to legal requirement
xieyongliang Jun 21, 2023
c1d1123
Merge branch 'main' into main
atqy Aug 21, 2023
a181601
add missing file - build_and_push.sh
xieyongliang Aug 22, 2023
deaa7c5
Merge branch 'main' of https://github.com/xieyongliang/amazon-sagemak…
xieyongliang Aug 22, 2023
eee3758
Merge branch 'main' into main
atqy Aug 23, 2023
528fd8c
change kernel
atqy Aug 23, 2023
3233e82
test
atqy Aug 23, 2023
7a50186
test
atqy Aug 23, 2023
c271b34
test
atqy Aug 23, 2023
24bab2d
test
atqy Aug 23, 2023
ee155d0
test
atqy Aug 25, 2023
b534f86
Merge branch 'main' into main
atqy Aug 25, 2023
a01f9c0
Merge branch 'aws:main' into main
xieyongliang Aug 25, 2023
7465e47
upgrade webui to v1.5.1 and pytorch to 2.0.1
xieyongliang Aug 25, 2023
b81eb6b
cleanup
xieyongliang Aug 25, 2023
4b67b91
minor cleanup
xieyongliang Aug 25, 2023
ac6fb13
minor cleanup
xieyongliang Aug 25, 2023
618ca2f
minor cleanup
xieyongliang Aug 25, 2023
1123382
Merge branch 'aws:main' into main
xieyongliang Sep 27, 2023
d2dab7e
Merge branch 'aws:main' into main
xieyongliang Nov 14, 2023
3b6cf91
update to v1.6.0
xieyongliang Nov 14, 2023
0833d90
cleanup
xieyongliang Nov 14, 2023
0b29e7e
update for generative fill
xieyongliang Nov 14, 2023
ba8d7a7
update for generative fill
xieyongliang Nov 15, 2023
603e486
cleanup
xieyongliang Nov 15, 2023
a0b90ea
cleanup && add badges
xieyongliang Nov 15, 2023
6a01e6a
update the notebook to use different text prompt
xieyongliang Nov 17, 2023
579ea08
cleanup
xieyongliang Nov 21, 2023
ee2a050
revise for docker build on sagemaker notebook and sagemaker studio
xieyongliang Nov 22, 2023
2f9641c
reformat for notebook
xieyongliang Nov 22, 2023
09cd847
update README
xieyongliang Nov 22, 2023
a795bf1
cleanup
xieyongliang Nov 22, 2023
1824b23
cleanup
xieyongliang Nov 22, 2023
b06abd2
add libtcmalloc-minimal4 in Dockerfile
xieyongliang Nov 22, 2023
9e4a236
clear all outputs
xieyongliang Nov 22, 2023
c15e3fe
cleanup
xieyongliang Nov 22, 2023
ccf2faa
update README
xieyongliang Nov 22, 2023
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
@@ -1,23 +1,28 @@
ARG REGION
FROM 763104351884.dkr.ecr.$REGION.amazonaws.com/pytorch-inference:2.0.1-gpu-py310-cu118-ubuntu20.04-sagemaker

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

RUN mkdir -p /opt/ml/code
WORKDIR /opt/ml/code

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

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

ADD https://api.github.com/repos/xieyongliang/inpaint-anything/git/refs/heads/main /opt/ml/inpaint-anything.version.json
RUN git clone https://github.com/xieyongliang/inpaint-anything.git /opt/ml/code/extensions/inpaint-anything

RUN python launch.py -f --exit --skip-torch-cuda-test
RUN pip install -U pytorch_lightning==1.6.5 pydantic==1.10.11
RUN pip install -U pytorch_lightning==1.6.5 pydantic==1.10.11 httpx==0.24.1
RUN pip install -U torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118

RUN rm requirements.txt

COPY serve /opt/ml/code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,89 @@
# stable-diffusion-webui-api

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.
## Overview

You will find 2 Jupyter Notebooks: 1 for sync ControlNet / Lora inference, and 1 for async ControlNet / Lora inference.
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.

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.
You will find 2 Jupyter Notebooks: 1 for running with Amazon SageMaker Studio and 1 for running with Amazon SageMaker Notebook.

## IAM role recommendations

1) Running with Amazon SageMaker Studio

* Permissions policies

```
AmazonSageMakerFullAccess
AmazonEC2ContainerRegistryFullAccess
AWSCodeBuildAdminAccess
IAMFullAccess
```

* Trusted entities

```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"sagemaker.amazonaws.com",
"codebuild.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
```

* Tested image, kernel, and instance:
```
image: Pytorch 2.0.1 Python 3.10 CPU Optimized
kernel: Python 3
instance: ml.m5.4xlarge

```

2) Running with Amazon SageMaker Notebook

* Permission Policies

```
AmazonSageMakerFullAccess
AmazonEC2ContainerRegistryFullAccess
```

* Trusted entities

```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ecs.amazonaws.com",
"sagemaker.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
```

* Tested kernel:
```
kernel: conda_pytorch_p310

```

## Note

1. You may need to adjust IAM roles definition to achieve fine grained access control.

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.
Binary file not shown.
Binary file not shown.
Loading