Repository navigation
Commit 5ec684f
BoHao Tu
perf(medusa): fuse full-vocabulary CE and bound its memory (#64)
* perf(medusa): fuse full-vocabulary CE and bound its memory
Add a Medusa-specific Triton CE/argmax/dlogits epilogue while keeping the
PyTorch objective as the numerical reference and fallback path.
- Replace per-128-token dW accumulation with one whole-head dW GEMM in the
fast path; retain BF16 logits only within an 8 GiB all-head budget.
- Bound backward dlogits to a 2 GiB full-buffer budget and accumulate dW per
token chunk for longer selections.
- Fail closed for vocabularies above 2^24 where the FP32 tile argmax column
would not be exact, and enable the target device assert.
- Add CPU fallback/2-layer wiring tests and GPU parity/edge tests, including
the chunked backward path and its BF16-accumulation-noise calibration.
- Add tools/performance/bench_medusa_loss.py and document the L20 loss-only
measurement (3.22x vs reference, 1.20x vs whole-head restructure), memory
bounds and explicit non-claims.
Review fixes: bounded dlogits, V > 2^24 fallback, active device assert,
shared retained-logits budget constant, and calibrated chunked-gradient test.
Refs #17
* fix(medusa): address CodeRabbit review findings
- Retain fused logits only when a backward pass can consume them.
- Clear warm-up gradients before the benchmark peak-memory baseline and
refresh the measured memory figures.
- Share the retained-logits budget helper with the benchmark and pin the
K=5 8 GiB boundary.
- Strengthen CPU guard/2-layer/benchmark-reference tests and add GPU
positive-hit coverage.
- Correct the 5.8 GiB unit and the random-target hit-count caveat.
Refs #17
* fix(medusa): harden fused CE numerics and launch bounds
- Keep row_max and log_total separate for NLL/dlogits to avoid FP32
cancellation with large logits.
- Launch Triton kernels under the tensor CUDA device and bound backward
chunks by both row_chunk and the dlogits/scratch byte budgets.
- Capture benchmark peak memory before fingerprint allocations and refresh
the L20 memory table.
- Document the first-maximal argmax tie rule and add large-logit/chunk
coverage.
Refs #17
* test(medusa): cover fused CE on a non-current CUDA device
Run fused forward/backward with the current device at cuda:0 and tensors on
cuda:1, for both retained and recomputed logits. This catches missing
per-device Triton launch contexts on multi-GPU Draft hosts.
Refs #171 parent e1da445 commit 5ec684f
7 files changed
Lines changed: 1573 additions & 21 deletions
File tree
- aspec/models
- ops
- docs/user-guide
- tests
- cpu
- tools/performance
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
18 | 32 | | |
19 | 33 | | |
20 | 34 | | |
21 | 35 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
25 | 39 | | |
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
29 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
30 | 81 | | |
31 | 82 | | |
32 | 83 | | |
| |||
54 | 105 | | |
55 | 106 | | |
56 | 107 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
75 | 140 | | |
76 | 141 | | |
77 | 142 | | |
| |||
0 commit comments