Spaces:
Build error
Build error
oneflow
Browse files- app.py +1 -9
- config.py +13 -0
- pipelines/controlnet.py +10 -0
- pipelines/img2imgSDTurbo.py +8 -0
- requirements.txt +5 -2
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 |
|
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/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,13 @@ 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.vae.encoder = oneflow_compile(self.pipe.vae.encoder)
|
| 129 |
+
self.pipe.vae.decoder = oneflow_compile(self.pipe.vae.decoder)
|
| 130 |
+
|
| 131 |
self.pipe.set_progress_bar_config(disable=True)
|
| 132 |
self.pipe.to(device=device, dtype=torch_dtype)
|
| 133 |
if device.type != "mps":
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
git+https://github.com/huggingface/diffusers@
|
| 2 |
transformers==4.35.2
|
| 3 |
--extra-index-url https://download.pytorch.org/whl/cu121;
|
| 4 |
torch==2.1.0
|
|
@@ -11,4 +11,7 @@ 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 |
+
git+https://github.com/huggingface/diffusers@22b45304bf85a3c5281753d6b3259ccaf96e5085
|
| 2 |
transformers==4.35.2
|
| 3 |
--extra-index-url https://download.pytorch.org/whl/cu121;
|
| 4 |
torch==2.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 |
+
--extra-index-url https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu121
|
| 16 |
+
oneflow
|
| 17 |
+
git+https://github.com/Oneflow-Inc/onediff.git@main#egg=onediff
|