diff options
| author | jdj <jdj@kunix.org> | 2026-10-29 11:25:11 -0700 |
|---|---|---|
| committer | jdj <jdj@kunix.org> | 2026-10-29 11:25:11 -0700 |
| commit | 72fab81a09083eb858840a21366eace175d01721 (patch) | |
| tree | dea97140c924fb0906fbcb4c1f1a9dac7efb615c /README.md | |
| download | volta-train-kernels-72fab81a09083eb858840a21366eace175d01721.tar.gz volta-train-kernels-72fab81a09083eb858840a21366eace175d01721.zip | |
Volta training kernels with secret/path scanner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..0708172 --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# volta-train-kernels + +Hand-written CUDA and Triton kernels for **training** transformer language +models on NVIDIA Volta (V100, sm_70). + +Modern attention and fusion libraries need Ampere or newer. FlashAttention 2/3 +does not build for sm_70, there is no bf16, and on sm_70 Triton's `tl.dot` lowers +to plain FMA with no tensor cores. On a V100, PyTorch's only training-capable attention +backend is the CUTLASS memory-efficient kernel. These kernels fill that gap. +They were written for the Boris-2 pretraining run on a single V100, and they are +described in the paper *Outrageously Fast Training on Volta*. + +## What is here + +| module | what it does | +|---|---| +| `attn.cu` via `varlen_causal_attention` | Causal attention over packed variable-length documents, head_dim 64, fp16 in/out. Forward and backward run on raw `mma.sync.aligned.m8n8k4` tensor-core instructions (HMMA.884) with fp32 accumulation. Documents are launched longest-first. | +| `canon_rope_bw.py` via `canon_rope_attention` | A Canon depthwise 3-tap convolution, RoPE and the attention above, as one autograd function. The Canon/RoPE part is a bandwidth-bound CUDA kernel. | +| `canon_rope.py` | The Triton reference for Canon+RoPE. The CUDA version is bitwise-identical to it. | +| `head.py` via `fused_lm_loss` | Chunked cross-entropy LM head that never materializes `(N, V)` logits. dW and dx come from fp32-output GEMMs. | +| `integ_ops.py` | Fused residual-add + RMSNorm backward, weight-gradient accumulation straight into fp32 `.grad`, and a tied-embedding gradient. | + +## Requirements + +- An sm_70 GPU (Tesla V100). The kernels may run on later architectures through + PTX JIT, but they are neither tuned nor benchmarked there. +- PyTorch with CUDA and a matching `nvcc`, plus Triton. +- fp16 operands, head_dim 64, and a token stride that is a multiple of 8. Anything else + raises an error. + +The first call compiles with nvcc (about 1 minute) into `$VOLTA_KERNELS_CACHE`, +which defaults to `~/.cache/volta_kernels`. + +## Usage + +```python +import torch +from volta_kernels import varlen_causal_attention + +# q, k, v: (N, H, 64) fp16, N tokens of several documents packed back to back +# offsets: document boundaries, e.g. tensor([0, 700, 764, 765, 2813]) +o = varlen_causal_attention(q, k, v, offsets) # same as causal SDPA per document +o.sum().backward() +``` + +## Precision + +Every kernel keeps the operand dtypes and fp32 accumulation of the stock path it +replaces. The test suite holds each output's error against an fp64 reference +to at most 1.05x the stock path's own error on the same inputs. Document +isolation is exact. dQ uses fp32 atomics, so the attention backward is not +bitwise deterministic run to run (the difference is fp32 summation order only). + +## Tests + +```bash +VK_TEST_DEVICE=cuda:0 python -m unittest discover -s tests -v +``` + +## Results + +Speedups, precision tables and the methodology are in the paper. A link will be +added on publication. + +## License + +MIT |
