Commit ffa3136
committed
[perf]: cache Wan DiT rotary embeddings per (shape, device)
Wan's DiT forward rebuilt rotary embeddings on every call via a
float64 CPU compute (`get_rotary_pos_embed`) + H2D copy of the cos/sin
pair. The inputs — post-patch shape + compute device — are constant
across every step of a single generation, so the precompute happens
once per (shape, device) and is reused for the rest of the denoise
loop (180+ forwards for a 50-step CFG run).
Mirrors the matrixgame2 fix in hao-ai-lab#1415: same hotspot, different model,
same cache-on-self pattern. Composes with hao-ai-lab#1245's fused RoPE Triton
kernel (that PR optimizes each `_apply_rotary_emb` call site; this
one removes the recurring per-forward precompute upstream of it).
Math is identical — first call computes, subsequent calls memoize.
Bit-exact equivalence with the prior path expected.1 parent 5706079 commit ffa3136
1 file changed
Lines changed: 30 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
652 | 669 | | |
653 | 670 | | |
654 | 671 | | |
| |||
0 commit comments