Open-weight model families: Llama, Mistral, Qwen, Gemma and BLOOM
The open-weight families share one recipe and differ in a few attention tricks that shrink memory and in their licenses. Learn grouped-query attention, sliding windows, local and global layers and ALiBi, and what each license lets you do.
What runs in CodeSplash
- LNG035LLaMA / Llama family Explained here
- LNG036Mistral 7B Explained here
- LNG038Qwen language-model family Explained here
- LNG041Gemma model family Explained here
- LNG044BLOOM Explained here
You will be able to
- Explain how grouped-query attention, sliding windows and local layers shrink the KV cache
- Describe ALiBi's distance penalty and why it helps with longer inputs
- Read a model license for the clauses that matter to your use
- Run an open-weight model locally through CodeSplash's AI layer, and say what that does and doesn't promise
One recipe, small differences
ReadMost open-weight decoders share a recipe: pre-normalized Transformer blocks (often RMSNorm), rotary position embeddings, gated feed-forward layers, a byte-level or SentencePiece tokenizer, and next-token pretraining followed by instruction and preference tuning.
Where they differ most is in how they keep generation affordable. While generating, a model stores every layer's keys and values for every previous token, the KV cacheKV cacheKeys and values a language model keeps for every token in its context, per layer. It grows with the context window.. For long prompts that cache, not the weights, often fills the memory. Each trick below shrinks it.
DExplorable · How much memory does a model need?
Where does a language model's memory go — weights, KV cache, optimizer state — and does it fit on this Mac?
Model
Hypothetical decoders; the first is the reference workflow's own.
Tokens held in the KV cache (and the length of the attention scores).
Sequences processed at once; the KV cache grows with it.
Weight format
Bits per stored weight; the llama.cpp types include their block scales.
KV cache format
Bytes per stored key or value.
Use
Training adds gradients and optimizer state; LoRA adds them only for the adapters.
LoRA only: rank of each adapter.
LoRA targets
LoRA only: which matrices get adapters.
Under half is “fits”, under 85% “tight”, as the app's own estimate says.
- Weights: 0.31 GiB
- KV cache: 0.02 GiB
- Runtime overhead (10%): 0.03 GiB
- Verdict: fits (2%)
- This model's KV heads (grouped-query)
- One KV head per query head
- Parameters
- 168059904
- Weight bytes
- 336119808
- KV cache bytes
- 25165824
- Trainable parameters
- 0
- Total bytes
- 397414195
- Share of this Mac's memory
- 0.023
- Puzzle: Make the larger decoder fit (under half) a 16 GB Mac for inference with a 4,096-token context.
- Puzzle: With LoRA training less than 1% of the parameters, find a case where the total is still more than half of full fine-tuning's.
Reference decoder (168M parameters): 168,059,904 parameters, 0.31 GiB of weights in fp16 and a 0.02 GiB KV cache for 2,048 tokens. Total 0.37 GiB: 2% of 16 GB, so it fits. These are logical tensor sizes, not measured memory.
Fewer key–value heads: Llama
ReadStandard attention gives every query head its own key and value head. Grouped-query attentionGrouped-query attentionSeveral query heads share one key–value head, so the KV cache shrinks by the group size with little loss in quality., used by Llama 2 and later, lets a group of query heads share one key–value head. With 32 query heads and 8 key–value heads, the reference program finds 4 queries per key–value head, so the cache is 25% of full multi-head attention's.
Llama's license is not an open-source license: it adds a clause for very large services, naming rules for derivatives and an acceptable-use policy. CodeSplash never bundles or auto-downloads Llama; you can run it in your own local runtime.
Look back a fixed distance: Mistral and Gemma
ReadSliding-window attentionSliding-window attentionEach token attends only to the last W tokens; stacked layers still reach further back, and the KV cache stays W tokens long. lets each token attend only to the last W tokens. Mistral 7B uses it in every layer; stacked layers still pass information further back, one window per layer. The reference program's mask for six tokens and a window of three is a band of ones along the diagonal.
Gemma interleaves local sliding-window layers with global layers that see everything before them. For five tokens and a window of two, a local layer has 9 allowed connections against 15 for a global one. Fewer connections, smaller cache, with global layers keeping long-range reach.
A penalty for distance: BLOOM
ReadBLOOM drops position embeddings and uses ALiBiALiBiEncodes position by subtracting a per-head slope times query–key distance from attention scores; extends to longer inputs.: each head subtracts a fixed slope times the distance from its attention scores. With slope 0.2, a query at position 4 penalizes keys from −0.8 for the farthest down to zero for itself. Because the penalty is a rule, not a learned table, it extends to inputs longer than any seen in training.
BLOOM's RAIL license restricts uses and requires passing those restrictions on to your users, which is why CodeSplash keeps it out of any catalog.
Compare ALiBi's distance penalty with RoPE's rotations.
DExplorable · Positional encodings: sinusoidal, RoPE, ALiBi
How does attention learn where a word is, and what does each scheme remember about distance?
Shift the query and every key by the same amount. Do the scores change with this scheme?
Scheme
Base
Sets the slowest wavelength: larger bases tell far positions apart.
Score both positions s places later: does anything change?
Each head has its own slope.
- score(20, n)
- both shifted by 7
ALiBi bias −slope·|i − j| (slope 0.1250)
Commit your prediction above to see the result
Make your prediction to see the result.
Families and licenses move
ReadQwen spans many sizes, dense and mixture-of-experts. In its MoE variants a router mixes chosen experts' outputs by softmax weights; the reference program mixes two experts into 0.236 and 0.364. Optional "thinking" modes write long reasoning before answering, which costs tokens and time.
Licenses change between releases: Qwen3 and Gemma 4 are Apache-2.0, while earlier Gemma models came with Gemma Terms of Use. Check the license of the exact release you run.
Running one on your Mac
PredictPredict first
You point CodeSplash's AI layer at an open-weight model running in Ollama. What does running it locally give you?
Reveal
Your text stays on your Mac, but answers still vary with the model version, its quantizationQuantization (language models)Storing a model's weights with fewer bits (Q4 ≈ 4.5 bits, Q8 ≈ 8.5, F16 = 16), which shrinks memory at some cost in quality. and sampling settings. Local is a privacy and cost choice, not a reproducibility guarantee.
Where it stands in CodeSplash
Read| Entry | In CodeSplash |
|---|---|
| Llama (LNG035) | Explained here; usable through the AI layer, not a method, never bundled |
| Mistral 7B (LNG036) | Explained here; usable through the AI layer, not a method |
| Qwen (LNG038) | Explained here; usable through the AI layer, not a method |
| Gemma (LNG041) | Explained here; usable through the AI layer, not a method |
| BLOOM (LNG044) | Explained here; kept out of every catalog (RAIL license) |
"Through the AI layer" means a local runtime you install (Ollama or LM Studio) behind AI features such as Ask documents and Label with AI. There are no parity checks, and answers change with the model version and its quantization.
Check: open-weight families
CheckpointCheck yourself
A model has 32 query heads and 8 key–value heads. What does grouped-query attention save?
Show the answer
Answer: b
Four query heads share each key–value head, so the cache holds a quarter of what full multi-head attention would.
Check yourself
Why doesn't CodeSplash bundle or auto-download Llama models?
Show the answer
Answer: b
Open weights don't mean an open-source license. Users who want Llama install it in their own local runtime under its terms.
Check yourself
With sliding-window attention of width W in every layer, can information travel further back than W tokens?
Show the answer
Answer: b
Token t sees t − W + 1 … t in one layer; a token in that window saw its own window in the layer below, and so on.
Check yourself
Why does a sliding window cap the KV cache?
Show the answer
Answer: a
A rolling buffer of W tokens per layer is enough, however long the generation runs.
Check yourself
A Qwen model's thinking mode writes a long reasoning passage before answering. What does that cost?
Show the answer
Answer: b
Every reasoning token is generated like any other. Use it where it helps, and measure whether it does.
Check yourself
In a mixture-of-experts layer, how are the chosen experts' outputs combined?
Show the answer
Answer: b
The router scores the experts, keeps the top few, and mixes their outputs by renormalized weights.
Check yourself
Why does Gemma mix local and global attention layers instead of using only local ones?
Show the answer
Answer: b
The interleave trades memory against reach: most layers look nearby, a few look everywhere.
Check yourself
Gemma 3 and Gemma 4 come under different licenses. What follows for your project?
Show the answer
Answer: b
Earlier Gemma releases used Gemma Terms of Use; Gemma 4 moved to Apache-2.0. The release, not the family name, decides.
Check yourself
How does ALiBi encode position?
Show the answer
Answer: b
Nearby tokens are penalized less than far ones; because the rule is linear, it applies to any length.
Check yourself
What makes BLOOM's RAIL license different from Apache-2.0?
Show the answer
Answer: b
Responsible-AI licenses attach use restrictions that travel downstream, which is why the model stays out of CodeSplash's catalogs.
Recap
Recap- The KV cache dominates memory in long generations; GQA, sliding windows and local layers shrink it.
- ALiBi penalizes distance linearly and extends to longer inputs.
- Read the license of the exact release: Llama, Gemma (≤3) and BLOOM carry conditions; Qwen3 and Gemma 4 are Apache-2.0.
- These models run in CodeSplash only through the AI layer, in a local runtime you install.
Concepts in this lesson