How can a model remember a long context with a fixed-size state? In this assignment, you will build the forward kernels step by step: start with linear attention, add forgetting and prediction-error correction, then combine your work into chunked Kimi Delta Attention (KDA).
Like Assignment 1, the starter code supplies the GPU plumbing. You implement the masked arithmetic in PyTorch and Triton. Only the forward pass is required.
- Read the overview or open the introduction slides.
- Follow Problems 1–9 in order, reading each PDF before editing its code.
- Implement the
STUDENT IMPLEMENTATION REQUIREDregions and run the checker.
| Problem | Implement | Reading |
|---|---|---|
| P1 | Sequential and chunked linear attention in PyTorch | |
| P2 | Recurrent linear attention in Triton | |
| P3 | Chunked linear attention | |
| P4 | Forgetting: gated linear attention | |
| P5 | Prediction-error correction: DeltaNet | |
| P6 | Chunked DeltaNet and the triangular inverse | |
| P7 | Combine forgetting and correction: Gated DeltaNet | |
| P8 | Recurrent KDA and stable scores | |
| P9 | Assemble the complete chunked KDA forward pass |
Later problems reuse your earlier kernels. In particular, P9 combines the P4 prefix scan, P6 triangular inverse, and P8 score builder. P4 uses a supplied score baseline until you replace it with your P8 implementation.
Use Python 3.10+. P1 runs on CPU, including macOS. P2–P9 require Linux, Triton, and an NVIDIA CUDA GPU.
cd GStar-Assignment-2-KDA
python -m pip install -r requirements.txt
python autograder.py --check-templatesReplace each NotImplementedError or tl.static_assert(False, ...) in the
student regions. Keep the function signatures and region markers intact.
The unfinished starter code is expected to fail numerical checks.
# Start with P1 on CPU.
python autograder.py --p1 --device cpu
# On a CUDA GPU, check each problem as you finish it.
python autograder.py --p2 # use --p3 through --p9 for later problems
# Check the complete assignment, then benchmark KDA after correctness passes.
python autograder.py --all --dtype bfloat16
python autograder.py --p9 --benchmarkThe checker compares outputs and final states against independent references. Its numerical tolerances are provisional; final grading criteria come from the course staff. Use the required Triton kernels and reuse earlier student work; do not call the checker references from your implementations.
For shapes, precision, and kernel conventions, consult the
implementation reference. The formulas omit query
scaling; use scale=1.0 to reproduce the written examples.
Submit problem_1.py through problem_9.py with the explanation comments
requested in each problem. See the
verification and submission guide for details.