Skip to content

Commit c40d924

Browse files
Aisukomudler
authored andcommitted
feat(conda): Add seperate conda env for diffusers (#1145)
**Description** This PR relates to #1117 **Notes for Reviewers** * Add `conda` env `diffusers.yml` * Add Makefile to create it automatically * Add `run.sh` to support running as a extra backend * Also adding it to the main Dockerfile * Add make command in the root Makefile * Testing the server, it can start up under the env Signed-off-by: GitHub <[email protected]> Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent d1d164b commit c40d924

File tree

7 files changed

+118
-12
lines changed

7 files changed

+118
-12
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ARG TARGETARCH
1414
ARG TARGETVARIANT
1515

1616
ENV BUILD_TYPE=${BUILD_TYPE}
17-
ENV EXTERNAL_GRPC_BACKENDS="huggingface-embeddings:/build/extra/grpc/huggingface/huggingface.py,autogptq:/build/extra/grpc/autogptq/run.sh,bark:/build/extra/grpc/bark/run.sh,diffusers:/build/extra/grpc/diffusers/backend_diffusers.py,exllama:/build/extra/grpc/exllama/exllama.py,vall-e-x:/build/extra/grpc/vall-e-x/ttsvalle.py,vllm:/build/extra/grpc/vllm/backend_vllm.py"
17+
ENV EXTERNAL_GRPC_BACKENDS="huggingface-embeddings:/build/extra/grpc/huggingface/huggingface.py,autogptq:/build/extra/grpc/autogptq/run.sh,bark:/build/extra/grpc/bark/run.sh,diffusers:/build/extra/grpc/diffusers/run.sh,exllama:/build/extra/grpc/exllama/exllama.py,vall-e-x:/build/extra/grpc/vall-e-x/ttsvalle.py,vllm:/build/extra/grpc/vllm/backend_vllm.py"
1818
ENV GALLERIES='[{"name":"model-gallery", "url":"github:go-skynet/model-gallery/index.yaml"}, {"url": "github:go-skynet/model-gallery/huggingface.yaml","name":"huggingface"}]'
1919
ARG GO_TAGS="stablediffusion tts"
2020

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ protogen-python:
412412
prepare-extra-conda-environments:
413413
$(MAKE) -C extra/grpc/autogptq
414414
$(MAKE) -C extra/grpc/bark
415+
$(MAKE) -C extra/grpc/diffusers
415416

416417
backend-assets/grpc:
417418
mkdir -p backend-assets/grpc

extra/grpc/diffusers/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PONY: diffusers
2+
diffusers:
3+
@echo "Creating virtual environment..."
4+
@conda env create --name diffusers --file diffusers.yml
5+
@echo "Virtual environment created."
6+
7+
.PONY: run
8+
run:
9+
@echo "Running diffusers..."
10+
bash run.sh
11+
@echo "Diffusers run."

extra/grpc/diffusers/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Creating a separate environment for the diffusers project
2+
3+
```
4+
make diffusers
5+
```

extra/grpc/diffusers/backend_diffusers.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
#!/usr/bin/env python3
2-
import grpc
32
from concurrent import futures
4-
import time
5-
import backend_pb2
6-
import backend_pb2_grpc
3+
74
import argparse
5+
from collections import defaultdict
6+
from enum import Enum
87
import signal
98
import sys
9+
import time
1010
import os
1111

12-
# import diffusers
12+
from PIL import Image
1313
import torch
14-
from torch import autocast
14+
15+
import backend_pb2
16+
import backend_pb2_grpc
17+
18+
import grpc
19+
1520
from diffusers import StableDiffusionXLPipeline, StableDiffusionDepth2ImgPipeline, DPMSolverMultistepScheduler, StableDiffusionPipeline, DiffusionPipeline, EulerAncestralDiscreteScheduler
21+
from diffusers import StableDiffusionImg2ImgPipeline
1622
from diffusers.pipelines.stable_diffusion import safety_checker
23+
1724
from compel import Compel
18-
from PIL import Image
19-
from io import BytesIO
20-
from diffusers import StableDiffusionImg2ImgPipeline
25+
2126
from transformers import CLIPTextModel
22-
from enum import Enum
23-
from collections import defaultdict
2427
from safetensors.torch import load_file
28+
29+
2530
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
2631
COMPEL=os.environ.get("COMPEL", "1") == "1"
2732
CLIPSKIP=os.environ.get("CLIPSKIP", "1") == "1"

extra/grpc/diffusers/diffusers.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: diffusers
2+
channels:
3+
- defaults
4+
dependencies:
5+
- _libgcc_mutex=0.1=main
6+
- _openmp_mutex=5.1=1_gnu
7+
- bzip2=1.0.8=h7b6447c_0
8+
- ca-certificates=2023.08.22=h06a4308_0
9+
- ld_impl_linux-64=2.38=h1181459_1
10+
- libffi=3.4.4=h6a678d5_0
11+
- libgcc-ng=11.2.0=h1234567_1
12+
- libgomp=11.2.0=h1234567_1
13+
- libstdcxx-ng=11.2.0=h1234567_1
14+
- libuuid=1.41.5=h5eee18b_0
15+
- ncurses=6.4=h6a678d5_0
16+
- openssl=3.0.11=h7f8727e_2
17+
- pip=23.2.1=py311h06a4308_0
18+
- python=3.11.5=h955ad1f_0
19+
- readline=8.2=h5eee18b_0
20+
- setuptools=68.0.0=py311h06a4308_0
21+
- sqlite=3.41.2=h5eee18b_0
22+
- tk=8.6.12=h1ccaba5_0
23+
- tzdata=2023c=h04d1e81_0
24+
- wheel=0.41.2=py311h06a4308_0
25+
- xz=5.4.2=h5eee18b_0
26+
- zlib=1.2.13=h5eee18b_0
27+
- pip:
28+
- accelerate==0.23.0
29+
- certifi==2023.7.22
30+
- charset-normalizer==3.3.0
31+
- compel==2.0.2
32+
- diffusers==0.21.4
33+
- filelock==3.12.4
34+
- fsspec==2023.9.2
35+
- grpcio==1.59.0
36+
- huggingface-hub==0.17.3
37+
- idna==3.4
38+
- importlib-metadata==6.8.0
39+
- jinja2==3.1.2
40+
- markupsafe==2.1.3
41+
- mpmath==1.3.0
42+
- networkx==3.1
43+
- numpy==1.26.0
44+
- nvidia-cublas-cu12==12.1.3.1
45+
- nvidia-cuda-cupti-cu12==12.1.105
46+
- nvidia-cuda-nvrtc-cu12==12.1.105
47+
- nvidia-cuda-runtime-cu12==12.1.105
48+
- nvidia-cudnn-cu12==8.9.2.26
49+
- nvidia-cufft-cu12==11.0.2.54
50+
- nvidia-curand-cu12==10.3.2.106
51+
- nvidia-cusolver-cu12==11.4.5.107
52+
- nvidia-cusparse-cu12==12.1.0.106
53+
- nvidia-nccl-cu12==2.18.1
54+
- nvidia-nvjitlink-cu12==12.2.140
55+
- nvidia-nvtx-cu12==12.1.105
56+
- packaging==23.2
57+
- pillow==10.0.1
58+
- protobuf==4.24.4
59+
- psutil==5.9.5
60+
- pyparsing==3.1.1
61+
- pyyaml==6.0.1
62+
- regex==2023.10.3
63+
- requests==2.31.0
64+
- safetensors==0.4.0
65+
- sympy==1.12
66+
- tokenizers==0.14.1
67+
- torch==2.1.0
68+
- tqdm==4.66.1
69+
- transformers==4.34.0
70+
- triton==2.1.0
71+
- typing-extensions==4.8.0
72+
- urllib3==2.0.6
73+
- zipp==3.17.0
74+
prefix: /opt/conda/envs/diffusers

extra/grpc/diffusers/run.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
##
2+
## A bash script wrapper that runs the diffusers server with conda
3+
4+
# Activate conda environment
5+
source activate diffusers
6+
7+
# get the directory where the bash script is located
8+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
9+
10+
python $DIR/backend_diffusers.py

0 commit comments

Comments
 (0)