Commit
·
c7d725d
1
Parent(s):
8947670
speed up demo
Browse files- README.md +1 -2
- app.py +7 -3
- requirements.txt +7 -4
README.md
CHANGED
@@ -4,10 +4,9 @@ emoji: 👀
|
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: agpl-3.0
|
11 |
---
|
12 |
|
13 |
Inference Code: https://github.com/PixArt-alpha/PixArt-alpha
|
|
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.1.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Inference Code: https://github.com/PixArt-alpha/PixArt-alpha
|
app.py
CHANGED
@@ -22,7 +22,7 @@ if not torch.cuda.is_available():
|
|
22 |
MAX_SEED = np.iinfo(np.int32).max
|
23 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "1") == "1"
|
24 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
25 |
-
USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "
|
26 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
27 |
|
28 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
@@ -96,6 +96,7 @@ if torch.cuda.is_available():
|
|
96 |
pipe = PixArtAlphaPipeline.from_pretrained(
|
97 |
"PixArt-alpha/PixArt-XL-2-1024-MS",
|
98 |
torch_dtype=torch.float16,
|
|
|
99 |
use_safetensors=True,
|
100 |
)
|
101 |
|
@@ -105,6 +106,9 @@ if torch.cuda.is_available():
|
|
105 |
pipe.to(device)
|
106 |
print("Loaded on Device!")
|
107 |
|
|
|
|
|
|
|
108 |
if USE_TORCH_COMPILE:
|
109 |
pipe.transformer = torch.compile(
|
110 |
pipe.transformer, mode="reduce-overhead", fullgraph=True
|
@@ -254,7 +258,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
254 |
fn=lambda x: gr.update(visible=x),
|
255 |
inputs=use_negative_prompt,
|
256 |
outputs=negative_prompt,
|
257 |
-
queue=False,
|
258 |
api_name=False,
|
259 |
)
|
260 |
|
@@ -282,4 +285,5 @@ with gr.Blocks(css="style.css") as demo:
|
|
282 |
)
|
283 |
|
284 |
if __name__ == "__main__":
|
285 |
-
demo.queue(max_size=20).launch()
|
|
|
|
22 |
MAX_SEED = np.iinfo(np.int32).max
|
23 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "1") == "1"
|
24 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
25 |
+
USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
|
26 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
27 |
|
28 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
|
|
96 |
pipe = PixArtAlphaPipeline.from_pretrained(
|
97 |
"PixArt-alpha/PixArt-XL-2-1024-MS",
|
98 |
torch_dtype=torch.float16,
|
99 |
+
variant="fp16",
|
100 |
use_safetensors=True,
|
101 |
)
|
102 |
|
|
|
106 |
pipe.to(device)
|
107 |
print("Loaded on Device!")
|
108 |
|
109 |
+
# speed-up T5
|
110 |
+
pipe.text_encoder.to_bettertransformer()
|
111 |
+
|
112 |
if USE_TORCH_COMPILE:
|
113 |
pipe.transformer = torch.compile(
|
114 |
pipe.transformer, mode="reduce-overhead", fullgraph=True
|
|
|
258 |
fn=lambda x: gr.update(visible=x),
|
259 |
inputs=use_negative_prompt,
|
260 |
outputs=negative_prompt,
|
|
|
261 |
api_name=False,
|
262 |
)
|
263 |
|
|
|
285 |
)
|
286 |
|
287 |
if __name__ == "__main__":
|
288 |
+
# demo.queue(max_size=20).launch()
|
289 |
+
demo.launch(share=True)
|
requirements.txt
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
3 |
gradio==4.1.1
|
4 |
Pillow==10.1.0
|
5 |
-
torch==2.0.1
|
6 |
-
transformers==4.35.0
|
7 |
sentencepiece==0.1.99
|
|
|
|
1 |
+
--index-url https://download.pytorch.org/whl/cu118
|
2 |
+
torch==2.0.1
|
3 |
+
|
4 |
+
diffusers==0.22.1
|
5 |
+
accelerate
|
6 |
+
transformers
|
7 |
gradio==4.1.1
|
8 |
Pillow==10.1.0
|
|
|
|
|
9 |
sentencepiece==0.1.99
|
10 |
+
|