README.md 2.99 KB
Newer Older
lijian6's avatar
lijian6 committed
1
2
3
4
5
6
7
8
9
10
11
12
# HunyuanDiT

## 论文

**Hunyuan-DiT : A Powerful Multi-Resolution Diffusion Transformer with Fine-Grained Chinese Understanding**

* https://arxiv.org/pdf/2405.08748

## 模型结构

模型基于`transformer decoder`结构,在`DiT`基础上重新设计了`Time Embedding`以及`positional Embedding`的添加方式,`Text Prompt`通过两个`text encoder`进行编码,其余与DiT一致。

lijian6's avatar
lijian6 committed
13
![alt text](docs/model_structure.png)
lijian6's avatar
lijian6 committed
14
15
16
17
18


## 算法原理
使用`self-attention`捕获图像内部的结构信息,使用`cross attention`对齐文本与图像。

lijian6's avatar
lijian6 committed
19
![alt text](docs/alg.png)
lijian6's avatar
lijian6 committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


## 环境配置

### Docker(方法一)
    
    docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10

    docker run --shm-size 10g --network=host --name=hunyuan --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

### Dockerfile(方法二)

    docker build -t <IMAGE_NAME>:<TAG> .

    docker run --shm-size 10g --network=host --name=hunyuan --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it <your IMAGE ID> bash

lijian6's avatar
lijian6 committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
### Conda(方式三)
1. 创建conda虚拟环境:
```
conda create -n hunyuan python=3.10
```

2. 关于本项目DCU显卡所需的工具包、深度学习库等均可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。
- [DTK 24.04.1](https://cancon.hpccube.com:65024/1/main/DTK-24.04.1)
- [Pytorch 2.1.0](https://cancon.hpccube.com:65024/directlink/4/pytorch/DAS1.1/torch-2.1.0+das1.1.git3ac1bdd.abi1.dtk2404-cp310-cp310-manylinux_2_31_x86_64.whl)

    Tips:以上dtk驱动、python等工具版本需要严格一一对应。

3. 其它依赖库参照requirements.txt安装:
```
pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
```

lijian6's avatar
lijian6 committed
53
### 拉取代码并安装依赖
lijian6's avatar
lijian6 committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

```
git clone https://developer.hpccube.com/codes/modelzoo/hunyuandit_diffusers.git
cd hunyuandit_diffusers
git submodule init && git submodule update

1. 卸载apex
pip uninstall apex
2. 安装diffusers
cd diffusers
python3 setup.py install
cd ..

```

lijian6's avatar
lijian6 committed
69
70
71
72
73
74
## 数据集



## 推理

lijian6's avatar
lijian6 committed
75
76
### 模型下载

lijian6's avatar
lijian6 committed
77
模型快速下载中心:[AIModels](http://113.200.138.88:18080/aimodels), 本项目模型链接:[HunyuanDiT](http://113.200.138.88:18080/aimodels/HunyuanDiT)
lijian6's avatar
lijian6 committed
78
79
80
81

### 运行

    python SD-HunyuanDit.py
lijian6's avatar
lijian6 committed
82
83
### 注意事项
    如果代码里要使用xformers fa,需要此加上'export HY_USE_XFORMERS=1'
lijian6's avatar
lijian6 committed
84
85
86
87
88
89
90
91
92
93
94
95
96

## result

![img](./docs/result.png)

### 精度



## 应用场景

### 算法类别

lijian6's avatar
lijian6 committed
97
`以文生图`
lijian6's avatar
lijian6 committed
98
99
100
101
102
103
104
105
106
107
108
109

### 热点应用行业

`零售,广媒,电商`

## 源码仓库及问题反馈

* https://developer.hpccube.com/codes/modelzoo/hunyuandit_diffusers

## 参考资料

* https://hf-mirror.com/Tencent-Hunyuan/HunyuanDiT-Diffusers