{"slug": "testing-llm-architectures-part-1-memory-and-speed", "title": "Testing LLM Architectures, Part 1: Memory and Speed", "summary": "A benchmark of thirteen open-weight models on an RTX 4060 with 8 GB of VRAM and 32 GB of RAM running llama.cpp found that dense models store between 112 and 144 KiB of KV cache per token, while most other architecture groups store much less and often add a fixed cache component that does not grow with context. The study measured memory placement and speed as context scaled from 1K to 128K tokens, with llama.cpp moving 2 of gpt-oss-20b's 25 layers to RAM at 128K and 18 of GLM-4.7-Flash's 48 layers, forcing GLM-4.7-Flash to run at 64K where all layers stay on the GPU. Speed runs used greedy decoding with thinking off, 128-token answers and prompt caching disabled, and the three runs per prompt differed by at most 8.4%.", "body_md": "How much memory thirteen open-weight models need, and how fast they read and write as the context grows from 1K to 128K tokens.\n\nThe previous article, [Inside the Architectures](https://medium.com/towards-artificial-intelligence/inside-the-architectures-of-open-source-llms-attention-moe-hybrid-layers-and-quantization-28df54739076), described the architectures of the models in this series and how a model writes an answer: the server reserves the KV cache in VRAM, prefill reads the prompt in batches and is limited by computation, and decode writes one token at a time and is limited by memory. It ended with what each architecture should do as the context grows. This series tests those expectations on the same machine, an RTX 4060 with 8 GB of VRAM and 32 GB of RAM, running llama.cpp. Memory totals are in GB, units of 1⁰⁹ bytes, the same unit as memory bandwidth. The VRAM, sold as 8 GB, holds 8 GiB, in units of 1,02⁴³ bytes, which makes 8.6 GB.\n\nThe models are grouped by architecture in the table below. Every later table uses the same groups in the same order, and within each group the models are listed from the fewest to the most parameters.\n\nThe tests are split into four studies, one per part: Part 1 measures memory and speed, Part 2 the cost of reasoning, Part 3 quantization, and Part 4 long context.\n\nStudy A looks at the cost of context: how much memory each model needs, how fast it runs, and how each architecture changes both as the context grows from 1K to 128K tokens.\n\nStudy A runs in two steps. The first step measures memory. Each model was started with -c, the context size reserved at startup, at values from 4K to 128K, and at each size the test recorded where llama.cpp placed the weights, how large the KV cache was, and whether anything spilled into shared GPU memory. llama.cpp can also move whole layers to RAM without spilling. At 128K, it moved 2 of the 25 layers of gpt-oss-20b, which was kept at that size, and 18 of the 48 layers of GLM-4.7-Flash, which therefore ran at 64K, where all its layers stay on the GPU. The second step measures speed. Each model ran at the largest -c that fit in VRAM, with prompts of filler text from 1K tokens up to that size. Each prompt asked for 128 tokens of answer and ran three times, and the three runs differed by at most 8.4%. Prompt caching was disabled, so every request read its whole prompt from the start. All runs used greedy decoding with thinking off, and gpt-oss, which always thinks, ran at low effort.\n\nThe KV cache of every model whose layout gives the terms of the formula grows exactly as the formula from the previous post predicts. The formula multiplies 2, for keys and values, by the layers that keep a cache, the key/value heads, the size of each head and the bytes per value. Most models store 2 bytes per value. Bonsai stores its cache in 8 bits, which takes 1.06 bytes per value once the scale of each block of 32 values is counted. In models with local layers, the formula counts only the global ones, since only these grow with the context. GLM-4.7-Flash uses Multi-head Latent Attention, which stores one compressed vector per layer in place of keys and values, so its prediction uses the formula of the previous post for this method: the layers times the size of the vector, 512 values plus 64 for the position, times the bytes per value. Sizes per token are in KiB (1,024 bytes) and fixed parts in MiB (1,02⁴² bytes), the units llama.cpp reports.\n\nThe dense models store between 112 and 144 KiB per token, and they differ only through the terms of the formula.\n\nMost other groups store much less per token, and many of them add a fixed part to the cache, memory reserved once at startup that does not grow with the context.\n\nIn the models with sliding-window layers, the fixed part is the cache of those layers, since each one keeps only its last window of tokens. The sliding-window model, Gemma 3 4B, has 29 such layers, each holding a window of 1,024 tokens plus room for one batch of 512, which adds up to 174 MiB. Only its 5 global layers grow with the context, so it stores 20 KiB per token, seven times less than Qwen3-VL 4B, a dense model of similar size.\n\nThe latent-attention MoE, GLM-4.7-Flash, compresses each token to 576 values per layer, against the 10,240 that its 20 heads of keys and values would take, but it keeps this vector in all 47 layers. It therefore stores 53 KiB per token, close to Qwen2.5 7B, the dense model with the smallest cache, and has no fixed part.\n\nIn the hybrid MoE models, the fixed part is the recurrent state, a matrix of constant size in each recurrent layer, and only the few attention layers grow. Nemotron 3 Nano Omni, with 6 attention layers, stores 6 KiB per token, twenty times less than Llama 3.1 8B.\n\nThe convolution hybrid, LFM3 1.7B, has both kinds of fixed part. Its 5 sliding-window layers keep windows of 256 tokens plus one batch, which take 7.5 MiB, and its 13 convolutions keep only their last 6 tokens, which take 0.6 MiB. Only its 6 global layers grow, at 12 KiB per token.\n\nThe ternary model, Bonsai, also has a recurrent state, of 150 MiB, and its cache matches exactly 16 attention layers. llama.cpp creates this state only for recurrent layers, so Bonsai is a dense hybrid: ternary weights, a dense FFN and three recurrent layers for each attention layer, the same layout as the recent Qwen models from which it was derived.\n\nAt 128K tokens, the dense models trained for that length would need between 15 and 19 GB of cache, about twice the VRAM. Every other model needs between 0.8 and 4.6 GB, except GLM-4.7-Flash, whose compressed cache in every layer still needs 7.1 GB.\n\nThe weights are the other part of the memory, and their placement differs most between the groups. For each model, the table shows the largest -c that fit entirely in VRAM, the weights and the cache that filled the VRAM at that size, and the weights llama.cpp placed in RAM.\n\nThe dense models keep almost all their weights in VRAM, with only the embedding table in RAM, so the cache has to fit in the VRAM that is left. Llama 3.1 8B has 4.6 GB of weights in VRAM, which leaves less than 4 GB for the cache. Its cache takes 2.1 GB at 16K tokens, 4.3 GB at 32K and 17.2 GB at 128K, so 16K is the largest -c that fits. The KV formula sets this limit, and it restricts every dense model to prompts of 16K or 32K tokens.\n\nThe per-layer embeddings model, Gemma 4 E4B, keeps 2.4 GB in RAM, the size of its per-layer embedding tables and its ordinary embedding table. As described in the previous post, the lookup tables stay in RAM and the GPU computes only the 4.5B effective parameters. The MoE models keep their attention layers and shared weights in VRAM, and llama.cpp places their experts in RAM. It also trades experts for cache: as -c grows, it moves more experts to RAM to make room. gpt-oss-20b, Qwen3.6–35B-A3B and GLM-4.7-Flash go from 5.8 to 6.0 GB of weights in VRAM at 4K to between 2.5 and 3.0 GB at their largest -c. At that size, the experts in RAM take 10.9 GB for gpt-oss-20b, 15.0 GB for GLM-4.7-Flash, and 19.7 and 19.4 GB for the hybrid MoE models. The three with small caches reach 128K without spilling, and GLM-4.7-Flash, at 53 KiB per token, stops at 64K. The ternary model, Bonsai, has the largest weights in VRAM, 5.7 GB for its 27B parameters, which leaves room for 32K tokens of cache.\n\n**Prefill** is limited by how fast the GPU chip computes, so its speed depends on how many parameters each token goes through. Each parameter costs two operations per token, a multiplication and an addition. Multiplying the prefill speed by twice the parameters therefore gives the rate at which the GPU chip computes. Llama 3.2 3B, for example, reads 5,561 tokens per second with 3.2B parameters: 5,561 × 2 × 3.2B gives 36 trillion operations per second (TFLOP/s). For almost every model that keeps its weights in VRAM, this rate is between 32 and 41 TFLOP/s, whatever the size of the model.\n\nThe table lists the models that keep their weights in VRAM. It shows the prefill speed measured with prompts of 4K tokens and the compute rate calculated from it. This length is long enough that the fixed costs of each request no longer matter, and short enough that attention, whose work grows with the prompt, still adds little.\n\nThe GPU chip computes at a nearly constant rate, so a model with more parameters per token reads the prompt more slowly. Bonsai fits this rule: its ternary weights take little memory, but each token still goes through all 27B parameters, so it reads a prompt about eight times more slowly than Llama 3.2 3B.\n\nLFM3 1.7B is the exception. It has the fewest parameters and is the fastest model at reading prompts, at 7,520 tokens per second. At the rate of the other models, around 36 TFLOP/s, it would read about 10,000 tokens per second. However, its compute rate is 26 TFLOP/s. It is also the only model in the study that runs in 16 bits.\n\nThe MoE models read prompts at 250 to 540 tokens per second, far below what their 3B to 3.6B active parameters would allow. The cause is the copy described in the previous post: for every batch of 512 tokens, llama.cpp copies the experts stored in RAM across the PCIe link to the GPU chip, and at 13 GB/s this copy sets a ceiling on the speed. The table shows the time of each copy, the ceiling it sets (512 tokens divided by that time) and the best speed measured.\n\nEach model reaches between 72% and 88% of its ceiling, so the PCIe link takes most of its prefill time. During prefill, a MoE model pays for its total parameters, not only the active ones.\n\nPrompt length also changes prefill speed. In an attention layer, each token is compared with all the tokens before it, so the work per token grows with the length of the prompt. In the dense models, every layer makes this comparison. Llama 3.2 3B falls from 5,561 tokens per second at 4K to 2,537 at 32K, 46% of its speed. In Gemma 3 4B, the sliding-window layers compare each token with at most 1,024 others, and only the 5 global layers grow. It falls from 4,780 tokens per second at 4K to 3,560 at 128K, 74% of its speed. In the hybrid MoE models, the PCIe copy takes most of the time and only a few layers use attention, so the speed barely changes. Qwen3.6–35B-A3B stays between 273 and 299 tokens per second from 1K to 128K. The latent-attention MoE pays both costs: GLM-4.7-Flash copies its experts for every batch and uses attention in all its layers, and it falls from 317 tokens per second at 4K to 176 at 64K, 56% of its speed.\n\nThe prefill speed sets how long the user waits before the answer starts, the time to first token. With a prompt of 128K tokens, LFM3 1.7B starts answering after 30 seconds, Gemma 3 4B after 37 seconds and Gemma 4 E4B after 80 seconds; gpt-oss-20b takes five and a half minutes, Qwen3.6–35B-A3B eight minutes and Nemotron 3 Nano Omni nine. GLM-4.7-Flash, which reaches only 64K, takes six minutes at that length.\n\nDecode works differently. For every new token, the model reads all its active weights and the whole cache once, and does little computation with each value, so its speed is limited by how fast memory is read. Multiplying the measured writing speed by the bytes read per token therefore gives the bandwidth each model used. The table lists the models that keep their weights in VRAM. It shows the writing speed measured with a 1K prompt, where the cache is still small, and the bandwidth calculated from it.\n\nEvery model that keeps its weights in VRAM used between 200 and 231 GB/s, about 80% of the 272 GB/s the VRAM can deliver. Writing speed therefore follows the bytes of weights each token reads, while prefill speed follows the number of parameters.\n\nThis is where quantization pays off. Comparing Llama 3.1 8B with Llama 3.2 3B, the first has 4-bit weights and the second 8-bit weights. Llama 3.1 8B is much bigger, with two and a half times the parameters of Llama 3.2 3B (8.0B against 3.2B). But its quantization makes the weights read per token close in size (4.6 GB against 3.4 GB). In the end, it still writes at 76% of the speed of Llama 3.2 3B (49.7 against 65.6 tokens per second). Bonsai takes this further. Its weights are ternary, about 1.58 bits each. It has 27B parameters, more than three times Llama 3.1 8B. But its ternary weights fit in 5.7 GB. In the end, it writes at 37 tokens per second, the speed of 5.7 GB of weights.\n\nThe convolution hybrid shows the opposite case. LFM3 1.7B is the smallest model, with 1.7B parameters, but it is not quantized, so its weights keep their original 16 bits. Its weights therefore take 3.5 GB, about the same as Llama 3.2 3B (3.4 GB). In the end, both write at the same speed, 66 tokens per second.\n\nThe cache adds to these bytes. Every new token reads the whole cache, which grows during a conversation, so the model slows down as the context grows. The time per token grows in proportion to the bytes read, weights plus cache, which gives a prediction for each prompt length. The table shows how much speed each model kept as the prompt grew.\n\nHow fast the cache grows decides how much speed each group loses. The dense models have the fastest-growing cache. Llama 3.2 3B, with 3.4 GB of weights and 3.8 GB of cache at 32K, should fall from 65.6 to about 31 tokens per second, and it was measured at 34.3. Qwen2.5 7B, with half the cache per token of Llama 3.2 3B, keeps 73%.\n\nIn the groups with local layers, only the global layers grow the cache. Gemma 3 4B keeps 87% of its speed at 32K and 64% at 128K, and Gemma 4 E4B keeps 82% and 52%. The convolution hybrid, LFM3 1.7B, keeps 92% at 32K and 71% at 128K.\n\nIn the recurrent hybrids, only a few attention layers grow the cache, so they slow down little. Nemotron 3 Nano Omni keeps 91% of its speed at 128K, and Qwen3.6–35B-A3B keeps 78%. Bonsai, also a recurrent hybrid, keeps 86% at 32K.\n\nThe MoE models start slower than the others, at 18 to 30 tokens per second. Their experts stay in RAM, and the CPU reads them far more slowly than the GPU reads VRAM. As the prompt grows, the two hybrid MoE models follow the prediction, since their cache is small. gpt-oss-20b does not. With 3.2 GB of cache at 128K, it should keep 79% of its speed, but it kept 31%. At this size, llama.cpp placed two of its 25 layers and their part of the cache in RAM, where the CPU computes attention over all 128K tokens. The latent-attention MoE, GLM-4.7-Flash, keeps its cache in every layer, and with 3.5 GB of it at 64K it keeps 71% of its speed, in the range of the dense models.\n\nStudy A confirms what each architecture was expected to do. The KV cache follows its formula exactly in every model whose layout gives its terms. Prefill is limited by computation and follows the parameters each token uses. Decode is limited by memory and follows the bytes each token reads. The dense models have the largest cache per token, which limits them to prompts of 16K or 32K tokens. In the models with local layers, only the global layers grow the cache, so they reach 128K. The latent-attention MoE compresses its cache to 53 KiB per token, but keeps it in every layer, so it reaches 64K. Since each token reads only a few experts, the MoE models write at 18 to 30 tokens per second with most of their weights in RAM. During prefill, however, they copy the experts across the PCIe link for every batch, and a 128K prompt takes five to nine minutes. The hybrids, recurrent or convolutional, keep their cache small and lose little writing speed as the context grows. The ternary model, Bonsai, fits 27B parameters in 5.7 GB and writes at the speed of those 5.7 GB, while its prefill still goes through all 27B parameters.\n\nThe next part looks at what reasoning adds to this cost: how many tokens each model writes with thinking off and on, and how long they take. The full post, with the four studies, the tables and the interactive charts, is on my site:\n\n[https://www.silasdata.com/llm-playground-testing-architectures/](https://www.silasdata.com/llm-playground-testing-architectures/)\n\n[Testing LLM Architectures, Part 1: Memory and Speed](https://pub.towardsai.net/testing-llm-architectures-part-1-memory-and-speed-3e9df0f91fd2) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/testing-llm-architectures-part-1-memory-and-speed", "canonical_source": "https://pub.towardsai.net/testing-llm-architectures-part-1-memory-and-speed-3e9df0f91fd2?source=rss----98111c9905da---4", "published_at": "2026-12-04 04:43:53+00:00", "updated_at": "2026-12-04 05:13:49.591562+00:00", "lang": "en", "topics": ["large-language-models", "ai-infrastructure", "machine-learning", "ai-research"], "entities": ["llama.cpp", "RTX 4060", "gpt-oss-20b", "GLM-4.7-Flash", "Gemma 3 4B", "Bonsai"], "also_reported_by": [], "takeaway": "Dense models need 112-144 KiB of KV cache per token, while sliding-window and MLA architectures store far less per token but add a fixed startup cache; on an 8 GB RTX 4060, llama.cpp kept gpt-oss-20b at 128K by offloading 2 of 25 layers to RAM but had to drop GLM-4.7-Flash to 64K after offloading 18", "recommendation": {"advice": "Budget KV cache from the architecture's per-token formula before choosing context size, and offload whole layers to RAM rather than spilling to shared GPU memory when the cache exceeds VRAM.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/testing-llm-architectures-part-1-memory-and-speed", "markdown": "https://wpnews.pro/news/testing-llm-architectures-part-1-memory-and-speed.md", "text": "https://wpnews.pro/news/testing-llm-architectures-part-1-memory-and-speed.txt", "jsonld": "https://wpnews.pro/news/testing-llm-architectures-part-1-memory-and-speed.jsonld"}}