README.md 2.88 KB
Newer Older
dcuai's avatar
dcuai committed
1
# stable_diffusion
chenxj's avatar
chenxj committed
2
3
4
5
6
## 论文
[High-Resolution Image Synthesis with Latent Diffusion Models](https://arxiv.org/pdf/2112.10752)
## 模型结构
stable diffusion的核心是latent diffusion model,latent diffusion model结构如下:

chenzk's avatar
chenzk committed
7
![image](https://developer.sourcefind.cn/codes/modelzoo/stable_diffusion_ait/-/raw/master/resources/sd_model.png)
chenxj's avatar
chenxj committed
8
9
10
## 算法原理
根据模型结构,算法原理简要如下:

chenzk's avatar
chenzk committed
11
![image](https://developer.sourcefind.cn/codes/modelzoo/stable_diffusion_ait/-/raw/master/resources/sd_principle.png)
chenxj's avatar
chenxj committed
12
13
14
15
16
## 数据集

## 环境配置
[光源](https://sourcefind.cn/#/service-list)可拉取推理的docker镜像。stable_diffusion_ait推荐的镜像如下:
```
dcuai's avatar
dcuai committed
17
18
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
docker run -d -t -v /opt/hyhal:/opt/hyhal:ro --privileged --device=/dev/kfd --device=/dev/dri/ --network=host --group-add video --name sd-test image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
chenxj's avatar
chenxj committed
19
20
docker exec -it sd-test bash
source /opt/dtk/env.sh
dcuai's avatar
dcuai committed
21
22

pip3 install click timm 
dcuai's avatar
dcuai committed
23
pip3 install diffusers==0.11.1
chenxj's avatar
chenxj committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
```
## 推理
#### 01_resnet-50
```
cd examples/01_resnet-50
```
下载resnet50 weights(https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-rsb-weights/resnet50_a1_0-14fe96d1.pth)

**benchmark**
```
python3 benchmark_ait.py
python3 benchmark_pt.py
```
**infer**
```
python3 infer_with_torch.py
```
#### 02_bert
```
cd examples/02_bert
```
chenzk's avatar
chenzk committed
45
下载[bert-base-uncased](https://huggingface.co/google-bert/bert-base-uncased)
chenxj's avatar
chenxj committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59

**benchmark**
```
python3 benchmark_ait.py
python3 benchmark_pt.py
```
**infer**
```
python3 demo.py
```
#### 03_vit
```
cd examples/03_vit
```
chenzk's avatar
chenzk committed
60
下载[vit_base_patch16_224](https://huggingface.co/google/vit-base-patch16-224)
chenxj's avatar
chenxj committed
61
62
63
64
65
66
67
68
69
70
71
72

**benchmark**
```
python3 benchmark_ait.py
python3 benchmark_pt.py
```
**verification**
```
python3 verification.py
```
#### 04_stable_diffusion

chenzk's avatar
chenzk committed
73
下载[stable-diffusion-2-1-base](https://huggingface.co/stabilityai/stable-diffusion-2-1-base)
chenxj's avatar
chenxj committed
74

chenzk's avatar
chenzk committed
75
下载[clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)
chenxj's avatar
chenxj committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

**compile**
```
cd examples/04_stable_diffusion
python3 scripts/compile.py --local-dir stable-diffusion-2-1-base_path
```
**benchmark**
```
python3 src/benchmark.py --local-dir stable-diffusion-2-1-base_path --clip-dir clip-vit-large-patch14_path --benchmark-pt True
```
**infer**
```
python3 scripts/demo.py --local-dir stable-diffusion-2-1-base_path
python3 scripts/demo_pt.py --local-dir stable-diffusion-2-1-base_path
```
## result
chenzk's avatar
chenzk committed
92
![image](https://developer.sourcefind.cn/codes/modelzoo/stable_diffusion_ait/-/raw/master/resources/example_ait.png)
chenxj's avatar
chenxj committed
93
94
95
96
97
98
99
100
### 精度

## 应用场景
### 算法类别
文生图
### 热点应用行业
艺术设计,游戏开发,电影制作
## 源码仓库及问题反馈
chenzk's avatar
chenzk committed
101
http://developer.sourcefind.cn/codes/modelzoo/stable_diffusion_ait.git
chenxj's avatar
chenxj committed
102
103
104
## 参考资料
https://github.com/ROCm/AITemplate