Spaces:
Runtime error
Runtime error
Commit
•
79e814b
1
Parent(s):
d7ee290
commit
Browse filesFormer-commit-id: 8af21e8704b199f29ac59d82fe37d872de3c90e0 [formerly 8af21e8704b199f29ac59d82fe37d872de3c90e0 [formerly 8af21e8704b199f29ac59d82fe37d872de3c90e0 [formerly 8af21e8704b199f29ac59d82fe37d872de3c90e0 [formerly 8af21e8704b199f29ac59d82fe37d872de3c90e0 [formerly 1ad46af96222172330ca4a1361e94228cdc385a4]]]]]
Former-commit-id: 6914280c2386f422e333da5824527c519b05d9cc
Former-commit-id: d92a847a71cb6fc030979214cc75245e9d1cb45f
Former-commit-id: 4634f78eea39a6e99f7d62cf24f83ad544283214
Former-commit-id: 72ed2e43abdee7b50825ea7ac4701534f4ffca66
Former-commit-id: 30e20bd953f168881ba2371ee110eb6db5178169
Former-commit-id: df75e1f7a56254eb9f84a028fdf35d49a185e8e8
Former-commit-id: b00c8eaeb479754fcbd396338af147a84bc91b9f
api/routers/sdxl_text_to_image.py
CHANGED
@@ -1,13 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import config
|
2 |
from fastapi import APIRouter, HTTPException
|
3 |
from typing import List
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
from functools import lru_cache
|
|
|
7 |
from scripts.api_utils import accelerator
|
8 |
from models.sdxl_input import InputFormat
|
9 |
from async_batcher.batcher import AsyncBatcher
|
10 |
from scripts.api_utils import pil_to_b64_json, pil_to_s3_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
torch._inductor.config.conv_1x1_as_mm = True
|
12 |
torch._inductor.config.coordinate_descent_tuning = True
|
13 |
torch._inductor.config.epilogue_fusion = False
|
@@ -20,10 +34,38 @@ device = accelerator()
|
|
20 |
router = APIRouter()
|
21 |
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
|
25 |
# Load the diffusion pipeline
|
26 |
@lru_cache(maxsize=1)
|
|
|
27 |
def load_pipeline(model_name, adapter_name,enable_compile:bool):
|
28 |
"""
|
29 |
Load the diffusion pipeline with the specified model and adapter names.
|
@@ -43,6 +85,19 @@ def load_pipeline(model_name, adapter_name,enable_compile:bool):
|
|
43 |
if enable_compile is True:
|
44 |
pipe.unet = torch.compile(pipe.unet, mode="max-autotune")
|
45 |
pipe.vae.decode = torch.compile(pipe.vae.decode, mode="max-autotune")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
pipe.fuse_qkv_projections()
|
47 |
return pipe
|
48 |
|
|
|
1 |
+
<<<<<<< HEAD:api/routers/sdxl_text_to_image.py
|
2 |
+
=======
|
3 |
+
import sys
|
4 |
+
sys.path.append("../scripts") # Path of the scripts directory
|
5 |
+
>>>>>>> 846a4a3 (commit):product_diffusion_api/routers/sdxl_text_to_image.py
|
6 |
import config
|
7 |
from fastapi import APIRouter, HTTPException
|
8 |
from typing import List
|
9 |
from diffusers import DiffusionPipeline
|
10 |
import torch
|
11 |
from functools import lru_cache
|
12 |
+
<<<<<<< HEAD:api/routers/sdxl_text_to_image.py
|
13 |
from scripts.api_utils import accelerator
|
14 |
from models.sdxl_input import InputFormat
|
15 |
from async_batcher.batcher import AsyncBatcher
|
16 |
from scripts.api_utils import pil_to_b64_json, pil_to_s3_json
|
17 |
+
=======
|
18 |
+
from s3_manager import S3ManagerService
|
19 |
+
from PIL import Image
|
20 |
+
import io
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
>>>>>>> 846a4a3 (commit):product_diffusion_api/routers/sdxl_text_to_image.py
|
25 |
torch._inductor.config.conv_1x1_as_mm = True
|
26 |
torch._inductor.config.coordinate_descent_tuning = True
|
27 |
torch._inductor.config.epilogue_fusion = False
|
|
|
34 |
router = APIRouter()
|
35 |
|
36 |
|
37 |
+
<<<<<<< HEAD:api/routers/sdxl_text_to_image.py
|
38 |
+
=======
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
def pil_to_b64_json(image):
|
43 |
+
image_id = str(uuid.uuid4())
|
44 |
+
buffered = BytesIO()
|
45 |
+
image.save(buffered, format="PNG")
|
46 |
+
b64_image = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
47 |
+
return {"image_id": image_id, "b64_image": b64_image}
|
48 |
+
|
49 |
+
|
50 |
+
def pil_to_s3_json(image: Image.Image,file_name) -> str:
|
51 |
+
image_id = str(uuid.uuid4())
|
52 |
+
s3_uploader = S3ManagerService()
|
53 |
+
image_bytes = io.BytesIO()
|
54 |
+
image.save(image_bytes, format="PNG")
|
55 |
+
image_bytes.seek(0)
|
56 |
+
|
57 |
+
unique_file_name = s3_uploader.generate_unique_file_name(file_name)
|
58 |
+
s3_uploader.upload_file(image_bytes, unique_file_name)
|
59 |
+
signed_url = s3_uploader.generate_signed_url(
|
60 |
+
unique_file_name, exp=43200
|
61 |
+
) # 12 hours
|
62 |
+
return {"image_id": image_id, "url": signed_url}
|
63 |
+
>>>>>>> 846a4a3 (commit):product_diffusion_api/routers/sdxl_text_to_image.py
|
64 |
|
65 |
|
66 |
# Load the diffusion pipeline
|
67 |
@lru_cache(maxsize=1)
|
68 |
+
<<<<<<< HEAD:api/routers/sdxl_text_to_image.py
|
69 |
def load_pipeline(model_name, adapter_name,enable_compile:bool):
|
70 |
"""
|
71 |
Load the diffusion pipeline with the specified model and adapter names.
|
|
|
85 |
if enable_compile is True:
|
86 |
pipe.unet = torch.compile(pipe.unet, mode="max-autotune")
|
87 |
pipe.vae.decode = torch.compile(pipe.vae.decode, mode="max-autotune")
|
88 |
+
=======
|
89 |
+
def load_pipeline(model_name, adapter_name,adapter_name_2):
|
90 |
+
pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype= torch.bfloat16 ).to(
|
91 |
+
"cuda"
|
92 |
+
)
|
93 |
+
pipe.load_lora_weights(adapter_name)
|
94 |
+
pipe.load_lora_weights(adapter_name_2)
|
95 |
+
pipe.set_adapters([adapter_name, adapter_name_2], adapter_weights=[0.7, 0.5])
|
96 |
+
pipe.fuse_lora()
|
97 |
+
pipe.unload_lora_weights()
|
98 |
+
pipe.unet.to(memory_format=torch.channels_last)
|
99 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead")
|
100 |
+
>>>>>>> 846a4a3 (commit):product_diffusion_api/routers/sdxl_text_to_image.py
|
101 |
pipe.fuse_qkv_projections()
|
102 |
return pipe
|
103 |
|
scripts/output/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: creativeml-openrail-m
|
3 |
+
library_name: diffusers
|
4 |
+
tags:
|
5 |
+
- stable-diffusion-xl
|
6 |
+
- stable-diffusion-xl-diffusers
|
7 |
+
- text-to-image
|
8 |
+
- diffusers
|
9 |
+
- diffusers-training
|
10 |
+
base_model: stabilityai/stable-diffusion-xl-base-1.0
|
11 |
+
inference: true
|
12 |
+
---
|
13 |
+
|
14 |
+
<!-- This model card has been generated automatically according to the information the training script had access to. You
|
15 |
+
should probably proofread and complete it, then remove this comment. -->
|
16 |
+
|
17 |
+
SDXL Product Images
|
18 |
+
|
19 |
+
## Intended uses & limitations
|
20 |
+
|
21 |
+
#### How to use
|
22 |
+
|
23 |
+
```python
|
24 |
+
# TODO: add an example code snippet for running this diffusion pipeline
|
25 |
+
```
|
26 |
+
|
27 |
+
#### Limitations and bias
|
28 |
+
|
29 |
+
[TODO: provide examples of latent issues and potential remediations]
|
30 |
+
|
31 |
+
## Training details
|
32 |
+
|
33 |
+
[TODO: describe the data used to train the model]
|
scripts/output/pytorch_lora_weights.safetensors.REMOVED.git-id
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
55f1b147723f81304a3217185314d068b6d49439
|