Repository navigation
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
When logits are retained for backward, the forward vocabulary GEMM now writes directly into the retained buffer with torch.mm(hidden, weight.t(), out=...) instead of copying chunk results into it. This removes the chunk-sized temporary and reads the vocabulary weight once per head instead of once per chunk. The recompute path keeps its bounded scratch chunks. The fused epilogue now follows the projection dtype: `_projection_dtype` reports what F.linear actually produces (autocast narrows BF16 inputs to FP16 and never narrows FP64), `use_fused_medusa_ce` and `medusa_head_ce` reject a non-BF16 effective projection, and every retained or recomputed buffer is allocated from the input dtype. Tests cover the autocast fallback and an all -inf row that must stay NaN.
0b80863 to
5ac62bc
Compare
Summary
Finalize the Medusa fused-CE forward path that #64 introduced: when logits are retained for backward, the forward vocabulary GEMM writes directly into the retained buffer with
torch.mm(hidden, weight.t(), out=...)instead ofcopy_(F.linear(...))chunk by chunk.saved_logits; the recompute path keeps its bounded 256 MB scratch chunks._projection_dtype(hidden, weight)reports whatF.linearactually produces: FP64 stays FP64 (autocast never narrows it), autocast narrows FP32 (and BF16 under FP16 autocast) to its dtype, otherwise the operands promote.use_fused_medusa_ceandmedusa_head_cenow require the effective projection dtype to be BF16, and every retained/recomputed buffer is allocated from the input dtype, so forward and backward always read the same precision.-inflogits row keeps NaN in the NLL and the gradient, matchingF.cross_entropy, instead of a silent finite value.Refs #17. Follows #64 and the review conclusions from #71.
Verification
Loss-only A/B on the same host and inputs,
tools/performance/bench_medusa_loss.py --mode both(reference / restructure / fused, 10 warmup, 30 iterations). The dtype-contract commit only touches the Python side of the BF16 path, so it does not change these numbers.referenceandrestructurecells move by less than 0.1% between arms; loss and gradient fingerprints are identical.tests/cpu/test_medusa.py47 passed.tests/test_medusa_loss_kernel_gpu.pywithASPEC_RUN_GPU_INTEGRATION=1on RTX 6000D: 22 passed, 2 skipped. Mutation check: removing the effective-dtype predicate failstest_autocast_dtype_mismatch_falls_back. These GPU results and the benchmark figures are author-run evidence: a diff-based review cannot execute them.Not verified
ok-path performance was measured before the dtype-contract commit; that commit is Python-only and leaves the BF16 path (and its numerics) unchanged.Changes in
aspec/models/ops/medusa_ce.py(verified in diff):_projection_dtype. It returns float64 when an operand is float64, the autocast dtype under autocast, and otherwise the promoted dtype.use_fused_medusa_ceandmedusa_head_cereject a projection dtype other than BF16.medusa_head_cereports the autocast-state requirement in its error.torch.mm(hidden, weight.t(), out=saved_logits)call. The chunked path remains when logits are not saved.hidden.dtypeinstead of hard-coded BF16.Not verified from the diff: the 22-test GPU result, the all-
-infNaN behavior, and the benchmark figures. These are author-reported only.