Commit 193b49e
Han Wang
perf(dpmodel): stop broadcasting DPA4 so3 linear weights across nodes
Both so3 channel mixers spelled their einsum as a batched matmul with the
NODE/EDGE axis as the matmul BATCH and the weight carrying a dummy leading
axis:
matmul(x[:, :, :, None, :], weight_expanded[None, ...])
matmul broadcasts batch axes, so this expands the weight to
(N, D, F, Cin, Cout). For examples/water/dpa4 that turns a 165K-element
parameter into 191M elements -- about 0.8 GB -- on every call, and autograd
must then reduce the whole expanded gradient back to the parameter shape.
An op-level CUDA profile of a DPA4 training step attributed 45.6 ms per
call to that ExpandBackward0 reduce over a [1152, 9, 1, 32, 576] operand,
three calls per step, making it the most expensive kernel in the run; the
ChannelLinear twin cost a further ~7-9 ms per call over [102510, 1, 32, 64].
The pt backend spells the same contraction as torch.einsum and never
expands the weight.
Batch over the small (D, F) / (F,) axes instead, which keeps N as matmul
ROWS. The weight is then used in place and its gradient is an ordinary
matmul. The transposes this adds touch only the (N, D, F, C) operands,
which are orders of magnitude smaller than the expanded weight.1 parent 01c58e6 commit 193b49e
1 file changed
Lines changed: 24 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
136 | 144 | | |
137 | | - | |
| 145 | + | |
| 146 | + | |
138 | 147 | | |
139 | 148 | | |
140 | 149 | | |
| |||
439 | 448 | | |
440 | 449 | | |
441 | 450 | | |
442 | | - | |
443 | | - | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
444 | 461 | | |
445 | 462 | | |
446 | 463 | | |
447 | | - | |
| 464 | + | |
| 465 | + | |
448 | 466 | | |
449 | 467 | | |
450 | 468 | | |
| |||
0 commit comments