Beyond the KV cache: Training and serving i14’s Laplace 3B linear attention model on AWS Trainium2 with native PyTorch
Learn how i14 trained and served Laplace 3B, a linear attention model, on AWS Trainium2 using native PyTorch. Its recurrent state stays fixed at 29.5 MB per sequence regardless of context length, avoiding the growing key-value cache of transformer models and keeping serving memory predictable.

Most large language models (LLMs) use transformer architectures with softmax attention. During inference, their key-value (KV) cache grows with the conversation or document context. This can reduce concurrency, increase serving cost, and force agentic applications to discard useful history.
i14 designed Laplace 3B as a linear attention alternative. Its recurrent state stays at 29.5 MB per sequence, independent of context length. Working with AWS, i14 used native PyTorch support through TorchNeuron Native to bring this custom architecture to AWS Trainium2. This preserved its Gated Linear Attention (GLA) design and Muon optimizer.
On one trn2.48xlarge instance, Laplace 3B trained at about 120,000 tokens per second. The model served 11,544 output tokens per second across 1,280 concurrent sequences. This post explains the model design, the changes i14 made for Trainium2, and the training and inference results.
i14 is an AI research and technology company that develops model architectures, components, and runtimes. Its work draws on AI, computational cognitive science, and research into how biological systems learn over time. i14 applies these ideas to models that can retain long-range context without allowing serving state to grow with every token.
Transformer softmax attention compares tokens across the context. During training, this computation grows quadratically with sequence length. During inference, the KV cache grows as the model processes more tokens.
Linear attention reorganizes the computation around a recurrent state that is updated for each token. Laplace 3B uses GLA to compress prior context into a fixed-size matrix state. This changes training attention from O( T 2) to O( T ) and keeps inference state fixed at 29.5 MB per sequence.
Linear attention compresses history rather than retaining every key and value. You must therefore evaluate retrieval quality for your workloads. The fixed state can benefit long-running agents, large-document analysis, and applications that need persistent memory with predictable serving requirements.
The original implementation of Laplace 3B used GPU-optimized Triton kernels. The AWS Generative AI Innovation Center (GenAIIC) team first rewrote the GLA kernel with standard PyTorch operators for Trainium2. After comparing both approaches, the team chose the beta version of TorchNeuron Native, the native PyTorch backend for AWS Trainium, because it performed better.
The implementation required three changes:
The engineering challenges section describes each change in detail.
AWS Trainium is a family of AWS machine learning (ML) accelerators designed for model training and inference. A trn2.48xlarge instance combines 16 Trainium2 chips, 64 logical NeuronCores, high-bandwidth memory, and NeuronLink-v3 connectivity. These resources support the distributed training and inference configurations described in this post.
Three properties of Trainium2 shaped the implementation: software-managed on-chip memory (Challenge 1), a fast chip-to-chip interconnect (Challenge 2), and a static compiler (Challenge 3). The compiler traces the GLA recurrence as a fixed graph.
Software-managed on-chip memory. Each NeuronCore has a 28 MiB State Buffer (SBUF) with 128 partitions and a 2 MiB partial-sum buffer (PSUM). The PSUM is wired to a 128×128 systolic Tensor Engine, alongside separate vector and scalar units. The SBUF is not a cache: the compiler schedules every HBM-to-SBUF transfer ahead of time, so the data is in place with no evictions or misses (Figure 1).
Figure 1: NeuronCore-v3 internal architecture. Software-managed SBUF (28 MiB, 128 partitions), Tensor Engine (128×128 systolic array), Vector Engine, Scalar Engine, and GPSIMD cores.
Laplace 3B is the 24-layer i14 decoder, where every layer replaces softmax attention with Simple GLA. Figure 2 follows one layer from the input x t at the top to the output x t + 1 at the bottom. This section explains each module: normalization and convolution, the QKVG projection, the GLA mixer, and the feed-forward channel mixer.
Normalization and convolution. Each token’s residual-stream vector x t ∈ ℝ D ( D = 3, 072 ) passes through a LayerNorm and a depth-wise causal Conv1d of width k = 4 with SiLU. This gives every position a 4-gram summary before the mixer. The GLA mixer then does content-based retrieval over the whole history through its decaying state.
QKVG projection. The post-conv output goes through one fused matrix W q k v g ∈ ℝ 9, 216 × 3, 072, where 9, 216 = H × (2 d k + 2 d v ). It splits into four per-token streams: queries q t, keys k t, values v t, and a gate g t ( H = 16, d k = 96, d v = 192 ). The gate is used after the mixer.
Figure 2: Laplace decoder layer architecture. Green = fixed (no params), gray = learned, yellow = recurrent state, blue = projection.
GLA mixer. Each head h keeps a matrix state S t ( h ) of size d k × d v (96 × 192), a compressed, decaying record of past key-value pairs. At each token, it updates as:
Decay schedule. The per-head decay rate λ h controls how fast a head forgets past tokens. It is fixed at initialization (not learned) and set by a geometric schedule. The schedule gives the 16 heads a spread of memory lengths and defines each head’s log-decay rate γ h:
Channel mixer (FFN). After the attention block and its residual, a second LayerNorm feeds a GLU (SiLU) FFN with inner dimension 8,192. Its three matrices are two up-projections W 1, W 2 ∈ ℝ 8, 192 × D and one down-projection W 3 ∈ ℝ D × 8, 192. A second residual follows.
The state S ( h ) is fixed at d k × d v = 96 × 192 per head regardless of sequence length. As a result, inference is O (1) per token, and training is O ( T ) rather than O ( T 2 ).
Each of the three changes raised its own engineering challenge.
On GPU, GLA runs as the fused Triton kernel fused_chunk_simple_gla from the flash-linear-attention library. The GenAIIC team re-expressed it with standard PyTorch operators running through TorchNeuron Native, as explicit loops over fixed-size chunks. The chunk count is fixed at compile time and sets the backward-unroll depth. The team uses fla_num_chunks = 16, so each chunk holds C = 128 tokens.
Within each chunk c, the intra-chunk output is masked linear attention, and the running state S adds earlier context:
The state then advances to the next chunk:
Here λ C is the per-head decay compounded over the chunk. The 16 intra-chunk computations run in parallel, and only the state update is sequential (Figure 3).
Figure 3: GLA chunked recurrence with parallel intra-chunk attention and a sequential state chain.
Because the SBUF has 128 partitions, each 128-token chunk maps one token per partition, with no padding or cross-partition movement. This alignment increased measured throughput by 14 percent (Figure 4).
Figure 4: Chunk size C = 128 maps one-to-one onto the 128 SBUF partitions.
Muon orthogonalizes each gradient before the update. For each of the 96 two-dimensional weight matrices (2.718 billion parameters), it runs five Newton–Schulz iterations (Algorithm 1).
The distributed problem. The Gram matrix A = X X ⊤ correlates every row of the weight with every other row. Under Fully Sharded Data Parallel (FSDP2), each of the 64 ranks holds only 1/64 of the rows. A shard-local X X ⊤ therefore yields only a diagonal block and drops every cross-shard term (Figure 5).
Figure 5: Newton–Schulz under FSDP2: the shard-local Gram block, and gather/broadcast compared with all_to_all.
Naive approach: Gather and broadcast. Every rank gathers the full gradient (5.44 GB), one rank runs Newton–Schulz, and it broadcasts the result. This moves 10.87 GB per step while the other 63 ranks wait.
Production approach: all_to_all transposition. In MuonFSDP2, one all_to_all gives each rank a few complete matrices, all 64 ranks run Newton–Schulz in parallel, and a second all_to_all returns the results. Per-rank traffic drops to 0.45 GB, 24 times less. Throughput rises from 73,378 to 119,934 tokens per second, 1.63 times higher, with a bit-identical loss curve (Figure 6).
Figure 6: Per-step communication volume: 10.87 GB with all_gather compared with 0.45 GB with all_to_all.
Communication cost. Newton–Schulz is only about 2 percent of the FLOPs in a training step ( 1.95 × 10 14 of 9.53 × 10 15 ), so communication was the bottleneck. Over NeuronLink-v3 at 1.28 TB/s, the 0.45 GB exchange takes under 0.4 ms of the roughly 4.4-second step.
The backward pass differentiates through all 16 sequential state updates. On GPU, autograd builds this graph at runtime. On Trainium2, the compiler must see the whole unrolled 16-step graph in advance, which creates three constraints.
Graph depth grows with chunk count: at 32 chunks ( C = 64 ), the graph overflowed the scheduler. Per-chunk memory grows with chunk size: at 8 chunks ( C = 256 ), intermediates spilled into HBM. Every shape is fixed at trace time, so each loop intermediate needs its own static allocation.
Sixteen chunks ( C = 128 ) satisfy all three: the unroll fits the scheduler, intermediates stay on chip, and tiles align with the 128 SBUF partitions.
The GenAIIC team trained Laplace 3B on one trn2.48xlarge instance using all 64 logical NeuronCores and the all_to_all Muon path. The full recipe is 190,735 steps (100 billion FineWeb-Edu tokens). The following results are through step 84,210, about 44 billion tokens.
Throughput. After compilation warmup, throughput settles at roughly 120,000 tokens per second and holds there through step 84,210.
Loss and gradient stability. The loss (Figure 7a) drops smoothly from about 11.4 to 2.3729 at step 84,210. The gradient norm (Figure 7b) shows the expected early spike then a steady decline to about 0.05, with no post-warmup spikes, divergence, or NaN/Inf values.
Figure 7: Training dynamics. (a) Loss 11.4 → 2.3729. (b) Gradient norm from TensorBoard data.
Through an unmodified vLLM engine, the GenAIIC team served 11,544 output tokens per second at 1,280 concurrent sequences on one trn2.48xlarge instance.
Constant serving state. The 29.5 MB recurrent state per sequence is roughly 82 times smaller than a comparable KV cache at 8,192 tokens. Increasing the prompt from 2,048 to 8,192 tokens added only 0.5% to the cost per output token.
Unmodified vLLM. A wrapper replaces one attribute per decoder layer, the token mixer, to read and write the recurrent state in the vLLM pool. Because the model declares itself attention-free, vLLM allocates one fixed page per sequence. Outputs matched the i14 reference token for token (48/48 steps on 3/3 prompts in BF16).
Finding the bottleneck. A linear fit of decode time against the number of decoder layers L gives:
Scaling to a full instance. Without tensor parallelism, throughput scales through replicas, with one engine and 20 sequences per logical NeuronCore. Eager throughput grew from 133 output tokens per second on one replica to 6,772 on 64, where host CPU usage reached 82 percent. Compiling the decode step removed per-operator dispatch and raised throughput 1.7 times, to 11,544 (Figure 8).
Figure 8: Whole-instance inference throughput. (a) Replica scaling on eager and compiled decode. (b) Compiled decode lifts throughput from 6,772 to 11,544 output tokens per second.
What fixed-batch benchmarks hide. Under real traffic, each new decode batch width is a separately compiled shape whose first use costs about 11 seconds. These steps were only 1.1 percent of the total but consumed 47.5 percent of decode time. Padding to fixed widths removed this cost with bit-exact results. Compiled decode then improved per-replica throughput 3.52 times under staggered arrivals, compared with 1.46 times on fixed batches. Because BF16 reassociation makes compiled output differ slightly from eager, use eager decode when exact reproducibility matters.
The project produced lessons across both training and inference:
Laplace 3B shows that AWS Trainium2 can support model architectures beyond standard transformers. Using native PyTorch through TorchNeuron Native and the AWS Neuron SDK, i14 trained and served its GLA-based model while preserving a fixed recurrent state.
For agentic systems, this changes a basic serving constraint. Longer histories don’t require a larger per-sequence state, which can help teams retain more context while keeping memory use predictable.
If growing context is increasing serving cost, reducing concurrency, or limiting agent memory, try i14 or contact your AWS account team to evaluate Laplace 3B on AWS Trainium2.
Kevin is VP of AI Research at i14, where he researches different model architectures. His work centers on applying insights from cognitive science and computational neuroscience to develop more efficient large language models.
Massimo is CTO of i14.ai, an AI research startup. He has led engineering teams at Amazon Web Services, Microsoft, and startups in AI, neurotechnology, and entertainment. He also creates interactive art installations featured at festivals worldwide.
Iman is an Applied Scientist at AWS, working with customers to design, develop, and deploy generative AI solutions. His work bridges AI research and practical applications, with a focus on large language models, agentic AI systems, model fine-tuning, and performance optimization to build reliable, efficient, and cost-effective AI solutions on AWS.
Xiaodong is a Machine Learning Engineer at AWS who focuses on generative AI, large language models, and machine learning performance optimization. His work covers efficient training and inference on AWS purpose-built machine learning accelerators, including AWS Trainium.
Daniel is a Solutions Architect at AWS focused on AI and SaaS startups. As a former startup CTO, he works with founders and engineering leaders to build and grow on AWS. Outside work, Daniel enjoys walking with a coffee, spending time in nature, and learning new ideas.