Spaces:
Runtime error
Runtime error
cpu speed up
Browse files- app.py +26 -4
- requirements.txt +1 -0
app.py
CHANGED
@@ -12,18 +12,19 @@ from diffusers import UniPCMultistepScheduler
|
|
12 |
from diffusers import AutoencoderKL
|
13 |
from diffusers import StableDiffusionPipeline
|
14 |
from diffusers.loaders import LoraLoaderMixin
|
|
|
15 |
|
16 |
import os
|
17 |
from os.path import join as opj
|
18 |
|
19 |
-
token = os.getenv("ACCESS_TOKEN")
|
20 |
-
os.system(f"python -m pip install git+https://{token}@github.com/logn-2024/StableGarment.git")
|
21 |
|
22 |
from stablegarment.models import GarmentEncoderModel,ControlNetModel
|
23 |
from stablegarment.piplines import StableGarmentPipeline,StableGarmentControlNetPipeline
|
24 |
|
25 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
26 |
-
torch_dtype = torch.
|
27 |
height = 512
|
28 |
width = 384
|
29 |
|
@@ -39,6 +40,27 @@ pipeline_t2i = StableGarmentPipeline.from_pretrained(base_model_path, vae=vae, t
|
|
39 |
# pipeline = StableDiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V4.0_noVAE", vae=vae, torch_dtype=torch_dtype).to(device=device)
|
40 |
pipeline_t2i.scheduler = scheduler
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
pipeline_tryon = None
|
43 |
'''
|
44 |
# not ready
|
|
|
12 |
from diffusers import AutoencoderKL
|
13 |
from diffusers import StableDiffusionPipeline
|
14 |
from diffusers.loaders import LoraLoaderMixin
|
15 |
+
import intel_extension_for_pytorch as ipex
|
16 |
|
17 |
import os
|
18 |
from os.path import join as opj
|
19 |
|
20 |
+
# token = os.getenv("ACCESS_TOKEN")
|
21 |
+
# os.system(f"python -m pip install git+https://{token}@github.com/logn-2024/StableGarment.git")
|
22 |
|
23 |
from stablegarment.models import GarmentEncoderModel,ControlNetModel
|
24 |
from stablegarment.piplines import StableGarmentPipeline,StableGarmentControlNetPipeline
|
25 |
|
26 |
+
device = "cpu" #"cuda" if torch.cuda.is_available() else "cpu"
|
27 |
+
torch_dtype = torch.bfloat16 if device=="cpu" else torch.float16
|
28 |
height = 512
|
29 |
width = 384
|
30 |
|
|
|
40 |
# pipeline = StableDiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V4.0_noVAE", vae=vae, torch_dtype=torch_dtype).to(device=device)
|
41 |
pipeline_t2i.scheduler = scheduler
|
42 |
|
43 |
+
|
44 |
+
# speed up for cpu
|
45 |
+
# to channels last
|
46 |
+
pipeline_t2i.unet = pipeline_t2i.unet.to(memory_format=torch.channels_last)
|
47 |
+
pipeline_t2i.vae = pipeline_t2i.vae.to(memory_format=torch.channels_last)
|
48 |
+
pipeline_t2i.text_encoder = pipeline_t2i.text_encoder.to(memory_format=torch.channels_last)
|
49 |
+
# pipeline_t2i.safety_checker = pipeline_t2i.safety_checker.to(memory_format=torch.channels_last)
|
50 |
+
|
51 |
+
# Create random input to enable JIT compilation
|
52 |
+
sample = torch.randn(2,4,64,64).type(torch_dtype)
|
53 |
+
timestep = torch.rand(1)*999
|
54 |
+
encoder_hidden_status = torch.randn(2,77,768).type(torch_dtype)
|
55 |
+
input_example = (sample, timestep, encoder_hidden_status)
|
56 |
+
|
57 |
+
# optimize with IPEX
|
58 |
+
pipeline_t2i.unet = ipex.optimize(pipeline_t2i.unet.eval(), dtype=torch.bfloat16, inplace=True, sample_input=input_example)
|
59 |
+
pipeline_t2i.vae = ipex.optimize(pipeline_t2i.vae.eval(), dtype=torch.bfloat16, inplace=True)
|
60 |
+
pipeline_t2i.text_encoder = ipex.optimize(pipeline_t2i.text_encoder.eval(), dtype=torch.bfloat16, inplace=True)
|
61 |
+
# pipeline_t2i.safety_checker = ipex.optimize(pipeline_t2i.safety_checker.eval(), dtype=torch.bfloat16, inplace=True)
|
62 |
+
|
63 |
+
|
64 |
pipeline_tryon = None
|
65 |
'''
|
66 |
# not ready
|
requirements.txt
CHANGED
@@ -6,4 +6,5 @@ spaces
|
|
6 |
Pillow
|
7 |
numpy
|
8 |
accelerate
|
|
|
9 |
# git+https://github.com/logn-2024/StableGarment.git
|
|
|
6 |
Pillow
|
7 |
numpy
|
8 |
accelerate
|
9 |
+
intel_extension_for_pytorch
|
10 |
# git+https://github.com/logn-2024/StableGarment.git
|