What Is a Transformer? BERT, Model Size, Quantization
Watch the video on YouTubeA transformer is the neural-network design behind every modern chatbot: it turns text into tokens and learns which tokens matter for each other. BERT, built by Google in 2018, was the first transformer to reach everyday users through Google Search. Today the practical questions are model size (8B, 27B, 70B parameters) and quantization, because together they decide how much memory a model needs and therefore which Mac can run it.
This is part 2 of the AI Basics series. Part 1, how AI works: tokens, transformers and attention, explains the building blocks. This part follows one thread from the transformer to BERT to the size and compression choices you face when you download a local model. A short video with the same outline is embedded above.
Key takeaways
- A transformer is a neural network design (not a robot) that reads text as tokens and learns which tokens relate to each other.
- BERT (2018) reads a sentence in both directions and was trained by filling in hidden words. It understands text but does not write it.
- Chatbots such as Llama, Qwen and Gemma use the other half: a transformer that predicts the next token, over and over.
- Model size is the parameter count. Each parameter is one number that must sit in memory, so twice the parameters means roughly twice the memory.
- Quantization stores each weight in fewer bits. 8-bit is nearly lossless, 4-bit is about a quarter of the 16-bit size with a small loss, and quality drops fast below 4 bits.
What is a transformer?
Despite the name, a transformer has nothing to do with robots that turn into trucks. It is a neural-network architecture, published by Google researchers in 2017, that processes text by looking at all the words of a passage at once and weighing how strongly each one relates to the others. That weighing mechanism is called attention, and part 1 of this series covers it in detail.
Earlier language models read text one word after another and tended to forget the beginning of long sentences. A transformer can connect a word to another word far away, and it can be trained efficiently on huge amounts of text. That combination is why almost every chatbot, translator and coding assistant you use today is built on it.
The architecture comes in two main flavors. One half, the encoder, is built to understand text. The other half, the decoder, is built to produce it one token at a time. BERT uses the first. The chatbots you run locally use the second. Keeping that split in mind makes the rest of the article easy to follow.
BERT: a transformer that reads in both directions
In 2018, Google researchers released BERT, short for Bidirectional Encoder Representations from Transformers. The long name hides a simple idea. Older models read a sentence strictly left to right, so a word could only be understood from what came before it. BERT looks at the words on both sides of every position at once, which is what "bidirectional" means.
Context on both sides matters constantly in ordinary language. In "he went to the bank to fish", the word that settles the meaning of "bank" comes after it. A model that reads only left to right has to guess. A bidirectional model sees "fish" and settles on a river bank, not a financial one.
The original BERT models were also small by today's standards, with hundreds of millions of parameters rather than billions. That is part of why they were practical to run inside a search engine that answers enormous numbers of queries.
How BERT was trained: filling in the blanks
BERT's training task is a fill-in-the-blank exercise. Researchers hide a share of the words in a sentence and ask the model to predict the missing ones from the words around them. "The cat sat on the [hidden]" becomes a question with a checkable answer, and the answer is already in the original text.
That detail is the important part. Because the correct answer comes from the text itself, nobody has to label anything by hand. Billions of such blanks later, the model has learned a great deal about grammar, word meaning and which words appear in which situations, with no human annotation at all. This style of learning is called self-supervised, and it is the reason transformers could scale to the size of the open web.
BERT in Google Search: the visa example
In October 2019, Google started using BERT in Search. It said the change helped understand roughly 1 in 10 English-language queries in the United States. It was not a new feature or a new box on the page. It was a better grasp of what people actually meant, especially for longer, conversational queries where small words carry the meaning.
Google's own example was the query "2019 brazil traveler to usa need a visa". The small word "to" signals direction: a person from Brazil traveling to the United States. The old ranking system largely ignored that little word and returned pages about US citizens traveling to Brazil, which is the opposite question. With BERT, the system understood the direction and could surface the right information.
For this article the lesson is simple. A transformer does not count keywords. It reads the relations between words, and that is why even a very small word can change the result.
BERT reads, chatbots write
BERT understands text, but it does not write text. Ask it to continue a story and it has nothing to offer, because its training task was filling gaps, not producing new sentences. It is excellent for search ranking, classification and finding which passage answers a question.
The local chatbots people run on a Mac, such as Llama, Qwen and Gemma, use the other half of the transformer. They are trained to predict the next token given everything before it, and then they repeat that step again and again, feeding each new token back in. That loop is what produces a paragraph. Reading the prompt and writing the answer are two different workloads on your hardware, which is why memory bandwidth decides tokens per second while the prompt is processed in a separate, compute-bound step.
What model size means: 8B, 27B, 70B
When a model is called "27B", the B stands for billions of parameters. A parameter, also called a weight, is simply one number. The model is a very large table of such numbers, and training is the process of adjusting them until the predictions are good. Frontier models run to hundreds of billions of parameters. The ones you can run on a laptop or a desktop usually sit between 1B and about 70B.
Bigger models usually know more and make fewer mistakes, but they cost memory in direct proportion. Every parameter has to be available whenever the model produces a token, so all of them have to sit in memory. The rough formula is parameters × bits per weight ÷ 8, which gives the size in bytes.
| Model | At 16 bits | At 8 bits | At 4 bits (nominal) |
|---|---|---|---|
| 8B | about 16 GB | about 8 GB | about 4 GB |
| 27B | about 54 GB | about 27 GB | about 13.5 GB |
| 70B | about 140 GB | about 70 GB | about 35 GB |
Twice the parameters means twice the memory, and also slower writing, because a dense model reads all of its weights for every token it generates. The nominal 4-bit column is a floor. Real 4-bit files are a bit larger, as the worked example below shows. For how this translates into Mac configurations, see how much RAM you need for a local LLM.
Why newer small models can beat older big ones
If size always won, you would simply buy the largest model that exists. It does not, because training keeps improving: better data, longer training runs and better recipes. A new 8B or 27B model can match or beat an older model that is several times its size.
So "newer" is often a better filter than "bigger". When you compare candidates, check the release date alongside the parameter count. A recent mid-size model frequently gives you the quality of last generation's giant at a fraction of the memory, and that is often the difference between a model that fits on your Mac and one that does not.
Quantization: fewer bits per weight
By default a model's weights are stored as 16-bit numbers. Quantization stores each weight with fewer bits, in the same spirit as compressing a photo: a smaller file and slightly less detail. Because the whole model must sit in memory, a smaller file is exactly what lets a big model fit on a smaller Mac.
The trade-off follows a clear pattern. 8-bit is almost lossless and halves the size. 4-bit is about a quarter of the 16-bit size, with a small quality loss that most people never notice in normal use. Below 4 bits quality falls off quickly, which is why 4-bit is the usual sweet spot.
The table uses our data for Qwen3.8 27B (27.8 billion parameters). File sizes are 27.8 × bits ÷ 8 in decimal gigabytes. The last column gives the smallest Mac memory size that fits the model with a 32K context, using the calculator's rule that the GPU can use about 2/3 of RAM up to 36 GB and about 3/4 above that.
| Format | Bits per weight | Size of 27.8B model | Quality loss | Smallest Mac that fits at 32K context |
|---|---|---|---|---|
| 16-bit (FP16) | 16 | about 55.6 GB | none (reference) | 96 GB |
| Q8_0 | 8.5 | about 29.5 GB | almost none | 48 GB |
| Q6_K | 6.6 | about 22.9 GB | very small | 48 GB |
| Q4_K_M | 4.85 | about 16.9 GB | small | 32 GB |
| Q3_K_M | 3.9 | about 13.6 GB | noticeable, growing fast | 32 GB (24 GB only with a short context) |
Quality labels are qualitative general guidance, not benchmark results for this model. The bits-per-weight values are higher than the headline number because the formats store block scales and keep some sensitive tensors at higher precision.
A worked example: a 27B model on a 32 GB Mac
The video gives the round numbers: a 27B model needs about 54 GB at 16 bits and about 16 GB at 4 bits, which is why it can run on a 32 GB Mac. Those figures are the right order of magnitude. Our data gives the exact picture for Qwen3.8 27B, and the differences are worth understanding.
- 16-bit weights. The round figure is 27 × 2 = 54 GB. The real model has 27.8 billion parameters, so 27.8 × 16 ÷ 8 = 55.6 GB.
- 4-bit weights. A pure 4-bit file would be 27.8 × 4 ÷ 8 = 13.9 GB. The Q4_K_M format averages 4.85 bits per weight, which gives 27.8 × 4.85 ÷ 8 = 16.9 GB, close to the video's "about 16". The extra comes from per-block scale values and the sensitive tensors kept at higher precision.
- Units. The calculator compares in binary gigabytes (GiB), where 16.9 GB of file is 15.7 GiB of memory. The Qwen3.8 27B entry has no published file size in our data, so this figure is a formula estimate.
- Usable memory. A 32 GB Mac gives the GPU about 32 × 0.667 = 21.3 GiB by default.
- Context and buffers. At a 32K context the KV cache is 2.0 GiB, because only 16 of the model's 64 layers keep a growing cache. The runtime buffers add about 1.4 GiB. Total: 15.7 + 2.0 + 1.4 = 19.1 GiB.
- Result. 21.3 minus 19.1 leaves about 2.2 GiB of headroom, with roughly 89 percent of usable memory in use. The calculator marks that as fits.
What about longer context? At 64K the cache doubles to 4.0 GiB and the headroom shrinks to about 0.1 GiB, which the calculator marks as tight. A 128K context does not fit at the default 16-bit cache. Storing the cache in 8-bit stretches the limit to roughly 117K tokens, but leaves no spare room there, so 32K to 64K is the realistic range on 32 GB. These are estimates, not measurements.
The rule: pick the biggest model that fits, then quantize
Put the pieces together and one rule falls out. A bigger model at 4-bit usually beats a smaller model at 16-bit in the same memory. A concrete pair: an 8B model at 16 bits takes about 16 GB, and a 27B model at Q4_K_M takes about 16.9 GB. The memory is almost the same, yet the larger model at 4-bit is the stronger choice for most tasks.
The practical order of operations is therefore:
- Decide which memory size you have, or can afford, and compute the usable share.
- Choose the largest recent model whose 4-bit version fits with room for your context.
- Quantize to 4-bit first. Move up to 6-bit or 8-bit only if you have spare memory.
- Go below 4-bit only as a last resort, and test the quality on your own prompts.
Once the model fits, speed is the next question. The speed simulator estimates tokens per second for each chip, and the buying guide turns both into a purchase decision. If the choice is between chip tiers, read Pro vs Max vs Ultra for local LLMs.
Try it yourself: match any model to the right Mac
Doing this arithmetic by hand for every model gets tedious. The free calculator that matches any local LLM to the right Mac does it for you: pick a model, a quantization, a context length and a Mac configuration, and it shows the weights, the KV cache, the headroom and the expected speed. It uses the same formulas as in this article, so you can check any number yourself.
FAQ
What is a transformer in AI?
A transformer is a neural-network architecture that processes text as tokens and uses attention to weigh how strongly each token relates to the others. It was introduced in 2017 and underlies almost every modern chatbot, translator and coding assistant. It has no connection to robots, apart from the name.
What does BERT stand for and what does it do?
BERT stands for Bidirectional Encoder Representations from Transformers. Google released it in 2018, and it understands text by reading in both directions at once. It is used for tasks such as ranking search results and classifying text, but it does not generate new text.
How did BERT improve Google Search?
Google began using BERT in Search in October 2019, and said it helped with about 1 in 10 English-language queries in the United States. It improved how the system reads small words that change a query's meaning. In Google's own example, "2019 brazil traveler to usa need a visa", the old system ignored the word "to" and showed rules for Americans traveling to Brazil.
What do 8B, 27B and 70B mean in a model name?
The number is the count of parameters in billions, and each parameter is a single number stored in memory. A 27B model therefore has about 27 billion such numbers. As a rule, a bigger model knows more but needs proportionally more memory and writes more slowly.
Is a 4-bit quantized model much worse than the full 16-bit one?
Usually the loss is small. 8-bit is almost lossless, and 4-bit takes about a quarter of the 16-bit size with a small drop in quality that most people do not notice in normal use. Below 4 bits quality falls quickly, so test it on your own prompts before relying on it.
Can a 27B model run on a 32 GB Mac?
Yes, at 4-bit. By our estimate Qwen3.8 27B at Q4_K_M needs about 15.7 GiB for weights, plus a 2.0 GiB cache and 1.4 GiB of buffers at 32K context, against about 21.3 GiB the GPU can use. That fits with roughly 2 GiB to spare, and 64K context is tight.
Why can a newer small model beat an older big one?
Because training keeps improving through better data, longer runs and better methods. A recent 8B or 27B model can match an older model several times its size. For that reason the release date is worth checking next to the parameter count.