This repository holds Cake training kernels for NVIDIA Blackwell GPUs (SM100, SM103 and SM107). Most families provide a forward, a backward and an autograd entry point. There are 24 kernel families, and each one is a separate pip distribution. You can pin, upgrade or roll back one family without changing the others.
All modules live under cake_pplx.. {det,nondet} means that both a deterministic module and a non-deterministic module exist.
| Family | Distribution | Public modules | Computes | API |
|---|---|---|---|---|
| rmsnorm | cake-pplx-rmsnorm |
cake_rmsnorm_{det,nondet}_train |
Fused BF16 RMSNorm, optional fused residual add | API |
| rmsnorm_silu_gate | cake-pplx-rmsnorm-silu-gate |
cake_rmsnorm_silu_gate_{det,nondet}_train |
RMSNorm(x) * weight * SiLU(z) over a last dim of 128 | API |
| causal_conv1d | cake-pplx-causal-conv1d |
cake_causal_conv1d_{det,nondet}_train[_kcp] |
Packed width-4 depthwise causal conv + SiLU | API |
| kda | cake-pplx-kda |
cake_kda_{det,nondet}_train[_kcp] |
Kimi Delta Attention chunked training | API |
| gdn | cake-pplx-gdn |
cake_gdn_{det,nondet}_train[_kcp] |
Gated DeltaNet chunked gated delta rule | API |
| mhc | cake-pplx-mhc |
cake_mhc_{det,nondet}_train |
Four-stream mHC hyper-connection layer | API |
| mhc_head | cake-pplx-mhc-head |
cake_mhc_head_{det,nondet}_train |
Stream mean at the mHC model head | API |
| engram_gate | cake-pplx-engram-gate |
cake_engram_gate_{det,nondet}_train |
Four-stream Engram context gate, width 5120 | API |
| attn_res | cake-pplx-attn-res |
cake_attn_res_{det,nondet}_train |
Attention residuals: softmax-weighted sum of 1 to 9 BF16 values, width 7168 | API |
| gqa | cake-pplx-gqa |
cake_gqa_{det,nondet}_train |
Packed-varlen causal GQA attention, head dim 256 | API |
| fmha | cake-pplx-fmha |
cake_fmha_{det,nondet}_train |
Dense multi-head attention, head dim 64/128 (backward only) | API |
| gated_kv_compression | cake-pplx-gated-kv-compression |
cake_gated_kv_compression_det_train |
Ratio-2 gated KV compression: per-document token-pair softmax pooling, width 512 | API |
| dsa_indexer | cake-pplx-dsa-indexer |
cake_dsa_indexer_{det,nondet}_train |
DSA indexer scores + exact top-k (forward only) | API |
| dsa_sparse_attention | cake-pplx-dsa-sparse-attention |
cake_dsa_sparse_attention_{det,nondet}_train |
Top-k sparse MLA attention: rope forms 64, 96 or 128 heads (96/128 run a single-pass forward and a head-window backward, det and nondet, on sm_100a/sm_103a/sm_107a), NoPE form 64 heads | API |
| dense_gemm | cake-pplx-dense-gemm |
cake_dense_gemm_{det,nondet}_train |
BF16 projection GEMM, FP32 router GEMM | API |
| moe_grouped_gemm | cake-pplx-moe-grouped-gemm |
cake_moe_grouped_gemm_{det,nondet}_train |
Ragged BF16 MoE grouped GEMM | API |
| gated_act_mxfp8 | cake-pplx-gated-act-mxfp8 |
cake_gated_act_mxfp8_det_train |
Fused SwiGLU + MXFP8 quantization | API |
| clamped_swiglu | cake-pplx-clamped-swiglu |
cake_clamped_swiglu_det_train |
Routed-expert clamped SwiGLU, FP32 route weight before the one BF16 rounding (I = 2304) | API |
| situ_glu | cake-pplx-situ-glu |
cake_situ_glu_det_train |
SiTU-GLU of an MLP, FP32 math and one BF16 rounding (I a multiple of 256: 3072, 6144, 33,792), with a fused checkpoint backward | API |
| engram_lookup | cake-pplx-engram-lookup |
cake_engram_lookup_det_train |
Engram row lookup: FP8 E4M3 rows with E8M0 scales to BF16 (forward only) | API |
| mok | cake-pplx-mok |
cake_mok_det_train |
Expert-parallel MoE layer training (BF16 or MXFP8 routed experts) | API |
| lm_head | cake-pplx-lm-head |
cake_lm_head_{det,nondet}_train |
Chunked LM-head loss, log-probs and support KL | API |
| act_qdq | cake-pplx-act-qdq |
cake_act_qdq_det_train |
FP4 / MXFP4 / MXFP8 quantize-dequantize of BF16 activations (forward only) | API |
| route_weight_scale | cake-pplx-route-weight-scale |
cake_route_weight_scale_det_train |
Routed-expert row scaling by the FP32 route weight, with the FP32 row-dot dw (H = 4096, 3584) |
API |
Each family's source is in kernels/<family>/. Distribution names use hyphens, and the subdirectory names use underscores. pip treats - and _ in distribution names as the same character.
To install one family pinned to a commit:
pip install "cake-pplx-kda @ git+https://github.com/perplexityai/cake-pplx-collab@<sha>#subdirectory=kernels/kda"In requirements.txt, give each family its own line. In this example the two families come from different commits:
cake-pplx-kda @ git+https://github.com/perplexityai/cake-pplx-collab@<sha-a>#subdirectory=kernels/kda
cake-pplx-rmsnorm @ git+https://github.com/perplexityai/cake-pplx-collab@<sha-b>#subdirectory=kernels/rmsnorm
To upgrade or downgrade one family, change the SHA on its line. The other families stay as they are.
All families install into one namespace package, cake_pplx (PEP 420). Neither cake_pplx/ nor cake_pplx/_backends/ contains an __init__.py, so each distribution only adds its own modules. Several families can be installed side by side, each from a different commit.
Each family has its own version in kernels/<family>/VERSION. Per-family release tags of the form <family>/vX.Y.Z are planned but do not exist yet. Until they do, pin by commit SHA.
import torch
from cake_pplx.cake_rmsnorm_det_train import cake_rmsnorm_det
x = torch.randn(129, 4096, device="cuda", dtype=torch.bfloat16, requires_grad=True)
w = torch.randn(4096, device="cuda", dtype=torch.bfloat16, requires_grad=True)
y = cake_rmsnorm_det(x, w, 1e-6) # BF16 [129, 4096]
y.backward(torch.randn_like(y)) # x.grad BF16, w.grad in w.dtypeThe first call compiles the kernels (see JIT build and cache). Each family section in docs/API.md includes a fuller example.
Import each module by its full name: the cake_pplx namespace does not re-export anything.
| Item | Requirement |
|---|---|
| GPU | Compute capability 10.0, 10.3 or 10.7 (sm_100a, sm_103a, sm_107a). Some families limit shapes per architecture; see docs/API.md. |
| CUDA toolkit | nvcc must be available at run time, because kernels compile on first use. Each library in build.json sets its own minimum: 12.8 for sm_100a (12.9 for act_qdq, lm_head and for some dsa_sparse_attention, gated_kv_compression, kda and rmsnorm_silu_gate libraries), 12.9 for sm_103a and 13.4 for sm_107a (13.5 for act_qdq, attn_res, causal_conv1d, clamped_swiglu, dense_gemm, dsa_indexer, dsa_sparse_attention, engram_gate, engram_lookup, fmha, gated_kv_compression, gdn, gqa, kda, lm_head, mhc, mhc_head, moe_grouped_gemm, mok, rmsnorm, rmsnorm_silu_gate, route_weight_scale and situ_glu). Some moe_grouped_gemm libraries (its FP32 accumulate builds) need 13.4 on sm_100a and sm_103a too. An older toolkit raises RuntimeError when that library is built; on those two architectures below 13.4, a moe_grouped_gemm FP32 accumulate call takes its composed route instead. |
torch |
Required by every family. |
apache-tvm-ffi |
>=0.1.11,<0.2, required by every family. |
ninja |
moe_grouped_gemm only. |
cuda-python |
causal_conv1d, dense_gemm, rmsnorm_silu_gate, and the locality="domain" paths of act_qdq and clamped_swiglu (cuda-bindings 13.5 or later: the locality extra of each). |
torch.distributed with symmetric memory |
mok only: an initialized process group whose ranks share one NVLink domain with multicast. |
Kernels are compiled just in time (JIT) with nvcc on first use. The build reads each backend's build.json and compiles for exactly the arch flags in that manifest. Compiled libraries are cached under a key that is a digest of the sources, the flags and the CUDA version, so switching commits never reuses a stale library.
| Variable | Effect |
|---|---|
CAKE_PPLX_CACHE_DIR |
Library cache directory. Default: ~/.cache/cake_pplx. |
CAKE_PPLX_NVCC |
Path of the nvcc that compiles. Default: <toolkit root>/bin/nvcc, with the root from the next row. The CUDA version check and the cache key still use <toolkit root>/bin/nvcc, so point both at the same toolkit. |
CUDA_HOME / CUDA_PATH |
CUDA toolkit root. Otherwise nvcc on PATH, or /usr/local/cuda. |
CXX |
Host compiler. Default: c++. |
CAKE_PPLX_JIT_WORKERS |
Number of parallel compile jobs. Default: min(8, cpu_count). |
CAKE_PPLX_DISABLE_JIT |
Disables JIT. Only prebuilt aot/ libraries load, and a missing library raises RuntimeError. |
Any non-empty value of CAKE_PPLX_DISABLE_JIT, including 0, disables the JIT. Exception: moe_grouped_gemm also builds a small queue-split probe with tvm_ffi.cpp.load_inline (needs ninja and nvcc), outside build.json and these variables. If that build fails, the kernel uses the even split and the output bits do not change.
Before you capture a CUDA graph, run one eager call so that no JIT build happens during capture.
The KCP (context-parallel) route of causal_conv1d uses the KCP context object that kda or gdn creates. The causal_conv1d distribution does not declare kda or gdn as a dependency, so you need to install both families yourself:
- Pin causal_conv1d and kda (or gdn) to compatible commits. The tested combination is listed in the pull requests.
- A protocol version check (
KCP_CONTEXT_PROTOCOL) is planned but not implemented yet. Today the contract is duck-typed. - Cross-family tests are in
tests/cross_family/<family>/. That directory has the same layout askernels/<family>/(tests/andbenchmarks/).
| Item | State |
|---|---|
| Validated | NVIDIA GB300 (sm_103a), driver 580.159.03, CUDA 13.4.92, torch 2.14.1+cu130, apache-tvm-ffi 0.1.15 |
| Supported by the code, not yet validated here | sm_100a, sm_107a |
| fmha, causal_conv1d, mhc, mhc_head, mok, rmsnorm | Validated on NVIDIA GB200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| engram_lookup | Validated on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| act_qdq | Validated on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| clamped_swiglu | Validated on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| situ_glu | Validated on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| dsa_sparse_attention | Validated on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| kda | Validated on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) |
| gated_kv_compression | GPU suites and benchmark run on NVIDIA B200 (sm_100a), GB300 (sm_103a) and VR200 (sm_107a) with CUDA 13.5, against the acceptance criteria of issue #76 |
| attn_res | GPU suites and the benchmark run on NVIDIA B200 and GB200 (sm_100a), GB300 (sm_103a), VR200 and R200 (sm_107a), with CUDA 13.5, against the acceptance criteria of issue #262. compute-sanitizer passes on GB300 at 0.1.3 for every backward program, on kernel-level builds of the same sources; the forwards are 0.1.2's, which passed on GB300 and, for those of 5 to 9 values, on VR200 |
| Not run | Tests that need more than 4 GPUs |
| Release tags | Planned, not created yet |
ARCHITECTURE.md describes the repository layout, the isolation rules, the CI, how to run the tests and the release procedure.
To run a family's tests, first install the family with its test extra. Then copy its tests, benchmarks (if the family has one; mok has none) and pyproject.toml to a directory outside the source tree, and run pytest there:
# from the repository root
pip install "./kernels/kda[test]"
mkdir -p /tmp/kda-tests
cp -r kernels/kda/tests kernels/kda/benchmarks kernels/kda/pyproject.toml /tmp/kda-tests/
cd /tmp/kda-tests && python -m pytest -p no:cacheprovider testsThe "Running tests" section of ARCHITECTURE.md has the details. CI runs the whole suite of each changed family on a CPU runner, where GPU tests are skipped.