Spaces:
Running
on
A100
Running
on
A100
oneflow
Browse files- Dockerfile +2 -2
- app.py +1 -9
- build-run.sh +5 -1
- config.py +13 -0
- pipelines/controlnet.py +10 -0
- pipelines/controlnetSDTurbo.py +10 -0
- pipelines/img2imgSDTurbo.py +9 -0
- requirements.txt +5 -3
Dockerfile
CHANGED
@@ -15,7 +15,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
|
15 |
google-perftools \
|
16 |
ca-certificates curl gnupg \
|
17 |
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
18 |
-
|
19 |
WORKDIR /code
|
20 |
|
21 |
RUN mkdir -p /etc/apt/keyrings
|
@@ -36,7 +36,7 @@ ENV HOME=/home/user \
|
|
36 |
PYTHONUNBUFFERED=1 \
|
37 |
SYSTEM=spaces
|
38 |
|
39 |
-
RUN pip3 install --no-cache-dir --upgrade -r /code/requirements.txt
|
40 |
|
41 |
# Set the working directory to the user's home directory
|
42 |
WORKDIR $HOME/app
|
|
|
15 |
google-perftools \
|
16 |
ca-certificates curl gnupg \
|
17 |
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
18 |
+
|
19 |
WORKDIR /code
|
20 |
|
21 |
RUN mkdir -p /etc/apt/keyrings
|
|
|
36 |
PYTHONUNBUFFERED=1 \
|
37 |
SYSTEM=spaces
|
38 |
|
39 |
+
RUN pip3 install --no-cache-dir --upgrade --pre -r /code/requirements.txt
|
40 |
|
41 |
# Set the working directory to the user's home directory
|
42 |
WORKDIR $HOME/app
|
app.py
CHANGED
@@ -6,17 +6,9 @@ from app_init import init_app
|
|
6 |
from user_queue import user_data
|
7 |
from util import get_pipeline_class
|
8 |
|
9 |
-
|
10 |
print("DEVICE:", device)
|
11 |
print("TORCH_DTYPE:", torch_dtype)
|
12 |
-
|
13 |
-
print("SAFETY_CHECKER:", args.safety_checker)
|
14 |
-
print("TORCH_COMPILE:", args.torch_compile)
|
15 |
-
print("SFast:", args.sfast)
|
16 |
-
print("USE_TAESD:", args.taesd)
|
17 |
-
print("COMPEL:", args.compel)
|
18 |
-
print("DEBUG:", args.debug)
|
19 |
-
|
20 |
|
21 |
app = FastAPI()
|
22 |
|
|
|
6 |
from user_queue import user_data
|
7 |
from util import get_pipeline_class
|
8 |
|
|
|
9 |
print("DEVICE:", device)
|
10 |
print("TORCH_DTYPE:", torch_dtype)
|
11 |
+
args.pretty_print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
app = FastAPI()
|
14 |
|
build-run.sh
CHANGED
@@ -12,5 +12,9 @@ cd ../
|
|
12 |
if [ -z ${PIPELINE+x} ]; then
|
13 |
PIPELINE="controlnet"
|
14 |
fi
|
|
|
|
|
|
|
15 |
echo -e "\033[1;32m\npipeline: $PIPELINE \033[0m"
|
16 |
-
|
|
|
|
12 |
if [ -z ${PIPELINE+x} ]; then
|
13 |
PIPELINE="controlnet"
|
14 |
fi
|
15 |
+
if [ -z ${COMPILE+x} ]; then
|
16 |
+
COMPILE="--sfast"
|
17 |
+
fi
|
18 |
echo -e "\033[1;32m\npipeline: $PIPELINE \033[0m"
|
19 |
+
echo -e "\033[1;32m\ncompile: $COMPILE \033[0m"
|
20 |
+
python3 run.py --port 7860 --host 0.0.0.0 --pipeline $PIPELINE $COMPILE
|
config.py
CHANGED
@@ -17,9 +17,16 @@ class Args(NamedTuple):
|
|
17 |
ssl_certfile: str
|
18 |
ssl_keyfile: str
|
19 |
sfast: bool
|
|
|
20 |
compel: bool = False
|
21 |
debug: bool = False
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
MAX_QUEUE_SIZE = int(os.environ.get("MAX_QUEUE_SIZE", 0))
|
25 |
TIMEOUT = float(os.environ.get("TIMEOUT", 0))
|
@@ -109,6 +116,12 @@ parser.add_argument(
|
|
109 |
default=False,
|
110 |
help="Enable Stable Fast",
|
111 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
parser.set_defaults(taesd=USE_TAESD)
|
113 |
|
114 |
args = Args(**vars(parser.parse_args()))
|
|
|
17 |
ssl_certfile: str
|
18 |
ssl_keyfile: str
|
19 |
sfast: bool
|
20 |
+
oneflow: bool = False
|
21 |
compel: bool = False
|
22 |
debug: bool = False
|
23 |
|
24 |
+
def pretty_print(self):
|
25 |
+
print("\n")
|
26 |
+
for field, value in self._asdict().items():
|
27 |
+
print(f"{field}: {value}")
|
28 |
+
print("\n")
|
29 |
+
|
30 |
|
31 |
MAX_QUEUE_SIZE = int(os.environ.get("MAX_QUEUE_SIZE", 0))
|
32 |
TIMEOUT = float(os.environ.get("TIMEOUT", 0))
|
|
|
116 |
default=False,
|
117 |
help="Enable Stable Fast",
|
118 |
)
|
119 |
+
parser.add_argument(
|
120 |
+
"--oneflow",
|
121 |
+
action="store_true",
|
122 |
+
default=False,
|
123 |
+
help="Enable OneFlow",
|
124 |
+
)
|
125 |
parser.set_defaults(taesd=USE_TAESD)
|
126 |
|
127 |
args = Args(**vars(parser.parse_args()))
|
pipelines/controlnet.py
CHANGED
@@ -175,6 +175,7 @@ class Pipeline:
|
|
175 |
).to(device)
|
176 |
|
177 |
if args.sfast:
|
|
|
178 |
from sfast.compilers.stable_diffusion_pipeline_compiler import (
|
179 |
compile,
|
180 |
CompilationConfig,
|
@@ -186,6 +187,15 @@ class Pipeline:
|
|
186 |
config.enable_cuda_graph = True
|
187 |
self.pipe = compile(self.pipe, config=config)
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
self.canny_torch = SobelOperator(device=device)
|
190 |
self.pipe.set_progress_bar_config(disable=True)
|
191 |
self.pipe.to(device=device, dtype=torch_dtype)
|
|
|
175 |
).to(device)
|
176 |
|
177 |
if args.sfast:
|
178 |
+
print("\nRunning sfast compile\n")
|
179 |
from sfast.compilers.stable_diffusion_pipeline_compiler import (
|
180 |
compile,
|
181 |
CompilationConfig,
|
|
|
187 |
config.enable_cuda_graph = True
|
188 |
self.pipe = compile(self.pipe, config=config)
|
189 |
|
190 |
+
if args.oneflow:
|
191 |
+
print("\nRunning oneflow compile\n")
|
192 |
+
from onediff.infer_compiler import oneflow_compile
|
193 |
+
|
194 |
+
self.pipe.unet = oneflow_compile(self.pipe.unet)
|
195 |
+
self.pipe.vae.encoder = oneflow_compile(self.pipe.vae.encoder)
|
196 |
+
self.pipe.vae.decoder = oneflow_compile(self.pipe.vae.decoder)
|
197 |
+
self.pipe.controlnet = oneflow_compile(self.pipe.controlnet)
|
198 |
+
|
199 |
self.canny_torch = SobelOperator(device=device)
|
200 |
self.pipe.set_progress_bar_config(disable=True)
|
201 |
self.pipe.to(device=device, dtype=torch_dtype)
|
pipelines/controlnetSDTurbo.py
CHANGED
@@ -182,6 +182,7 @@ class Pipeline:
|
|
182 |
).to(device)
|
183 |
|
184 |
if args.sfast:
|
|
|
185 |
from sfast.compilers.stable_diffusion_pipeline_compiler import (
|
186 |
compile,
|
187 |
CompilationConfig,
|
@@ -193,6 +194,15 @@ class Pipeline:
|
|
193 |
config.enable_cuda_graph = True
|
194 |
self.pipe = compile(self.pipe, config=config)
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
self.canny_torch = SobelOperator(device=device)
|
197 |
|
198 |
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
|
|
182 |
).to(device)
|
183 |
|
184 |
if args.sfast:
|
185 |
+
print("\nRunning sfast compile\n")
|
186 |
from sfast.compilers.stable_diffusion_pipeline_compiler import (
|
187 |
compile,
|
188 |
CompilationConfig,
|
|
|
194 |
config.enable_cuda_graph = True
|
195 |
self.pipe = compile(self.pipe, config=config)
|
196 |
|
197 |
+
if args.oneflow:
|
198 |
+
print("\nRunning oneflow compile\n")
|
199 |
+
from onediff.infer_compiler import oneflow_compile
|
200 |
+
|
201 |
+
self.pipe.unet = oneflow_compile(self.pipe.unet)
|
202 |
+
self.pipe.vae.encoder = oneflow_compile(self.pipe.vae.encoder)
|
203 |
+
self.pipe.vae.decoder = oneflow_compile(self.pipe.vae.decoder)
|
204 |
+
self.pipe.controlnet = oneflow_compile(self.pipe.controlnet)
|
205 |
+
|
206 |
self.canny_torch = SobelOperator(device=device)
|
207 |
|
208 |
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
pipelines/img2imgSDTurbo.py
CHANGED
@@ -109,6 +109,7 @@ class Pipeline:
|
|
109 |
).to(device)
|
110 |
|
111 |
if args.sfast:
|
|
|
112 |
from sfast.compilers.stable_diffusion_pipeline_compiler import (
|
113 |
compile,
|
114 |
CompilationConfig,
|
@@ -120,6 +121,14 @@ class Pipeline:
|
|
120 |
config.enable_cuda_graph = True
|
121 |
self.pipe = compile(self.pipe, config=config)
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
self.pipe.set_progress_bar_config(disable=True)
|
124 |
self.pipe.to(device=device, dtype=torch_dtype)
|
125 |
if device.type != "mps":
|
|
|
109 |
).to(device)
|
110 |
|
111 |
if args.sfast:
|
112 |
+
print("\nRunning sfast compile\n")
|
113 |
from sfast.compilers.stable_diffusion_pipeline_compiler import (
|
114 |
compile,
|
115 |
CompilationConfig,
|
|
|
121 |
config.enable_cuda_graph = True
|
122 |
self.pipe = compile(self.pipe, config=config)
|
123 |
|
124 |
+
if args.oneflow:
|
125 |
+
print("\nRunning oneflow compile\n")
|
126 |
+
from onediff.infer_compiler import oneflow_compile
|
127 |
+
|
128 |
+
self.pipe.unet = oneflow_compile(self.pipe.unet)
|
129 |
+
self.pipe.vae.encoder = oneflow_compile(self.pipe.vae.encoder)
|
130 |
+
self.pipe.vae.decoder = oneflow_compile(self.pipe.vae.decoder)
|
131 |
+
|
132 |
self.pipe.set_progress_bar_config(disable=True)
|
133 |
self.pipe.to(device=device, dtype=torch_dtype)
|
134 |
if device.type != "mps":
|
requirements.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
|
2 |
transformers==4.35.2
|
3 |
--extra-index-url https://download.pytorch.org/whl/cu121;
|
4 |
-
torch
|
5 |
fastapi==0.104.1
|
6 |
uvicorn[standard]==0.24.0.post1
|
7 |
Pillow==10.1.0
|
@@ -11,4 +11,6 @@ controlnet-aux==0.0.7
|
|
11 |
peft==0.6.0
|
12 |
xformers; sys_platform != 'darwin' or platform_machine != 'arm64'
|
13 |
markdown2
|
14 |
-
stable_fast @ https://github.com/chengzeyi/stable-fast/releases/download/v0.0.15.post1/stable_fast-0.0.15.post1+torch211cu121-cp310-cp310-manylinux2014_x86_64.whl
|
|
|
|
|
|
1 |
+
diffusers==0.24.0
|
2 |
transformers==4.35.2
|
3 |
--extra-index-url https://download.pytorch.org/whl/cu121;
|
4 |
+
torch
|
5 |
fastapi==0.104.1
|
6 |
uvicorn[standard]==0.24.0.post1
|
7 |
Pillow==10.1.0
|
|
|
11 |
peft==0.6.0
|
12 |
xformers; sys_platform != 'darwin' or platform_machine != 'arm64'
|
13 |
markdown2
|
14 |
+
stable_fast @ https://github.com/chengzeyi/stable-fast/releases/download/v0.0.15.post1/stable_fast-0.0.15.post1+torch211cu121-cp310-cp310-manylinux2014_x86_64.whl
|
15 |
+
oneflow @ https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu121/794a56cc787217f46b21f5cbc84f65295664b82c/oneflow-0.9.1%2Bcu121.git.794a56c-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
|
16 |
+
git+https://github.com/Oneflow-Inc/onediff.git@main#egg=onediff
|