Lyra is an LLM pretraining stack in pure JAX for Google TPUs, covering data preparation, the model, the optimizer, the training loop, and custom Pallas kernels. On a single TPU v6e it trains a 1.6B-parameter MoE at about 34,000 tokens/s, and its kernels run up to 5.27× faster than XLA.
Training stack
The model follows a GPT-OSS-style decoder architecture, combining local and global attention with Mixture-of-Experts (MoE) layers that route each token to 3 of 15 SwiGLU experts plus a shared expert.
The surrounding stack includes a hybrid Muon + Adam optimizer, configurable sharding across devices, resumable checkpoints, training metrics, evaluation, and text generation.
A 500-million-token run of Lyra Small (1.6B parameters, 1.0B active per token) on a single TPU v6e exercised the complete stack before full pretraining. It ran 7,630 updates in 4h 40m end to end at about 34,000 tokens/s (24% MFU), and validation loss fell from 12.62 to 3.06. Diagnostics tracked throughput, gradient norms, and expert routing, which stayed balanced throughout. The run notes include the full training plots, and the checkpoint is on Hugging Face.
Pallas kernels
Custom kernels written in Pallas, JAX’s interface for programming accelerators, optimize attention, linear cross-entropy, and the matrix multiplications used by Mixture-of-Experts layers.
One example is cross-entropy. The fused kernel computes logits and loss in blocks, so it never stores the full matrix of logits for every token across the vocabulary. For 4,096 tokens, the XLA reference allocates about 3.1 GiB of temporaries in the forward pass; the fused kernel uses under 0.1 MiB.
On one TPU v6e at lyra-small shapes (batch=4, seq_len=4096, n_embd=2048), the selected kernels achieve up to 5.27× speedups over matched JAX/XLA reference implementations, alongside substantial reductions in temporary memory:
| Operation | Pallas | XLA | Speedup | Temp. Memory savings |
|---|---|---|---|---|
| Cross-entropy fwd | 5.07 ms | 7.33 ms | 1.45× | >99.9% |
| Cross-entropy fwd + bwd | 21.42 ms | 24.82 ms | 1.16× | >99.9% |
| SW attention fwd | 1.50 ms | 5.97 ms | 3.98× | >99.9% |
| SW attention fwd + bwd | 4.25 ms | 22.40 ms | 5.27× | 98.5% |
| MoE GEMM up | 1.51 ms | 7.26 ms | 4.80× | >99.9% |
| MoE GEMM down | 0.86 ms | 3.24 ms | 3.76× | >99.9% |
The full benchmark report includes the training-step profile, exact shapes, memory measurements, and additional kernels.
Preparing 30 billion tokens
The data preparation pipeline ran in a container on GCP, tokenizing a
30-billion-token slice of a shuffled copy of NVIDIA’s ClimbMix dataset with
o200k_harmony and writing the results as 100 ArrayRecord shards of 300 million
tokens each.
The prepared dataset is published on Hugging Face, so training runs can download ready-to-use shards without repeating the preprocessing step.
What’s next
Building Lyra showed me how much performance depends on details below the model code: where fusion stops, how a multi-step reduction is tiled, when an array is materialized, and how control flow is written. Owning the full stack let me trace each of those from the training loop down to the hardware instruction.
The 500-million-token run tested the stack. The full pretraining run, Lyra Small on about 20 billion tokens, comes next, followed by multi-host and distributed training.
If you work on JAX, Pallas, or TPU training, email me at ibbymlx [at] gmail [dot] com.