Skip to content

Commit 5f6dade

Browse files
EtiennePerotgvisor-bot
authored andcommitted
Create Stable Diffusion XL Docker image and regression test.
PiperOrigin-RevId: 614015218
1 parent 5d51fb4 commit 5f6dade

File tree

9 files changed

+690
-1
lines changed

9 files changed

+690
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,22 @@ cos-gpu-smoke-tests: gpu-smoke-images $(RUNTIME_BIN)
298298
# This is a superset of those needed for smoke tests.
299299
# It includes non-GPU images that are used as part of GPU tests,
300300
# e.g. busybox and python.
301-
gpu-images: gpu-smoke-images load-gpu_pytorch load-gpu_ollama load-gpu_ollama_client load-basic_busybox load-basic_python
301+
gpu-images: gpu-smoke-images load-gpu_pytorch load-gpu_ollama load-gpu_ollama_client load-basic_busybox load-basic_python load-gpu_stablediffusionxl
302302
.PHONY: gpu-images
303303

304304
gpu-all-tests: gpu-images gpu-smoke-tests $(RUNTIME_BIN)
305305
@$(call install_runtime,$(RUNTIME),--nvproxy=true --nvproxy-docker=true)
306306
@$(call sudo,test/gpu:pytorch_test,--runtime=$(RUNTIME) -test.v $(ARGS))
307307
@$(call sudo,test/gpu:textgen_test,--runtime=$(RUNTIME) -test.v $(ARGS))
308+
@$(call sudo,test/gpu:imagegen_test,--runtime=$(RUNTIME) -test.v $(ARGS))
308309
@$(call sudo,test/gpu:sr_test,--runtime=$(RUNTIME) -test.v $(ARGS))
309310
.PHONY: gpu-all-tests
310311

311312
cos-gpu-all-tests: gpu-images cos-gpu-smoke-tests $(RUNTIME_BIN)
312313
@$(call install_runtime,$(RUNTIME),--nvproxy=true)
313314
@$(call sudo,test/gpu:pytorch_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
314315
@$(call sudo,test/gpu:textgen_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
316+
@$(call sudo,test/gpu:imagegen_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
315317
@$(call sudo,test/gpu:sr_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
316318
.PHONY: cos-gpu-all-tests
317319

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM nvidia/cuda:12.3.1-devel-ubuntu22.04
2+
3+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --yes \
4+
python3 \
5+
python3-distutils \
6+
python3-pip \
7+
clang \
8+
wget \
9+
vim \
10+
git \
11+
libgl1 \
12+
libglib2.0-0 \
13+
libgl1-mesa-glx \
14+
golang
15+
16+
RUN python3 -m pip install --ignore-installed \
17+
diffusers \
18+
transformers \
19+
accelerate \
20+
xformers \
21+
invisible-watermark
22+
23+
RUN go install \
24+
github.com/TheZoraiz/ascii-image-converter@d05a757c5e02ab23e97b6f6fca4e1fbeb10ab559 && \
25+
mv "$HOME/go/bin/ascii-image-converter" /usr/bin/
26+
27+
COPY download_checkpoints.py /tmp
28+
RUN chmod +x /tmp/download_checkpoints.py && \
29+
/tmp/download_checkpoints.py && \
30+
rm /tmp/download_checkpoints.py
31+
32+
COPY generate_image generate_image.py /
33+
RUN chmod 555 /generate_image /generate_image.py
34+
ENV PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
35+
ENTRYPOINT ["/generate_image"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2024 The gVisor Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Download Stable Diffusion XL checkpoints from Hugging Face."""
18+
19+
import diffusers
20+
import torch
21+
22+
# Download base model.
23+
base = diffusers.DiffusionPipeline.from_pretrained(
24+
"stabilityai/stable-diffusion-xl-base-1.0",
25+
torch_dtype=torch.float16,
26+
variant="fp16",
27+
use_safetensors=True,
28+
)
29+
30+
# Download refiner model.
31+
refiner = diffusers.DiffusionPipeline.from_pretrained(
32+
"stabilityai/stable-diffusion-xl-refiner-1.0",
33+
text_encoder_2=base.text_encoder_2,
34+
vae=base.vae,
35+
torch_dtype=torch.float16,
36+
use_safetensors=True,
37+
variant="fp16",
38+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
quiet_stderr=false
6+
for arg; do
7+
if [[ "$arg" == '--out' ]] || echo "$arg" | grep -qE '^--out='; then
8+
echo 'Cannot specify --out parameter; the image file will be written to stdout.' >&2
9+
exit 1
10+
fi
11+
if [[ "$arg" == '--quiet_stderr' ]]; then
12+
quiet_stderr=true
13+
fi
14+
done
15+
16+
# Try to find out pixel size of the shell.
17+
terminal_pixel_width=0
18+
terminal_pixel_height=0
19+
if [[ -t 1 ]]; then
20+
echo -e -n '\e[14t'; IFS=';' read -rs -t 0.5 -d 't' rest height width <$(tty)
21+
terminal_pixel_width="$width"
22+
terminal_pixel_height="$height"
23+
fi
24+
25+
out_dir="$(mktemp -d)"
26+
27+
set +e
28+
/generate_image.py \
29+
--out="$out_dir/out_image" \
30+
--terminal_pixel_width="$terminal_pixel_width" \
31+
--terminal_pixel_height="$terminal_pixel_height" \
32+
"$@" \
33+
1>/dev/null \
34+
2>"$out_dir/stderr"
35+
return_code="$?"
36+
set -e
37+
38+
if [[ "$return_code" == 0 ]]; then
39+
cat "$out_dir/out_image"
40+
fi
41+
if [[ "$return_code" != 0 ]] || [[ "$quiet_stderr" == false ]]; then
42+
cat "$out_dir/stderr" >&2
43+
fi
44+
rm -rf "$out_dir"
45+
exit "$return_code"

0 commit comments

Comments
 (0)