Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
pipeline_tag: text-to-image
|
3 |
+
---
|
4 |
+
# stable-diffusion-1.5 optimized for AMD GPU
|
5 |
+
|
6 |
+
|
7 |
+
## Original Model
|
8 |
+
https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
|
9 |
+
|
10 |
+
## _io32/16
|
11 |
+
_io32: model input is fp32, model will convert the input to fp16, perform ops in fp16 and write the final result in fp32
|
12 |
+
|
13 |
+
_io16: model input is fp16, perform ops in fp16 and write the final result in fp16
|
14 |
+
|
15 |
+
## How to Get Started with the Model
|
16 |
+
|
17 |
+
Use the code below to get started with the model.
|
18 |
+
|
19 |
+
With Python using Diffusers OnnxStableDiffusionPipeline
|
20 |
+
|
21 |
+
Required Modules
|
22 |
+
```
|
23 |
+
accelerate
|
24 |
+
numpy==1.26.4 # Due to newer version of numpy changing dtype when multiplying
|
25 |
+
diffusers
|
26 |
+
torch
|
27 |
+
transformers
|
28 |
+
onnxruntime-directml
|
29 |
+
```
|
30 |
+
|
31 |
+
Python Script
|
32 |
+
```
|
33 |
+
import onnxruntime as ort
|
34 |
+
from diffusers import OnnxStableDiffusionPipeline
|
35 |
+
|
36 |
+
model_dir = "D:\\Models\\stable-diffusion-v1-5_io32"
|
37 |
+
|
38 |
+
batch_size = 1
|
39 |
+
num_inference_steps = 30
|
40 |
+
image_size = 512
|
41 |
+
guidance_scale = 7.5
|
42 |
+
prompt = "a beautiful cabin in the mountains of Lake Tahoe"
|
43 |
+
|
44 |
+
ort.set_default_logger_severity(3)
|
45 |
+
|
46 |
+
sess_options = ort.SessionOptions()
|
47 |
+
sess_options.enable_mem_pattern = False
|
48 |
+
|
49 |
+
sess_options.add_free_dimension_override_by_name("unet_sample_batch", batch_size * 2)
|
50 |
+
sess_options.add_free_dimension_override_by_name("unet_sample_channels", 4)
|
51 |
+
sess_options.add_free_dimension_override_by_name("unet_sample_height", image_size // 8)
|
52 |
+
sess_options.add_free_dimension_override_by_name("unet_sample_width", image_size // 8)
|
53 |
+
sess_options.add_free_dimension_override_by_name("unet_time_batch", batch_size)
|
54 |
+
sess_options.add_free_dimension_override_by_name("unet_hidden_batch", batch_size * 2)
|
55 |
+
sess_options.add_free_dimension_override_by_name("unet_hidden_sequence", 77)
|
56 |
+
|
57 |
+
pipeline = OnnxStableDiffusionPipeline.from_pretrained(
|
58 |
+
model_dir, provider="DmlExecutionProvider", sess_options=sess_options
|
59 |
+
)
|
60 |
+
|
61 |
+
result = pipeline(
|
62 |
+
[prompt] * batch_size,
|
63 |
+
num_inference_steps=num_inference_steps,
|
64 |
+
callback=None,
|
65 |
+
height=image_size,
|
66 |
+
width=image_size,
|
67 |
+
guidance_scale=guidance_scale,
|
68 |
+
generator=None
|
69 |
+
)
|
70 |
+
|
71 |
+
output_path = "output.png"
|
72 |
+
result.images[0].save(output_path)
|
73 |
+
|
74 |
+
print(f"Generated {output_path}")
|
75 |
+
```
|
76 |
+
|
77 |
+
### Inference Results
|
78 |
+
|
79 |
+

|
80 |
+
|
81 |
+
|