Estimate the floating-point operations of a single attention layer and of the whole model from sequence length, head count and hidden size.
注意力和序列长度平方相关,长序列代价高。
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Attention cost | self attention scales with the square of sequence length times width | Attention Is All You Need |
| Linear cost | feed-forward and projection layers scale with length times width squared | Attention Is All You Need |
| Long sequence trade-off | doubling length quadruples attention cost and dominates runtime | Efficient attention literature |