attention.md 1.52 KB
Newer Older
helloyongyang's avatar
helloyongyang committed
1
# Attention Mechanisms
helloyongyang's avatar
helloyongyang committed
2

helloyongyang's avatar
helloyongyang committed
3
## Attention Mechanisms Supported by LightX2V
wangshankun's avatar
wangshankun committed
4

helloyongyang's avatar
helloyongyang committed
5
6
7
8
9
10
11
| Name               | Type Name        | 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) |
wangshankun's avatar
wangshankun committed
12
13
14

---

helloyongyang's avatar
helloyongyang committed
15
## Configuration Examples
wangshankun's avatar
wangshankun committed
16

helloyongyang's avatar
helloyongyang committed
17
The configuration files for attention mechanisms are located [here](https://github.com/ModelTC/lightx2v/tree/main/configs/attentions)
wangshankun's avatar
wangshankun committed
18

helloyongyang's avatar
helloyongyang committed
19
By specifying --config_json to a specific config file, you can test different attention mechanisms.
wangshankun's avatar
wangshankun committed
20

helloyongyang's avatar
helloyongyang committed
21
For example, for radial_attn, the configuration is as follows:
wangshankun's avatar
wangshankun committed
22
23
24
25
26
27
28
29
30

```json
{
  "self_attn_1_type": "radial_attn",
  "cross_attn_1_type": "flash_attn3",
  "cross_attn_2_type": "flash_attn3"
}
```

helloyongyang's avatar
helloyongyang committed
31
To switch to other types, simply replace the corresponding values with the type names from the table above.
wangshankun's avatar
wangshankun committed
32

helloyongyang's avatar
helloyongyang committed
33
Tips: radial_attn can only be used in self attention due to the limitations of its sparse algorithm principle.
wangshankun's avatar
wangshankun committed
34

helloyongyang's avatar
helloyongyang committed
35
For further customization of attention mechanism behavior, please refer to the official documentation or implementation code of each attention library.