Commit 9846cfb2 authored by helloyongyang's avatar helloyongyang
Browse files

Merge branch 'main' of github.com:ModelTC/lightx2v into main

parents b794489f e687fe1a
# 注意力机制
# 🎯 Attention Type Configuration in DiT Model
xxx
The DiT model in `LightX2V` currently uses three types of attention mechanisms. Each type of attention can be configured with a specific backend library.
---
## Attention Usage Locations
1. **Self-Attention on the image**
- Configuration key: `self_attn_1_type`
2. **Cross-Attention between image and prompt text**
- Configuration key: `cross_attn_1_type`
3. **Cross-Attention between image and reference image (in I2V mode)**
- Configuration key: `cross_attn_2_type`
---
## 🚀 Supported Attention Backends
| Name | Type Identifier | GitHub Link |
|--------------------|-------------------|-------------|
| Flash Attention 2 | `flash_attn2` | [flash-attention v2](https://github.com/Dao-AILab/flash-attention) |
| Flash Attention 3 | `flash_attn3` | [flash-attention v3](https://github.com/Dao-AILab/flash-attention) |
| Sage Attention 2 | `sage_attn2` | [SageAttention](https://github.com/thu-ml/SageAttention) |
| Radial Attention | `radial_attn` | [Radial Attention](https://github.com/mit-han-lab/radial-attention) |
| Sparge Attention | `sparge_ckpt` | [Sparge Attention](https://github.com/thu-ml/SpargeAttn) |
---
## 🛠️ Configuration Example
In the `wan_i2v.json` configuration file, you can specify the attention types as follows:
```json
{
"self_attn_1_type": "radial_attn",
"cross_attn_1_type": "flash_attn3",
"cross_attn_2_type": "flash_attn3"
}
```
To use other attention backends, simply replace the values with the appropriate type identifiers listed above.
Tip: Due to the limitations of the sparse algorithm's principle, radial_attn can only be used in self-attention.
---
For Sparge Attention like `wan_t2v_sparge.json` configuration file:
Sparge Attention need PostTrain weight path
```json
{
"self_attn_1_type": "flash_attn3",
"cross_attn_1_type": "flash_attn3",
"cross_attn_2_type": "flash_attn3"
"sparge": true,
"sparge_ckpt": "/path/to/sparge_wan2.1_t2v_1.3B.pt"
}
```
---
For further customization or behavior tuning, please refer to the official documentation of the respective attention libraries.
# 注意力机制
# 🎯 DiT 模型中的注意力类型配置说明
xxx
当前 DiT 模型在 `LightX2V` 中三个地方使用到了注意力,每个注意力可以分别配置底层注意力库类型。
---
## 使用注意力的位置
1. **图像的自注意力(Self-Attention)**
- 配置参数:`self_attn_1_type`
2. **图像与提示词(Text)之间的交叉注意力(Cross-Attention)**
- 配置参数:`cross_attn_1_type`
3. **I2V 模式下图像与参考图(Reference)之间的交叉注意力**
- 配置参数:`cross_attn_2_type`
---
## 🚀 支持的注意力库(Backend)
| 名称 | 类型名称 | GitHub 链接 |
|--------------------|------------------|-------------|
| Flash Attention 2 | `flash_attn2` | [flash-attention v2](https://github.com/Dao-AILab/flash-attention) |
| Flash Attention 3 | `flash_attn3` | [flash-attention v3](https://github.com/Dao-AILab/flash-attention) |
| Sage Attention 2 | `sage_attn2` | [SageAttention](https://github.com/thu-ml/SageAttention) |
| Radial Attention | `radial_attn` | [Radial Attention](https://github.com/mit-han-lab/radial-attention) |
| Sparge Attention | `sparge_ckpt` | [Sparge Attention](https://github.com/thu-ml/SpargeAttn) |
---
## 🛠️ 配置示例
`wan_i2v.json` 配置文件中,可以通过如下方式指定使用的注意力类型:
```json
{
"self_attn_1_type": "radial_attn",
"cross_attn_1_type": "flash_attn3",
"cross_attn_2_type": "flash_attn3"
}
```
如需更换为其他类型,只需将对应值替换为上述表格中的类型名称即可。
tips: radial_attn因为稀疏算法原理的限制只能用在self attention
---
对于 Sparge Attention 配置参考 `wan_t2v_sparge.json` 文件:
Sparge Attention是需要后一个训练的权重
```json
{
"self_attn_1_type": "flash_attn3",
"cross_attn_1_type": "flash_attn3",
"cross_attn_2_type": "flash_attn3"
"sparge": true,
"sparge_ckpt": "/path/to/sparge_wan2.1_t2v_1.3B.pt"
}
```
---
如需进一步定制注意力机制的行为,请参考各注意力库的官方文档或实现代码。
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment