KIVI, End to End: How 2-bit KV Cache Quantization Works Inside VeloxQuant-MLX
Imagine running a language model locally on your Mac. You load the model, start a conversation, and everything works smoothly. But as the conversation gets longer, memory consumption keeps increasing. Eventually, you may find that your Mac is running out of available memory, even though the model itself has already been loaded.
Why does this happen?
One important reason is something called the KV cache.
Every time a language model processes another token, it needs information about the tokens it has already seen. Rather than calculating that information again and again, the model stores it in memory. This makes text generation much faster, but it also creates a problem: the longer the conversation, the more memory the model needs.
This is particularly important when running large language models on consumer hardware. A Mac with 24 GB of unified memory, for example, has to share that memory between model weights, the KV cache, the operating system, and other applications.
One way to address this problem is to store the KV cache using fewer bits.
This is where KIVI comes in.
KIVI is a research method that reduces the precision of cached keys and values. Instead of storing every number as a 16-bit floating-point value, it represents most of them using only 2 bits. The method does not require additional model training or a calibration dataset.
That sounds simple, but there is an important detail: KIVI does not compress every number in the same way. It uses different grouping strategies for keys and values because they behave differently inside the attention mechanism.
In this article, we will follow that idea from the mathematics to its implementation inside VeloxQuant-MLX.
We will explore:
- Why the KV cache consumes so much memory.
- What quantization actually does to a number.
- How KIVI decides which numbers should share a quantization scale.
- Why keys and values use different grouping directions.
- How the newest tokens are protected using a residual window.
- How the implementation works inside VeloxQuant-MLX.
- How custom Metal kernels accelerate the quantization operation.
- What our experiments reveal about memory consumption, generation speed, and model quality.
- What it takes to deliver real memory savings, and what is still missing.
We will also distinguish between what the original KIVI paper demonstrates and what our current implementation actually does.
That distinction matters because a cache that contains quantized values is not necessarily a cache that occupies less memory.
What did we actually discover?
Before getting into the implementation, here are the most important results from our experiments.
We tested KIVI on an Apple M4 machine with 24 GB of unified memory, using real language models and synthetic data.
The results support several important conclusions:
- KIVI's decision to group keys and values along different axes makes a measurable difference. On Llama-3.2-1B, it produced substantially better next-token predictions than the three alternative grouping combinations we tested.
- At 4-bit precision, the additional next-token loss was only 0.015 nats compared with an uncompressed FP16 cache.
- At 2-bit precision, the additional loss increased to 0.544 nats.
- With 2-bit quantization, the model selected the same highest-scoring next token as the FP16 baseline only 66.7% of the time in our teacher-forced evaluation.
- The custom Metal kernels produced exactly the same reconstructed values as the MLX implementation and were faster as standalone operations.
- However, VeloxQuant-MLX's default KIVI cache still stores reconstructed values as FP16, so it does not reduce actual KV-cache memory consumption.
That last point deserves particular attention.
Our implementation applies KIVI's quantizer and grouping scheme to study its effect on model quality, with some differences in timing from the paper (see Section 13). By default it does not store the cache in a packed low-bit format, so it does not reduce KV-cache memory.
After this article was first published, we added an opt-in setting, kivi_packed_storage=True, that stores the cache packed. It produces the same output as the default cache, uses much less memory, and decodes more slowly. Section 15 has the measurements. Unless it says otherwise, the rest of this article describes the default cache.
For example, a compression estimate of 4.2× does not mean that the cache currently occupies one-fourth of its original memory. It means that a future packed representation could theoretically require approximately that amount of storage under the assumptions used by the estimate.
We will return to this distinction later.
1. Why does a language model need a KV cache?
To understand KIVI, we first need to understand the problem it is trying to solve.
When you ask a language model a question, the model processes your input as a sequence of tokens. Tokens are small units of text that can represent complete words, parts of words, or punctuation.
For example, consider this sentence:
The weather is beautiful today.
A tokenizer might split it into several tokens. The exact tokenization depends on the model.
A transformer processes these tokens through multiple attention layers. During this process, each token produces two important representations:
- Key (K): Helps the model determine which previous tokens are relevant to the current token.
- Value (V): Contains information that the model retrieves from those relevant tokens.
You can think of keys as helping the model decide where to look and values as providing what it finds there.
Why not calculate everything again?
Suppose you ask a model to generate a response containing 100 tokens.
When generating the first token, the model processes your prompt. When generating the second token, it needs information from the prompt and the first generated token.
When generating the third token, it needs information from everything that came before.
A straightforward implementation could recalculate the keys and values for every previous token at every generation step. But that would repeat a substantial amount of work.
Instead, transformer implementations keep previously calculated keys and values in memory.
This stored history is called the KV cache.
A simplified view of generation
- Process the prompt: The model calculates keys and values for the input tokens and stores them.
- Generate the next token: The model calculates the new token's representations and compares its query with the cached keys.
- Reuse previous information: The model reads the corresponding cached values and combines them using attention.
- Extend the cache: The newly calculated keys and values are added to the existing cache.
- Repeat: This process continues until the model finishes generating its response.
The benefit is straightforward: the model does not need to recalculate the entire history every time it generates another token.
The downside is that the cache keeps growing.
How much memory does the KV cache consume?
The memory requirement depends on the model architecture and the number of tokens being processed.
We can calculate the approximate memory requirement using:
Let's understand each variable.
| Variable | Meaning |
|---|---|
| Accounts for both keys and values | |
| Number of transformer attention layers | |
| Number of key/value heads in each layer | |
| Number of values in each head | |
| Number of cached tokens | |
| Bytes used to store each number |
For FP16, each number occupies 2 bytes because it uses 16 bits.
Consider a model with the following architecture, similar to Qwen3-8B:
- 36 attention layers.
- 8 key/value heads per layer.
- 128 dimensions per head.
- FP16 cache values.
The memory required for a single token is:
That means every additional token adds approximately 144 KiB to the KV cache.
Now consider how quickly this adds up:
| Context length | Approximate FP16 KV cache |
|---|---|
| 2,048 tokens | 288 MiB |
| 8,192 tokens | 1.12 GiB |
| 16,384 tokens | 2.25 GiB |
| 32,768 tokens | 4.50 GiB |
These numbers represent the KV cache alone. They do not include model weights, temporary computation buffers, or the memory required by other applications.
For someone running a model locally on a Mac with 24 GB of unified memory, an additional 4.5 GiB can make a significant difference.
This is the problem KIVI tries to address: how can we keep the information required by attention while using fewer bits to represent it?

Figure 1. KV cache memory requirements as the context gets longer. The solid line represents the actual memory required by an FP16 cache. The dashed lines show estimated memory requirements if KIVI used a genuinely packed 4-bit or 2-bit representation. These are theoretical packed-storage estimates, not the memory currently occupied by VeloxQuant-MLX.
2. Three concepts you need to understand first
Before exploring KIVI's implementation, let's establish three concepts that will make the rest of the article easier to follow.
You do not need to understand every mathematical detail immediately. The important thing is to understand what each concept does.
2.1 Attention: how the model decides what information matters
Attention is one of the central mechanisms inside a transformer.
Imagine reading a paragraph and answering a question about it. You do not give every word equal importance. You focus on the words that are relevant to the question.
Attention works in a similar way.
For a particular token, the model generates a query vector . It compares that query with the keys of previously processed tokens.
The comparison produces an attention score:
Here:
- is the query vector for the current token.
- is the key vector belonging to an earlier token.
- is the dimension of the vector.
- represents how relevant token is to the current query.
The model then converts these scores into attention weights using softmax:
These weights determine how much information the model retrieves from each token.
Finally, the model combines the corresponding value vectors:
Here, is the attention output.
The important distinction is:
- Keys influence the attention scores.
- Values provide the information that gets combined using those scores.
This is why modifying a key and modifying a value can have different effects on the model's output.
It is also the reason KIVI does not treat keys and values identically.
2.2 Quantization: representing numbers with fewer bits
Computers use bits to represent numbers.
A typical FP16 floating-point number uses 16 bits. Quantization attempts to represent that number using fewer bits.
For example:
| Precision | Available integer codes |
|---|---|
| 2-bit | 4 |
| 3-bit | 8 |
| 4-bit | 16 |
| 8-bit | 256 |
| 16-bit | 65,536 possible bit patterns |
The smaller the number of bits, the fewer distinct values we can represent.
Consider a number such as 0.55.
If we have a representation that allows only four possible values between -0.30 and 0.90, we cannot necessarily store 0.55 exactly. We have to select the closest available value.
That introduces an error.
Quantization therefore involves two related operations:
- Quantization: Map the original number to a smaller set of representable values.
- Dequantization: Reconstruct an approximate version of the original number.
In a packed implementation, the quantized integer codes are stored rather than the original floating-point numbers.
In our current VeloxQuant implementation, we perform both operations but store the reconstructed floating-point values. We will examine why that matters later.
2.3 Channels, tokens, and groups
There is one more concept we need before understanding KIVI.
A key or value tensor can be represented using four dimensions:
[batch, heads, tokens, D]
Each dimension tells us something:
batch: Number of independent sequences being processed.heads: Number of attention heads.tokens: Number of tokens in the sequence.D: Number of dimensions, or channels, in each head.
For simplicity, imagine that we are looking at one attention head.
We can represent its cached values as a table:
- Each row represents a token.
- Each column represents a channel.
- Each cell contains one numerical value.
A small example might look like this:
| Token | Channel 1 | Channel 2 | Channel 3 | Channel 4 |
|---|---|---|---|---|
| Token 1 | 0.2 | 1.5 | -0.3 | 0.7 |
| Token 2 | 0.4 | 1.7 | -0.1 | 0.9 |
| Token 3 | 0.1 | 1.3 | -0.2 | 0.8 |
| Token 4 | 0.3 | 1.6 | -0.4 | 0.6 |
Now imagine selecting a few cells and quantizing them together.
A quantization group is simply a collection of numbers that share the same quantization parameters.
In KIVI, these parameters are:
- A minimum value, which determines where the quantization grid starts.
- A scale, which determines the distance between consecutive representable values.
Which numbers we put together into a group has a major impact on the resulting error.
That is the central design decision behind KIVI.
3. What makes KIVI different?
KIVI stands for A Tuning-Free Asymmetric 2bit Quantization for KV Cache. It was introduced by Liu, Yuan and colleagues and published at ICML 2024.
Its central idea is surprisingly simple.
Rather than treating the entire KV cache as one large collection of numbers, KIVI divides it into small groups and independently quantizes each group.
However, it makes an important distinction between keys and values.
Its four main rules are:
- Find the minimum and maximum of each group and use them to construct a quantization grid.
- Group keys along the token dimension, keeping each channel separate.
- Group values along the channel dimension, keeping each token separate.
- Keep the newest tokens in higher precision instead of immediately quantizing them.
The second and third rules are what make KIVI asymmetric.
Why is that useful?
Because keys and values have different statistical characteristics and play different roles in attention. Applying the same grouping strategy to both can introduce unnecessary errors.
We will explore the reasoning behind this in detail.
Following one token through KIVI
Before looking at the individual operations, let's understand the complete process.
When a new token enters the cache, VeloxQuant-MLX:
- Adds the token's keys and values to the existing cache.
- Checks whether enough tokens have accumulated to move the quantization boundary.
- Identifies the older tokens that have become eligible for quantization.
- Quantizes keys and values using their respective grouping strategies.
- Reconstructs the values and writes them back into the cache.
- Updates its compression accounting.
- Returns the cache to the attention mechanism.
The process does not necessarily quantize something on every token. It waits until a complete group of tokens is ready.
Figure 2. The complete workflow inside KIVIKVCache.update_and_fetch. The blue boxes represent cache management and bookkeeping. The orange boxes represent operations that modify numerical values. Most single-token updates follow the dashed path because quantization only happens when the boundary advances.
Let's now look at exactly how those numbers are transformed.
4. How does the KIVI quantizer work?
At the heart of KIVI is a simple min-max quantization method.
Instead of trying to preserve every original number exactly, it creates a small set of representable values between the minimum and maximum of a group.
Let's work through the mathematics.
Suppose we have a group containing numbers:
We want to represent these numbers using bits.
The first step is to find the smallest and largest values:
The two quantities have specific purposes:
- is the starting point of the quantization grid, also called the zero point.
- is the distance between consecutive representable values, also called the scale.
Why divide by ?
Because bits provide possible codes. If we want to include both the minimum and maximum as representable values, there must be intervals between them.
We can then convert each original value into an integer code:
Finally, we reconstruct the approximate value:
The reconstructed value is the closest value available on the quantization grid, subject to the rounding rule.
An intuitive way to understand this
Imagine that you have a ruler.
The ruler starts at the smallest number in your group and ends at the largest number. It has only a limited number of marks.
At 2-bit precision, you get four available marks.
At 4-bit precision, you get sixteen available marks.
Every original number is moved to its nearest mark.
The fewer marks you have, the larger the potential distance between the original number and its reconstructed value.
This is the fundamental trade-off in quantization.
4.1 A complete 2-bit example
Let's use four numbers:
We want to quantize them using 2 bits.
Since 2 bits provide four possible codes, we have four available values.
Step 1: Find the minimum and maximum.
The smallest value is -0.30, and the largest is 0.90.
Therefore:
Our quantization grid now contains four values:
Step 2: Map each original number to a code.
For every number, we calculate its position on the grid and round it to the nearest integer.
For example, consider 0.55:
The nearest integer is 2.
Its reconstructed value becomes:
We repeat this for all four numbers.
| Original value | Calculated position | Code | Reconstructed value | Error |
|---|---|---|---|---|
| 0.10 | 1.000 | 1 | 0.10 | 0.00 |
| 0.90 | 3.000 | 3 | 0.90 | 0.00 |
| -0.30 | 0.000 | 0 | -0.30 | 0.00 |
| 0.55 | 2.125 | 2 | 0.50 | -0.05 |
Step 3: Calculate the error.
Three values are represented exactly. Only 0.55 changes, becoming 0.50.
The error for that value is:
The mean squared error across all four values is:
This is a small example, but it demonstrates the basic mechanism behind KIVI.

Figure 3. A visual representation of the quantization example. The original values are mapped to the nearest available grid points. The reconstructed values were produced using KIVIKVCache's own round-trip function.
An interesting property of this approach is that the minimum and maximum values are represented exactly, apart from floating-point rounding. This is because the quantization grid is constructed using those two values as its endpoints.
One implementation detail
VeloxQuant also includes a small safeguard.
What happens if every value in a group is identical?
In that situation:
The scale becomes zero, which would cause division by zero during quantization.
To avoid this, the implementation applies a minimum scale of:
This ensures that the operation remains numerically safe even when a group has no variation.
5. How much information do we lose during quantization?
Quantization always introduces some approximation error.
The important question is not whether an error exists, but how large it can become and whether the model can tolerate it.
Let's examine this from two perspectives: the mathematical error bound and the actual effect on attention.
5.1 The maximum possible error
Remember that quantization moves every number to its nearest available grid point.
The distance between two adjacent grid points is .
Because we round to the nearest point, the reconstructed value cannot be more than half a grid interval away from the original value.
Therefore:
Substituting the definition of :
This equation tells us something important.
The maximum error depends on two things:
- The range of values inside the group.
- The number of bits available for representing them.
A group with a very large range has a wider quantization grid and therefore potentially larger errors.
Increasing the bit width creates more representable values and reduces the spacing.
For example:
- At 2 bits, the spacing is the group range divided by 3.
- At 4 bits, the spacing is the group range divided by 15.
So moving from 2 bits to 4 bits reduces the maximum grid spacing by a factor of 5.
That is why 4-bit quantization generally preserves more information than 2-bit quantization.
5.2 What is the average error likely to be?
The maximum error tells us the worst possible situation. But most values will not necessarily experience that maximum.
If values are distributed approximately randomly between two neighboring grid points, the rounding error can be modelled as approximately uniform over:
The mean squared error of a uniform distribution over this interval is:
There is one additional detail in KIVI.
The smallest and largest values in every group are represented exactly because the grid is constructed using them.
If a group contains values, two of those values have zero reconstruction error.
This gives us the following approximation:
Here, is the group size and represents the average over many values.
This is an approximation rather than an exact guarantee. It assumes that the remaining values are distributed roughly randomly between quantization levels.
Does the approximation match real measurements?
We tested it using 4,000 synthetic groups for each configuration.
We generated both uniform and Gaussian data, passed the groups through the same quantization and reconstruction function used by the cache, and compared the observed error with the theoretical prediction.
The results are:
| Group size | Predicted | Uniform, 2-bit | Gaussian, 2-bit | Gaussian, 4-bit |
|---|---|---|---|---|
| 8 | 0.750 | 0.751 | 0.759 | 0.752 |
| 32 | 0.938 | 0.935 | 0.948 | 0.939 |
| 128 | 0.984 | 0.983 | 0.990 | 0.985 |
The reported values are the measured mean squared errors divided by .
The theoretical approximation is close to the measurements in all three group sizes.
We also confirmed that the largest observed reconstruction error in any group stayed within the theoretical half-step bound, apart from floating-point rounding.
Does increasing the group size always help?
Not necessarily.
Larger groups have one advantage: the cost of storing their quantization parameters can be spread across more numbers.
But there is also a disadvantage.
A larger group is more likely to contain values that are very far apart. That increases the group's minimum-to-maximum range and can make the quantization grid coarser.
We observed this trade-off in our Gaussian experiments:
| Group size | Mean squared error at 2 bits |
|---|---|
| 8 | 0.062 |
| 32 | 0.155 |
| 128 | 0.251 |
These values come from the same synthetic-data experiment.
KIVI uses a group size of 32 as its default.
5.3 Why even a small key error can affect attention
So far, we have discussed how accurately we can reconstruct an individual number.
But a language model does not care about individual reconstruction error in isolation. It cares about the effect that those errors have on attention and ultimately on the model's predictions.
Suppose a key element is reconstructed with an error:
Here:
- identifies the token.
- identifies the channel.
The attention score depends on the dot product between the query and the key.
Consequently, the change in the attention score is:
In simple terms, every key reconstruction error is multiplied by the corresponding query value and contributes to the final attention-score error.
This has an important implication.
An error in a channel that the query barely uses may have little effect. An error in a channel that the query relies on heavily can have a much larger effect.
If we approximately treat the errors as independent and zero-mean, the variance of the attention-score change becomes:
Here, represents the scale associated with the quantization group containing that element.
This equation connects the grouping decision directly to attention quality.
The goal is not simply to reduce average numerical error. We also want to avoid introducing large errors into the channels that matter most to attention.
There is another complication.
Attention uses softmax to convert scores into weights. Softmax involves exponentiation, which can amplify score differences.
If every attention score changes by at most , then the ratio between a reconstructed attention weight and its original weight satisfies:
For example:
- If , the ratio can change by approximately 22% in the worst direction.
- If , the ratio can change by a factor of more than 7.
This explains why quantization errors that look small numerically can still matter to a language model.
The quality of the grouping strategy is therefore just as important as the number of bits used.
6. Why does KIVI group keys and values differently?
This is arguably the most interesting design decision in KIVI.
We know that the cache contains keys and values. We also know that both can be represented as tables containing tokens and channels.
But KIVI does not group both tables in the same direction.
- Keys are grouped along tokens, keeping each channel separate.
- Values are grouped along channels, keeping each token separate.
Let's understand why.
Figure 4. KIVI's two grouping strategies. The diagram uses groups of four elements for readability, while the default implementation uses a group size of 32.
6.1 Why keys benefit from per-channel grouping
Imagine a table containing 128 channels.
You might expect the values in those channels to have similar numerical ranges. In practice, this is often not the case.
Some channels can consistently contain much larger values than others.
These unusually large channels are commonly called outlier channels.
Consider a simplified example:
| Channel | Typical values |
|---|---|
| Channel 1 | 0.1, 0.2, 0.3 |
| Channel 2 | 0.2, 0.1, 0.4 |
| Channel 3 | 15.0, 18.0, 20.0 |
| Channel 4 | 0.1, 0.3, 0.2 |
Channel 3 has much larger values than the other channels.
Now imagine quantizing all four channels together.
The quantization grid must cover the entire range, including the large values in Channel 3.
As a result, the small values in the other channels may end up being represented by the same one or two grid points.
Much of their original information is lost.
This is the problem KIVI avoids by grouping keys per channel.
Instead of combining values from different channels, it groups consecutive tokens within each individual channel.
Each channel gets its own minimum, maximum, and quantization scale.
A large value in one channel therefore does not determine the quantization range of another channel.
Do real language models actually have this problem?
We investigated the distribution of key and value magnitudes in two real models.
We collected keys and values while processing 640 tokens of text and measured the root-mean-square magnitude of every channel.
The following figure shows the measurements for one attention head in Llama-3.2-1B.

Figure 5. Root-mean-square magnitude of each of the 64 channels in layer 8, head 0 of Llama-3.2-1B, divided by the median channel magnitude. Keys show more prominent outlier channels than values.
We then calculated the ratio between the loudest channel and the median channel across all layers and heads.
| Model | Key ratio | Value ratio |
|---|---|---|
| Llama-3.2-1B (4-bit weights) | 5.3 | 2.2 |
| Qwen3-4B (4-bit weights) | 8.1 | 2.4 |
The pattern is clear.
Keys have considerably more variation across channels than values in these two models.
This provides a statistical reason for KIVI's decision to group keys per channel.
6.2 A controlled experiment: what happens when outliers are introduced?
To isolate the effect of outlier channels, we created a synthetic dataset.
It contained:
- 256 tokens.
- 128 channels.
- Normally distributed noise with unit variance.
- Three channels whose values were multiplied by 25.
We then compared two strategies:
- Per-channel grouping, which is KIVI's approach for keys.
- Per-token grouping, which combines values from different channels in the same token.
Importantly, we calculated the reconstruction error only on the 125 normal channels. We did not allow the three artificially enlarged channels to dominate the measurement.
The results were averaged over five random seeds.
| Precision | Per-channel (KIVI) | Per-token | Without outliers: per-channel / per-token |
|---|---|---|---|
| 2-bit | 0.154 | 2.54 | 0.154 / 0.153 |
| 4-bit | 0.0061 | 0.208 | 0.0061 / 0.0060 |
The normal channels have a variance of 1.
At 2-bit precision, per-token grouping produces an error of 2.54, which is larger than the variance of the original signal.
Per-channel grouping avoids that problem because the outlier channels no longer share their quantization ranges with the normal channels.
An especially interesting observation is what happens when we remove the outliers.
Without them, the two grouping strategies produce nearly identical errors.
This shows that the large difference in the first experiment comes from the outlier channels rather than an inherent advantage of one mathematical operation over the other.
6.3 What happens with real keys and values?
Synthetic experiments are useful because we control the data. But we also need to check whether the same behaviour appears in actual model tensors.
We compared per-channel and per-token grouping using keys and values collected from Llama-3.2-1B and Qwen3-4B.
The metric was relative reconstruction error:
A value of zero would mean perfect reconstruction. Smaller values indicate less information loss.

Figure 6. Reconstruction error at 2-bit precision for different grouping strategies. The comparison includes synthetic keys and real keys and values from the two models.
The numerical results are:
| Model and precision | Keys: per-channel / per-token | Values: per-channel / per-token |
|---|---|---|
| Llama-3.2-1B, 2-bit | 0.196 / 0.463 | 0.360 / 0.422 |
| Llama-3.2-1B, 4-bit | 0.039 / 0.093 | 0.072 / 0.084 |
| Qwen3-4B, 2-bit | 0.227 / 0.500 | 0.366 / 0.420 |
| Qwen3-4B, 4-bit | 0.045 / 0.098 | 0.073 / 0.083 |
For keys, the advantage is substantial.
Per-channel grouping reduces the reconstruction error by more than half in these measurements.
However, there is an unexpected result.
Per-channel grouping also produces slightly lower reconstruction error for values.
If that is the case, why does KIVI group values per token instead?
This is where we need to look beyond reconstruction error.
6.4 Why lower reconstruction error does not always mean better model quality
A quantization method can reconstruct individual values accurately without necessarily producing the best attention output.
Remember the attention equation:
The model does not use every value vector equally.
Some tokens receive high attention weights, while others contribute very little.
The grouping strategy determines which other values influence the quantization range of a particular value.
With per-token grouping, the values belonging to one token share their quantization parameters. This keeps the quantization decision local to that token.
With per-channel grouping, values from neighbouring tokens influence the same quantization range.
That distinction matters because different tokens contribute differently to the attention output.
To investigate this, we ran a controlled experiment on Llama-3.2-1B.
We tested all four possible combinations:
- Keys per-channel, values per-token: KIVI.
- Keys per-token, values per-token.
- Keys per-channel, values per-channel.
- Keys per-token, values per-channel.
Instead of comparing only reconstruction error, we measured the model's next-token loss.
Next-token loss measures how surprised the model is by the actual next token in the text. Lower values indicate that the model assigns a higher probability to the correct token.
We used identical input text for every configuration. This is important because it allows us to isolate the effect of the cache rather than differences in generated text.

Figure 7. Additional next-token loss compared with an FP16 cache. The evaluation used three texts, 128 decoded tokens per text, and a residual window of 128 tokens. The two panels use different scales.
Here are the results:
| Keys / values | Extra loss, 2-bit | Same top token, 2-bit | Extra loss, 4-bit | Same top token, 4-bit |
|---|---|---|---|---|
| Channel / token (KIVI) | +0.544 | 66.7% | +0.015 | 94.5% |
| Token / token | +1.825 | 45.1% | +0.029 | 91.1% |
| Channel / channel | +1.970 | 41.9% | +0.046 | 91.1% |
| Token / channel | +3.497 | 24.5% | +0.041 | 88.0% |
KIVI's original grouping strategy performs best at both precision levels.
The value result is especially interesting.
Per-channel grouping produced slightly lower average reconstruction error for values, but per-token grouping produced better next-token predictions.
This illustrates a broader lesson in model compression:
The smallest numerical reconstruction error is not necessarily the configuration that preserves model behaviour best.
The original KIVI paper reports a similar ordering in its own experiments.
For example, its Table 1 evaluates Llama-2-13B on CoQA with 2-bit quantization and every token quantized. The keys-per-channel and values-per-token configuration scores 63.53, compared with 66.37 for FP16. The configuration using per-token grouping for both keys and values scores 52.93, while the two configurations using per-channel values fall below 3.
These are results reported by the original paper, not measurements from VeloxQuant-MLX.
7. Why does KIVI keep recent tokens in higher precision?
There is another important observation about language models.
The newest tokens can have a strong influence on what the model generates next.
For example, consider a conversation where the user has just asked a question. The words in the latest part of the conversation may be particularly relevant to the next response.
If we aggressively quantize these recent tokens, we risk introducing errors into information that the model is currently using heavily.
KIVI addresses this by keeping a portion of the newest cache in its original precision.
This portion is called the residual window.
You can think of it as a protected region of the cache.
Older tokens become eligible for quantization, while the newest tokens remain untouched.
How does the residual window work?
VeloxQuant uses a parameter called residual_length.
Its default value is 128.
This means that the implementation aims to keep at least 128 recent tokens outside the quantized region.
There is another parameter:
kivi_group_size
Its default value is 32.
This controls how many elements are grouped together during quantization.
The quantization boundary is calculated using:
Where:
- is the total number of tokens in the cache.
- is the residual window length.
- is the group size.
- is the quantization frontier.
- The floor operation rounds down to the nearest whole number.
The frontier tells us how many tokens at the beginning of the cache have already been quantized.
Everything after that boundary remains in the higher-precision region.
Why does the implementation wait for complete groups?
Suppose the residual window is 128 tokens and the group size is 32.
Once enough tokens accumulate beyond the residual window, the implementation quantizes a complete group of 32 tokens.
It does not quantize one token at a time.
Why?
Because KIVI groups keys across the token dimension.
If we quantized a single token in isolation, its group would contain only one value for each channel. The minimum and maximum would therefore be identical.
The quantization scale would become zero, and the operation would not provide meaningful compression.
Waiting for a complete group ensures that the quantizer has enough values to calculate a useful range.
It also makes the grouping boundaries consistent whether a prompt is processed in one large batch or tokens are fed into the cache individually.
7.1 Following the quantization frontier
Let's use a concrete example.
Assume:
- Residual window: 128 tokens.
- Group size: 32 tokens.
Now imagine adding tokens to an initially empty cache.
| Event | Total tokens | Quantization frontier | Tokens remaining in FP16 region |
|---|---|---|---|
| Initial prefill: 100 | 100 | 0 | 100 |
| Add 60 tokens | 160 | 32 | 128 |
| Add 1 token | 161 | 32 | 129 |
| Add 31 tokens | 192 | 64 | 128 |
| Add 1 token | 193 | 64 | 129 |
Notice that the frontier does not move after every token.
It moves only when another complete group becomes eligible.

Figure 8. How the cache changes as tokens are added. Blue represents tokens that have already passed through quantization. Orange represents tokens that remain in the FP16 region.
There are two practical consequences.
First, short prompts may never be quantized.
If the prompt contains fewer tokens than the residual window, the frontier remains at zero.
For example, a 100-token prompt with a residual window of 128 tokens does not trigger any quantization.
This is important when designing benchmarks. A short-prompt experiment may appear to show that KIVI has no quality impact simply because the quantizer never runs.
Second, the FP16 region is not always exactly 128 tokens.
Because the frontier moves in groups of 32, the number of unquantized tokens can vary between 128 and 159.
This is an expected consequence of waiting for complete groups.
8. How KIVI is implemented inside VeloxQuant-MLX
Now that we understand the algorithm, let's look at the actual implementation.
VeloxQuant-MLX integrates KIVI into the MLX ecosystem used for machine learning on Apple Silicon.
The implementation uses a class called KIVIKVCache.
It inherits from the standard KVCache implementation provided by mlx_lm.
The central operation is:
update_and_fetch
This method is responsible for adding new keys and values, checking whether the quantization frontier has moved, quantizing newly eligible tokens, and returning the cache to the attention mechanism.
The implementation is available in kivi_cache.py.
Here is the simplified core of the method:
def update_and_fetch(self, keys, values):
B, H, S, D = keys.shape
self._shape_bhd = (B, H, D)
k_all, v_all = super().update_and_fetch(keys, values)
new_boundary = self._quantization_boundary()
n_quant_now = new_boundary - self._n_quantized
if n_quant_now > 0:
lo, hi = self._n_quantized, new_boundary
k_q = self._quant_dequant_along(
self.keys[:, :, lo:hi, :], axis=-2
)
v_q = self._quant_dequant_along(
self.values[:, :, lo:hi, :], axis=-1
)
self.keys[:, :, lo:hi, :] = k_q
self.values[:, :, lo:hi, :] = v_q
self._n_quantized = new_boundary
k_all, v_all = (
self.keys[..., : self.offset, :],
self.values[..., : self.offset, :]
)
self._account_bytes(B, H, S, D, n_quant_now)
return k_all, v_all
Let's break down what happens.
8.1 Understanding the workflow line by line
1. Append the new keys and values.
k_all, v_all = super().update_and_fetch(keys, values)
The implementation first calls the parent cache method.
This adds the new token's keys and values to the existing cache and updates the token count.
At this point, the cache contains the complete history, including the newest token.
2. Calculate the new quantization boundary.
new_boundary = self._quantization_boundary()
The method calculates how many tokens are now eligible for quantization.
It uses the residual-window and group-size formula introduced in Section 7.
3. Identify newly eligible tokens.
n_quant_now = new_boundary - self._n_quantized
The implementation does not repeatedly quantize the entire cache.
It only processes tokens that have just crossed the quantization boundary.
This avoids performing the same quantization operation on older tokens multiple times.
4. Quantize keys and values along different axes.
k_q = self._quant_dequant_along(
self.keys[:, :, lo:hi, :], axis=-2
)
v_q = self._quant_dequant_along(
self.values[:, :, lo:hi, :], axis=-1
)
This is where KIVI's asymmetric grouping strategy appears directly in the code.
For keys, axis=-2 selects the token dimension.
For values, axis=-1 selects the channel dimension.
The two operations therefore use different grouping directions.
5. Write the reconstructed values back into the cache.
self.keys[:, :, lo:hi, :] = k_q
self.values[:, :, lo:hi, :] = v_q
The original values are overwritten with their reconstructed approximations.
This is an important implementation detail.
The cache does not retain packed integer codes here. It retains the reconstructed floating-point values.
6. Update the bookkeeping.
self._n_quantized = new_boundary
self._account_bytes(B, H, S, D, n_quant_now)
The implementation records the new frontier and updates its compression accounting.
7. Return the cache.
return k_all, v_all
The method returns the keys and values in the format expected by the existing attention implementation.
The attention mechanism therefore receives ordinary floating-point tensors, but some of their values have already been rounded.
8.2 What happens inside the quantization function?
The main numerical operation is performed by:
_quant_dequant_along
It takes a tensor, chooses an axis, divides the values into groups, quantizes them, reconstructs them, and returns the reconstructed tensor.
Here is the pure-MLX implementation:
x32 = x.astype(mx.float32)
L = x32.shape[axis]
n_groups = (L + gs - 1) // gs
pad = n_groups * gs - L
xm = mx.moveaxis(x32, axis, -1) # Move the grouped axis to the end
if pad:
tail = xm[..., -1:]
xm = mx.concatenate(
[xm, mx.broadcast_to(tail, xm.shape[:-1] + (pad,))],
axis=-1
)
xg = xm.reshape(xm.shape[:-1] + (n_groups, gs))
gmin = mx.min(xg, axis=-1, keepdims=True)
gmax = mx.max(xg, axis=-1, keepdims=True)
scale = mx.maximum(
(gmax - gmin) / self._levels,
self._eps
)
codes = mx.clip(
mx.round((xg - gmin) / scale),
0,
self._levels
)
recon = codes * scale + gmin
recon = recon.reshape(xm.shape)[..., :L]
return mx.moveaxis(recon, -1, axis).astype(x.dtype)
Let's understand the important operations.
Convert the input to FP32.
x32 = x.astype(mx.float32)
The quantization arithmetic is performed using 32-bit floating-point values.
This provides additional precision during the calculations.
The final reconstructed tensor is converted back to the original data type.
Determine how many groups are needed.
n_groups = (L + gs - 1) // gs
This calculates the number of complete groups required to cover the selected dimension.
If the dimension is not evenly divisible by the group size, the final group will contain fewer values than the others.
Handle incomplete groups.
if pad:
tail = xm[..., -1:]
...
The implementation fills the final incomplete group by repeating its last element.
Why repeat the last element instead of adding zeros?
Because adding zeros could change the minimum or maximum of the group and therefore change the quantization scale.
Repeating the last element avoids introducing a new numerical extreme.
Calculate the group minimum and maximum.
gmin = mx.min(xg, axis=-1, keepdims=True)
gmax = mx.max(xg, axis=-1, keepdims=True)
Each group receives its own quantization range.
Calculate the scale.
scale = mx.maximum(
(gmax - gmin) / self._levels,
self._eps
)
The implementation calculates the distance between representable values.
It also applies the minimum scale safeguard to prevent division by zero.
Calculate the integer codes.
codes = mx.clip(
mx.round((xg - gmin) / scale),
0,
self._levels
)
Every number is mapped to the nearest available integer code.
The result is constrained to the valid range.
Reconstruct the values.
recon = codes * scale + gmin
The original approximate floating-point values are reconstructed.
Finally, the tensor is restored to its original shape and data type.
There is an important distinction here.
The intermediate codes, scales, and minimum values exist during the function's execution, but this cache path does not retain them as its persistent representation.
Once the function returns, the cache contains reconstructed floating-point values.
The package also provides a separate KIVIQuantizer interface with encode and decode operations that can expose the quantized codes. The cache implementation described here does not use that interface for persistent cache storage.
8.3 What happens when tokens are removed?
KV caches are not always extended continuously.
Some generation techniques, including speculative decoding and prompt reuse, may remove tokens from the end of a cache.
The KIVI implementation must therefore handle changes to the cache length.
This operation is called trimming.
When the cache is trimmed, the quantization frontier needs to be moved backward to a valid group boundary.
The relevant method is:
def _rollback_frontier(self, new_offset: int) -> int:
gs = self._group_size
new_nq = min(
self._n_quantized,
(max(new_offset, 0) // gs) * gs
)
n_rolled = self._n_quantized - new_nq
self._n_quantized = new_nq
return n_rolled
Consider this example:
| Event | Total tokens | Frontier | Counted as FP16 tail |
|---|---|---|---|
| Initial prefill | 400 | 256 | 144 |
trim(200) | 200 | 192 | 8 |
| Add one token | 201 | 192 | 9 |
There is a subtle limitation here.
Moving the frontier backward does not restore the original floating-point values.
Suppose tokens 192 to 199 were already quantized when the frontier was at 256.
After trimming, these tokens are counted as part of the unquantized tail, but their numerical values have already been rounded.
The implementation does not have the original values available to reverse that operation.
If these tokens are quantized again during a later flush, they may undergo another round of approximation.
This means that immediately after certain large trims, some tokens inside the nominal residual window may no longer contain their original FP16 values.
It is an important edge case to consider when evaluating cache reuse and speculative decoding.
9. Accelerating quantization with custom Metal kernels
The pure-MLX implementation is relatively straightforward.
However, it performs several operations that create temporary arrays:
- Moving tensor axes.
- Padding incomplete groups.
- Reshaping the tensor.
- Calculating group minima and maxima.
- Computing quantization codes.
- Reconstructing the values.
Each operation has its own computational and memory-management cost.
For larger caches, we wanted to reduce this overhead.
Because VeloxQuant-MLX targets Apple Silicon, we can use Apple's Metal GPU programming framework.
Metal allows us to write lower-level GPU kernels that process the tensors directly.
Instead of expressing the entire operation as a sequence of high-level MLX operations, we can implement the quantization logic in a more specialized way.
VeloxQuant uses two custom Metal kernels:
- A key quantization kernel.
- A value quantization kernel.
Why two kernels?
Because keys and values use different grouping directions, and their memory-access patterns are therefore different.
Understanding the memory layout
The cache is stored in row-major order.
For one token, the channel values are next to each other in memory.
For example:
Token 1: [C1, C2, C3, C4, ...]
Token 2: [C1, C2, C3, C4, ...]
Token 3: [C1, C2, C3, C4, ...]
The channels belonging to one token are contiguous.
However, the same channel across consecutive tokens is separated by the full channel dimension.
This difference determines how the GPU threads should access the data.
Figure 9. The two GPU execution strategies. The key kernel assigns complete vertical groups to individual threads, while the value kernel uses a group of cooperating SIMD lanes to process adjacent values.
9.1 The key kernel: one thread handles one complete group
For keys, the quantization group runs vertically through the token dimension.
That means the elements belonging to one group are separated in memory.
The implementation assigns one GPU thread to an entire group.
Here is the relevant part of the kernel:
const uint base = bh * S * DHEAD + d; // This thread's channel
float gmin = INFINITY;
float gmax = -INFINITY;
for (uint s = s0; s < s1; ++s) {
// Walk through consecutive tokens
float v = float(x[base + s * DHEAD]);
gmin = min(gmin, v);
gmax = max(gmax, v);
}
Let's understand what happens.
Each thread is responsible for a particular channel.
It starts with the largest possible minimum and the smallest possible maximum.
It then walks through the relevant tokens and updates the minimum and maximum values.
After completing the loop, the thread has everything required to quantize its group.
There is another useful property.
Neighbouring threads process neighbouring channels.
Although each thread moves vertically through the token dimension, neighbouring threads still access nearby memory addresses at each iteration.
This helps the GPU perform memory operations efficiently.
Because each thread owns its complete group, threads do not need to communicate with one another to calculate the minimum and maximum.
9.2 The value kernel: one SIMD group handles one quantization group
Values use the opposite grouping direction.
A value group contains consecutive channels from a single token.
These values are already adjacent in memory.
This makes them suitable for cooperative processing using a SIMD group.
A SIMD group contains 32 threads, called lanes, that execute together.
Each lane processes one element and calculates its local minimum and maximum.
The lanes then combine their results using shuffle operations.
Here is the relevant part:
for (uint off = 16u; off > 0u; off >>= 1u) {
gmin = min(
gmin,
simd_shuffle_xor(gmin, off)
);
gmax = max(
gmax,
simd_shuffle_xor(gmax, off)
);
}
What does this loop do?
It performs a reduction across the 32 lanes.
Each lane exchanges information with another lane at an increasing level of distance.
The offsets are:
16 → 8 → 4 → 2 → 1
After five steps, every lane has access to the minimum and maximum across the complete group.
This is an efficient way to calculate shared quantization parameters without requiring separate global-memory operations.
9.3 Why must both kernels produce exactly the same result?
A custom GPU implementation should not silently change the mathematical behaviour of the original implementation.
We therefore require the Metal kernels to produce bit-for-bit identical reconstructed outputs compared with the pure-MLX path.
There are three important details.
| Implementation detail | Why it matters |
|---|---|
Round half values to even using rint, rather than metal::round | Different rounding rules can produce different integer codes for values exactly halfway between grid points |
| Keep multiplication and addition as separate operations | Compiler fusion can change the final floating-point rounding |
| Repeat the last element when padding incomplete groups | Padding with another value can change the group minimum or maximum |
The floating-point detail is particularly important.
Consider the reconstruction:
If the compiler combines multiplication and addition into one fused operation, it may produce a slightly different result because the intermediate rounding behaviour changes.
For ordinary applications, that difference may be harmless.
But when we want two implementations to produce exactly the same output, it matters.
Because the Metal kernels preserve the same numerical behaviour, enabling them changes the execution speed rather than the algorithm's output.
If a Metal kernel raises an error, the implementation can fall back to the MLX path for the remaining lifetime of that cache instance.
9.4 How much faster are the Metal kernels?
We benchmarked the Metal and MLX paths using random FP16 tensors.
The configuration was:
- Batch size: 1.
- Attention heads: 8.
- Head dimension: 128.
- Quantization precision: 2 bits.
We interleaved measurements of the two implementations and compared their median execution times.
| Tokens quantized | Key kernel speed-up | Value kernel speed-up | Output identical |
|---|---|---|---|
| 32 | 1.19× | 1.61× | Yes |
| 512 | 2.77× | 1.94× | Yes |
| 2,048 | 4.38× | 3.28× | Yes |
The results suggest that the custom kernels become increasingly useful as the amount of data grows.
For a small group, the overhead of launching and coordinating GPU work limits the benefit.
For larger groups, the specialized implementation can process the data more efficiently.
However, benchmark timings vary between runs.
A separate run of the repository's benchmark test on the same day produced:
| Tokens | Key speed-up | Value speed-up |
|---|---|---|
| 32 | 1.30× | 1.52× |
| 2,048 | 3.26× | 3.45× |
Our kernel benchmark post also measured 1.40× and 5.65× speed-ups for keys and values together.
The practical interpretation is that the kernels provide a modest improvement for small groups and potentially several times faster execution for larger groups.
But an important question remains:
Does making quantization faster make the entire language model generate text faster?
We will answer that in Section 12.
10. Understanding the compression ratio: estimated bytes versus actual memory
This section is particularly important because compression numbers can be misleading if we do not understand how they are calculated.
When VeloxQuant reports an effective KIVI compression ratio, it estimates how much memory a packed KIVI representation would require.
It does not measure a smaller allocation in the current cache.
Let's first calculate the theoretical storage requirement.
10.1 How many bits does a quantized value actually need?
At first glance, 2-bit quantization appears to require only two bits per value.
But there is an additional storage cost.
Each quantization group needs its own:
- Minimum value, or zero point.
- Scale.
In our storage estimate, both are represented as FP16 values.
Each therefore requires 16 bits.
Together, the two parameters require 32 bits per group.
If a group contains values, the parameter overhead per value is:
The total number of bits required per quantized element becomes:
For KIVI's default group size of 32:
This gives us:
| Quantization bits | Code bits | Parameter overhead per element | Total bits per element | Theoretical maximum ratio versus FP16 |
|---|---|---|---|---|
| 2 | 2 | 1 | 3 | 5.33× |
| 3 | 3 | 1 | 4 | 4.00× |
| 4 | 4 | 1 | 5 | 3.20× |
Notice something important.
Even though the quantized values use only 2 bits each, the zero point and scale add another bit per element when the group size is 32.
That means the effective representation requires 3 bits per element, not 2.
The maximum theoretical ratio against FP16 is therefore:
This assumes every token is quantized and does not account for additional alignment or implementation overhead in a real storage format.
10.2 How does the residual window affect compression?
Remember that the newest tokens remain in FP16.
This means we cannot calculate the compression ratio by considering only the quantized portion.
We must also account for the unquantized tail.
Let:
- be the total number of tokens.
- be the number of quantized tokens.
- be the quantization bit width.
- be the group size.
The estimated compression ratio is:
The numerator represents the original FP16 storage requirement.
The denominator represents the estimated packed storage requirement, including the quantization parameters and the FP16 residual window.
This formula assumes that the relevant dimension is compatible with the group size and that the stated metadata overhead applies.
A worked example
Let's calculate the estimated compression ratio for:
- Total tokens: 2,048.
- Residual window: 128.
- Group size: 32.
- Precision: 2 bits.
The quantization frontier is:
The remaining 128 tokens stay in FP16.
At 2-bit precision with a group size of 32, each quantized element requires an estimated 3 bits.
Therefore:
The cache reports approximately 4.20×.
We verified the formula against effective_compression_ratio across 18 combinations of sequence length and residual-window size. The difference was zero in those comparisons.
The formula also reproduces several committed benchmark estimates:
| Model | Context length | Precision | Residual window | Estimated ratio |
|---|---|---|---|---|
| Qwen3-8B, long prompt | 2,358 | 4-bit | 32 | 3.05× |
| Qwen3-8B, short prompt | 351 | 4-bit | 32 | 2.29× |
| Llama-3.2-3B | 2,360 | 2-bit | 32 | 4.84× |
These values describe the estimated packed representation.
They should not be interpreted as actual memory savings in the default cache.
An important warning about key-only compression numbers
The benchmark scripts also report a separate key-compression figure.
That measurement compares:
- The estimated packed storage for quantized keys.
- The FP16 storage for all keys.
The exact tail is excluded from one side of that comparison.
This can produce numbers that appear to exceed the theoretical maximum.
For example, the Qwen3-8B short-prompt benchmark reports a 3.90× key-only ratio at 4 bits, even though the theoretical maximum for a fully quantized 4-bit representation with the assumed metadata is 3.20×.
The reason is the inconsistent treatment of the unquantized tail.
For meaningful comparisons, use the full key-and-value compression ratio that accounts for the residual window.
10.3 Does the default cache actually use less memory?
Now we come to the most important practical limitation.
We built a cache containing:
- 16 layers.
- 8 attention heads.
- A head dimension of 64.
- 4,096 tokens of random data.
This matches the cache shape used for our Llama-3.2-1B-style measurement.
We then compared the active memory usage of a standard FP16 cache with a KIVI cache using 2-bit quantization.

Figure 10. Actual active memory compared with the theoretical packed-storage estimate. The standard FP16 cache and current KIVI cache occupy the same amount of memory.
The measurements were:
| Cache configuration | Measured or estimated memory |
|---|---|
Standard KVCache, measured | 134,217,736 bytes |
KIVIKVCache at 2 bits, measured | 134,217,736 bytes |
KIVIKVCache at 2 bits, packed estimate | 28,573,696 bytes |
The result is unambiguous.
The standard cache and the default KIVI cache consume exactly the same amount of active memory in this experiment.
Why?
Look back at the implementation in Section 8.
After quantization, the reconstructed values are written back into the same FP16 cache buffer.
A number does not occupy less memory simply because its numerical value has been rounded.
For example, an FP16 representation still occupies 16 bits whether the value is:
- 0.123456 before quantization.
- 0.125 after quantization.
The numerical precision has changed, but the storage format has not.
This is why we distinguish between two things throughout this article:
- Quantization effect: The values have been rounded to a lower-precision grid.
- Memory compression: The original floating-point values have been replaced with a genuinely smaller packed representation.
The default cache implements the first, not the second. The opt-in packed storage described in Section 15 implements both.
That distinction is essential when interpreting the benchmark results.
11. How to use KIVI in VeloxQuant-MLX
If you want to experiment with KIVI yourself, VeloxQuant-MLX provides an integration through its cache configuration and builder interfaces.
Here is a minimal example:
import mlx_lm
from veloxquant_mlx import KVCacheConfig, KVCacheBuilder
model, tokenizer = mlx_lm.load(
"mlx-community/Llama-3.2-1B-Instruct-4bit"
)
config = KVCacheConfig(
method="kivi",
bit_width_inlier=4, # Default is 2
kivi_group_size=32,
residual_length=128,
)
cache = KVCacheBuilder.for_model(model, config)
prompt = (
"Explain in two sentences why a KV cache "
"grows during generation."
)
text = mlx_lm.generate(
model,
tokenizer,
prompt=prompt,
max_tokens=200,
prompt_cache=cache
)
print(text)
layer = cache[0]
print(
"tokens:", layer.offset,
"frontier:", layer._n_quantized
)
print(
"accounting estimate: %.2fx"
% layer.effective_compression_ratio
)
Let's understand the configuration.
| Setting | Default | Purpose |
|---|---|---|
bit_width_inlier | 2 | Number of bits used for quantized values |
kivi_group_size | 32 | Number of elements sharing quantization parameters |
residual_length | 128 | Number of recent tokens protected from quantization |
use_metal_kernels | auto | Controls whether custom Metal kernels are used |
A few practical details are worth mentioning.
Start with 4-bit precision.
Our experiments found that 4-bit precision preserved model behaviour much better than 2-bit precision on the tested model.
Two-bit precision is useful for studying the algorithm, but it introduces substantial prediction differences.
Pass the cache using prompt_cache.
In the version of mlx_lm used for these experiments (0.32.2), mlx_lm.generate rejects a kv_cache argument. The example therefore uses prompt_cache.
Use a separate cache for each independent conversation.
A KV cache stores the history passed into it. Reusing the same cache across unrelated conversations can mix their contexts.
Do not interpret the compression estimate as measured memory savings.
For the default cache, the reported ratio describes a potential packed representation, not its FP16 allocation. To actually store the packed form, set kivi_packed_storage=True (Section 15).
What happened in our example?
On our test machine, the example finished with:
- 214 tokens in the cache.
- A quantization frontier of 64.
- An estimated compression ratio of 1.26×.
This is a useful reminder that short conversations may not produce significant compression estimates.
With a residual window of 128 tokens, much of a short interaction remains in the higher-precision region.
12. What happens to speed and model quality?
Implementing a quantizer is only one part of the problem.
Ultimately, we want to understand what happens when the model actually uses the modified cache.
There are two questions:
- Does KIVI improve or reduce end-to-end generation performance?
- How much does quantization affect the model's predictions?
These questions require different measurements.
12.1 Does faster quantization make text generation faster?
The Metal kernels from Section 9 are faster than the pure-MLX implementation for the quantization operation.
But the quantization operation is only one part of language-model generation.
A typical generation step also involves:
- Running the transformer layers.
- Computing queries, keys, and values.
- Performing attention.
- Applying the model's remaining layers.
- Sampling or selecting the next token.
If quantization accounts for only a small portion of the total execution time, even a large improvement in that operation may have little effect on overall generation speed.
We examined the committed Qwen3-8B benchmark results.
These results were produced using:
- An Apple M4 with 24 GB memory.
- 4-bit KIVI.
residual_length=32.- Five interleaved benchmark repetitions.
They were not re-run specifically for this article.
| Prompt length | Configuration | Median tokens/s | Minimum to maximum | Peak memory |
|---|---|---|---|---|
| 2,238 tokens | FP16 | 5.93 | 5.86–6.81 | 5,226 MB |
| 2,238 tokens | KIVI, Metal off | 5.86 | 5.73–6.29 | 5,355 MB |
| 2,238 tokens | KIVI, Metal on | 5.92 | 5.76–6.16 | 5,274 MB |
The three configurations perform very similarly.
There is no meaningful end-to-end speed improvement in these results.
Why?
The custom kernels make the quantization step faster, but that step represents only a small part of the total generation workload.
Also, because the default cache retains FP16 storage, it does not reduce the memory required by the cache.
The key lesson is that optimizing one operation does not automatically improve the entire application.
A quantization kernel can be several times faster while the overall language model generates text at almost the same speed.
12.2 How should we measure model quality?
This is where benchmarking becomes more complicated.
Suppose we run the same prompt twice:
- Once using a normal FP16 cache.
- Once using a quantized KIVI cache.
Imagine that both models generate the same first few tokens, but at step 5, the quantized version chooses a different token.
From that point onward, the two models are processing different text.
Their caches now contain different histories.
If we compare their outputs after that point, we are mixing together two different effects:
- The numerical error introduced by quantization.
- The divergence caused by the models generating different tokens.
To separate these effects, we use two evaluation strategies.
Teacher-forced evaluation
Both cache configurations receive exactly the same sequence of real tokens.
At every step, the model is asked to predict the next token using the same input history.
This lets us isolate the effect of the cache on the model's predictions.
Free-running evaluation
Each configuration generates its own tokens and continues using its own output.
This measures what happens during actual generation, but it also includes the effects of divergence.
Both approaches are useful, but they answer different questions.
For the main quality experiment, we used:
- Llama-3.2-1B with 4-bit weights.
- Three texts from the repository.
- A 512-token prompt.
- 128 decoded tokens per text.
We also measured a noise floor by comparing an FP16 cache against itself, processing the text in one large batch rather than token by token.
The next-token loss changed by approximately 0.0002 nats at most, and logit cosine similarity remained above 0.9999.
This confirms that the evaluation setup itself introduces very little numerical variation.
12.3 Teacher-forced quality results
We used three measurements.
Logit cosine similarity
The model produces a vector of scores, called logits, for the possible next tokens.
Logit cosine similarity compares the direction of the quantized model's score vector with the FP16 model's score vector.
A value of 1.0 means that the two vectors point in exactly the same direction.
Top-token agreement
This measures how often both cache configurations select the same highest-scoring token.
Next-token loss
This measures how much probability the model assigns to the actual next token in the text.
Lower loss is better.
Here are the results:
| Precision | Mean logit cosine | Same top token as FP16 | Next-token loss (nats) | Additional loss |
|---|---|---|---|---|
| FP16 | 1.000 | 100% | 2.853 | 0 |
| 8-bit | 0.99999 | 100.0% | 2.853 | Within noise |
| 4-bit | 0.9958 | 94.5% | 2.868 | +0.015 |
| 3-bit | 0.980 | 89.6% | 2.914 | +0.061 |
| 2-bit | 0.837 | 66.7% | 3.398 | +0.544 |
The difference between 4-bit and 2-bit precision is significant.
At 4 bits, the additional loss was stable across the three evaluation texts, ranging from +0.014 to +0.015 nats.
At 2 bits, it varied considerably, from +0.16 to +1.00 nats.
This suggests that 2-bit quantization is much more sensitive to the input data in this experiment.

Figure 11. The left panel shows teacher-forced logit cosine similarity across decoding steps, averaged over three texts. The right panel compares teacher-forced and free-running evaluation on a random 64-token prompt with residual_length=32.
The results support a practical recommendation:
Use 4-bit precision as the starting point when exploring the current KIVI implementation.
It introduces a relatively small quality difference in this experiment, whereas 2-bit precision produces substantially more noticeable changes.
This is not a universal guarantee for every model or task. It is a recommendation based on the experiments described here.
12.4 Does quantization error keep increasing with every generated token?
One common concern with low-bit KV-cache quantization is that errors might accumulate over time.
For example, if the cache introduces a small error at every generation step, perhaps those errors become increasingly damaging as the conversation gets longer.
The repository's KIVIKVCache docstring reports a free-running 2-bit experiment where logit cosine similarity falls from 0.95 after the prompt to -0.18 after 64 decoding steps.
It describes this behaviour as compounding error.
We re-ran the repository's script.
In our current run, the similarity at step 64 was 0.31 rather than -0.18. Our independent implementation of the same setup produced the same 0.31 result.
We then compared teacher-forced and free-running evaluation.
| Precision | Free-running cosine at step 64 | Free-running token agreement | First different token | Teacher-forced mean cosine |
|---|---|---|---|---|
| 2-bit | 0.31 | 1.6% | Step 1 | 0.908 |
| 4-bit | 0.33 | 53% | Step 33 | 0.996 |
| 8-bit | 1.00 | 100% | Never | 1.000 |
The 4-bit result is particularly interesting.
Under teacher forcing, its average logit cosine similarity is 0.996 and never falls below 0.98.
Yet in free-running generation, its similarity at step 64 is only 0.33.
Why?
Because the two runs selected different tokens at step 33.
After that point, they were no longer generating from the same history.
The model using the quantized cache continued from its own generated token, while the FP16 model continued from a different token.
The two sequences increasingly diverged.
This means that free-running cosine similarity can measure how far two generated sequences have diverged, rather than directly measuring how much the cache's numerical error has increased.
Our teacher-forced experiments do not show a consistent downward trend in similarity over 128 decoding steps.
However, this does not mean that 2-bit quantization is harmless.
It still changes the top predicted token approximately one-third of the time in our teacher-forced experiment.
Once the first token changes during free-running generation, the model follows a different sequence of inputs and may produce an entirely different response.
The distinction is important:
- Teacher forcing helps us study the direct effect of quantization.
- Free-running evaluation helps us understand the practical consequences for generated text.
Neither measurement should be interpreted as a replacement for the other.
12.5 Why does prompt processing behave differently from token generation?
There is another important implementation detail.
A language model can process its prompt in two broad ways.
Prefill is the stage where the model processes the initial input prompt.
Decode is the stage where it generates subsequent tokens one at a time.
These two stages interact with the KV cache differently.
In the current VeloxQuant implementation, a long prompt can advance the quantization frontier before attention runs.
That means some tokens inside the prompt already use reconstructed, rounded keys and values when attention processes them.
We measured next-token loss over a 640-token prompt processed in one call.
| Cache configuration | Mean next-token loss | Additional loss |
|---|---|---|
| FP16 | 2.921 | 0 |
| KIVI, 4-bit | 2.953 | +0.032 |
| KIVI, 2-bit | 4.259 | +1.338 |
These results show that prompt processing is also affected by the current implementation.
The numbers should not be directly compared with the decoded-token results in Section 12.3 because they represent different evaluation positions and setups.
Why is this difference important?
Because the original KIVI paper describes a different prefill behaviour.
We will examine that implementation difference next.
13. How does VeloxQuant-MLX differ from the original KIVI paper?
It is important to distinguish between implementing the core idea of a research paper and reproducing every detail of its original system.
VeloxQuant-MLX implements KIVI's grouping and quantization approach, but its current cache implementation is not identical to the original paper's execution path.
Here are the main differences.
| Implementation detail | Original KIVI paper | VeloxQuant-MLX KIVIKVCache |
|---|---|---|
| Stored representation | Packed low-bit codes, plus zero points and scales | Reconstructed FP16 values by default; packed codes with kivi_packed_storage=True |
| Attention computation | Custom CUDA routine that dequantizes while performing attention | Standard attention using FP16 tensors |
| Prompt processing | Exact keys and values are passed to the next layers while only the quantized cache is retained | Attention can already see rounded values for older prompt tokens |
| When keys are quantized | When the key buffer reaches the residual threshold, the eligible block is quantized | Whole groups of tokens are quantized after becoming older than the residual window |
| Exact key tail | Between 0 and tokens, averaging approximately | Between and tokens |
| Exact value tail | The newest tokens | Same frontier as keys: between and tokens |
| Zero-point and scale precision | No explicit statement found in the paper | Computed in FP32; storage estimate assumes FP16 metadata |
Why does prompt processing matter?
The paper states that during prefill, the exact key and value tensors are passed to subsequent layers, even though only the quantized KV cache is retained in memory.
Our reading of Algorithm 1 is that attention for the current prompt block also uses the exact tensors.
The current VeloxQuant implementation behaves differently.
When the quantization frontier advances during prompt processing, the rounded values are written back into the cache before the corresponding attention computation uses them.
That means the prompt's attention computation can be affected by quantization.
This helps explain why our 640-token prefill experiment shows a larger quality difference than the teacher-forced decode experiment at the same bit width.
Why does metadata precision matter?
Every quantization group requires a minimum value and a scale.
The current implementation calculates these using FP32 arithmetic.
However, our packed-storage estimate assumes that the parameters are stored using FP16.
A future packed implementation would therefore introduce an additional numerical consideration: the effect of converting the metadata into its actual storage representation.
That error is not included in the default cache's round-trip simulation.
The packed mode in Section 15 avoids it. Instead of a rounded scale, it stores each group's minimum and maximum in the cache's own data type. Both are values taken from the input, so they are exact, and the scale is recalculated from them.
What does the original paper report?
The original KIVI paper reports results from its own implementation on NVIDIA A100 hardware.
Among its reported findings are:
- Up to 2.6× lower peak memory, including model weights.
- Up to 4× larger batch sizes.
- Between 2.35× and 3.47× higher throughput in its reported experiments.
- An average LongBench score of 44.27 for 2-bit KIVI on Llama-2-7B, compared with 44.52 for FP16.
These are results from the original paper.
They are not results from VeloxQuant-MLX.
The hardware, storage representation, attention implementation, and experimental setup are different.
This is why we should not transfer the paper's memory and throughput claims directly to the current VeloxQuant implementation.
14. What have we actually established?
After examining the mathematics, implementation, and experiments, it is useful to separate what our results support from what remains unverified.
14.1 What the experiments support
Our experiments provide evidence for six main conclusions.
1. The min-max quantizer behaves as expected.
The observed reconstruction error stays within the theoretical half-step bound.
The average error on synthetic data also closely matches the approximation:
2. Keys have more uneven channel distributions in the models we tested.
Both Llama-3.2-1B and Qwen3-4B showed substantially larger differences between their highest-magnitude key channels and median channels.
Per-channel grouping reduced key reconstruction error by more than half in our measurements.
3. KIVI's grouping combination preserves model predictions better than the alternatives we tested.
On Llama-3.2-1B, keys-per-channel and values-per-token produced the lowest additional next-token loss at both 2-bit and 4-bit precision.
4. Four-bit precision performs considerably better than two-bit precision in our evaluation.
The additional loss was +0.015 nats at 4 bits and +0.544 nats at 2 bits.
5. The Metal kernels reproduce the MLX output exactly.
They produce bit-identical reconstructed tensors and accelerate the quantization operation, particularly for larger groups.
6. The default cache does not reduce actual cache memory.
It stores reconstructed FP16 values, so its reported compression ratios describe estimated packed storage. The opt-in packed storage in Section 15 does reduce memory.
14.2 What remains unverified?
There are several limitations to the experiments.
| Limitation | Why it matters |
|---|---|
| Quality experiments use one small model | Larger models may tolerate 2-bit quantization differently. The original paper also evaluates larger models. |
| Only three short evaluation texts | Technical Markdown is not representative of every type of language-model workload. The 2-bit results varied significantly between texts. |
| Only 640 tokens in the prefill experiment | We have not established how the implementation behaves over much longer contexts. |
| No downstream task benchmarks | We did not evaluate LongBench, GSM8K, or comparable task-specific benchmarks. |
| Real-tensor statistics use one passage per model | Channel distributions can change depending on the input data. |
| Synthetic data for the error model and outlier experiments | These experiments demonstrate the mechanism but do not establish how frequently the same effects occur across all real workloads. |
| One hardware configuration | Metal performance measurements are specific to this Apple M4 system and can vary across runs. |
| Original paper implementation not independently reproduced | The comparison is based on the published paper and its algorithm description, not a direct execution of the authors' code. |
These limitations are important because a successful experiment on one model does not establish that the same results will hold across every model architecture, context length, or application.
More testing is needed before making broader claims about quality and performance.
15. Real memory savings: packed storage, and what is still missing
When this article was first published, VeloxQuant-MLX had no way to store a KIVI cache in packed form. It does now, as an opt-in setting.
1. Store packed integer codes instead of reconstructed FP16 values (done, opt-in)
By default, the cache performs the following operations:
FP16 values
↓
Quantization
↓
Integer codes
↓
Dequantization
↓
Reconstructed FP16 values
↓
Stored in the cache
With packed storage, it keeps the codes instead:
FP16 values
↓
Quantization
↓
Packed integer codes
+
Minimum and maximum of each group
↓
Stored in the cache
At 2-bit precision, four codes fit inside one byte. The newest tokens stay in FP16, exactly as before.
You enable it with one setting:
config = KVCacheConfig(
method="kivi",
bit_width_inlier=4,
kivi_packed_storage=True,
)
cache = KVCacheBuilder.for_model(model, config)
The output does not change. The packed cache returns the same keys and values as the default cache, bit for bit. In every benchmark run below it generated the same tokens.
We measured an 8,192-token prompt followed by 64 decoded tokens on the same Apple M4, with a residual window of 128. Each figure is the median of three runs, with each cache in its own process:
| Model, bits | Cache | Cache memory held | Peak memory above model weights | Decode tokens/s (range) |
|---|---|---|---|---|
| Llama-3.2-1B, 4-bit | FP16 | 277 MB | 944 MB | 41.4 (32.8–43.8) |
| Llama-3.2-1B, 4-bit | KIVI, default | 277 MB | 932 MB | 38.4 (34.3–41.8) |
| Llama-3.2-1B, 4-bit | KIVI, packed | 88 MB | 603 MB | 20.8 (19.8–23.9) |
| Qwen3-4B, 4-bit | FP16 | 1,246 MB | 1,787 MB | 9.3 (9.0–10.1) |
| Qwen3-4B, 4-bit | KIVI, default | 1,246 MB | 1,776 MB | 8.3 (7.2–9.5) |
| Qwen3-4B, 4-bit | KIVI, packed | 394 MB | 1,085 MB | 5.1 (4.6–6.8) |
| Qwen3-4B, 2-bit | FP16 | 1,246 MB | 1,787 MB | 11.2 (7.8–11.4) |
| Qwen3-4B, 2-bit | KIVI, default | 1,246 MB | 1,776 MB | 12.8 (10.2–14.4) |
| Qwen3-4B, 2-bit | KIVI, packed | 245 MB | 916 MB | 7.7 (7.1–15.7) |
Here "4-bit" and "2-bit" refer to the cache. Both models use 4-bit weights.
The trade-off is clear. The cache is 3.1 to 5.1 times smaller, and peak memory above the weights is 35% to 48% lower than with the default KIVI cache. In exchange, median decoding speed is roughly 40% to 46% lower. Timings on this machine vary considerably, so look at the ranges.
Quality is the same as the default cache at the same bit width, so the quality results in Section 12 apply, including the caution about 2 bits.
A few limitations apply: mlx_lm.server cannot batch requests that use packed storage, it works only with method="kivi", and we have not yet compared it with mlx_lm's built-in quantized cache.
2. Make attention work directly with the packed representation
This is the first thing still missing.
When attention needs to read the keys and values, they must be turned back into numbers. The packed cache currently takes the straightforward approach:
- Read the packed codes.
- Rebuild the whole cache of one layer in FP16, using a custom Metal kernel.
- Run the normal attention operation.
The temporary FP16 tensor is as large as that layer's uncompressed cache. Layers are processed one after another, so their temporary copies are not all needed at once, and peak memory still falls. But it falls much less than the stored cache does: 35% to 48%, against a cache that is 3.1 to 5.1 times smaller.
A better solution is to dequantize values as they are consumed by the attention computation.
In other words, the attention kernel should read the packed representation and reconstruct only the values it needs while performing the attention calculation.
This requires a more specialized attention implementation.
3. Make the complete operation fast enough
This is the second thing still missing. Rebuilding the history on every token is the main reason packed storage decodes more slowly than the default cache.
We have already explored a fused Metal kernel that combines dequantization and attention in a single pass.
However, our correction note reports end-to-end speeds between 0.48× and 0.85× relative to a standard FP16 cache.
In other words, the implementation was slower than the baseline in those measurements.
Our investigation points to an important hardware limitation.
During single-token decoding, the amount of work can be too small to keep the GPU fully occupied.
The kernel may perform the correct operations, but the hardware is not being used efficiently enough to offset the additional work.
This is an open engineering problem.
The goal is not merely to make quantization or dequantization fast in isolation.
We need a complete system that:
- Stores the cache in a genuinely compressed representation (available now, opt-in).
- Performs attention without reconstructing each layer's cache in FP16 (not yet).
- Preserves model quality (unchanged from the default cache).
- Provides competitive generation speed (not yet).
- Works efficiently on Apple Silicon (partly).
None of the remaining requirements is impossible, but each requires significant implementation work.
16. How to reproduce the experiments
Reproducibility is important for this kind of engineering work.
All the measurements created specifically for this article come from one main script:
scripts/plot_kivi_blog.py
The script writes its raw results to:
figures/kivi_blog/results.json
It also generates the figures used throughout the article.
To run the complete experiment:
# Requires Llama-3.2-1B-Instruct-4bit
# and Qwen3-4B-4bit from mlx-community
.venv/bin/python scripts/plot_kivi_blog.py
If you already have the saved results and only want to regenerate the figures:
.venv/bin/python scripts/plot_kivi_blog.py --plots-only
Run the packed-storage benchmark
The measurements in Section 15 come from a separate script, with raw results in figures/kivi_packed/:
.venv/bin/python benchmark_scripts/benchmark_kivi_packed.py \
--model mlx-community/Qwen3-4B-4bit --bits 4 --prompt-tokens 8192
Run the KIVI unit tests
The KIVI test suite includes tests for:
- Quantization and reconstruction.
- Cache behaviour.
- Frontier management.
- Metal kernel correctness.
The command is:
.venv/bin/python -m pytest \
veloxquant_mlx/tests/quantizers/test_kivi.py \
veloxquant_mlx/tests/cache/test_kivi_cache.py \
veloxquant_mlx/tests/metal/test_kivi_quant.py -q
At the time of this evaluation, all 92 tests passed.
Run the Metal kernel benchmark
To reproduce the repository's kernel benchmark:
.venv/bin/python -m pytest \
"veloxquant_mlx/tests/metal/test_kivi_quant.py::test_kivi_quant_benchmark" \
-s -q
Reproduce the free-running quality experiment
The free-running evaluation discussed in Section 12.4 can be run using:
.venv/bin/python scripts/kv_bookkeeping_e2e_bench.py \
--output /tmp/kv_e2e.json
Experimental environment
All the experiments were conducted using the following environment:
| Component | Configuration |
|---|---|
| Hardware | Apple M4 |
| Unified memory | 24 GB |
| Operating system | macOS 26.6.2 |
| MLX | 0.32.4 |
| mlx_lm | 0.32.2 |
| VeloxQuant-MLX | 0.96.1 |
| Commit | 4c0ad8c |
The three evaluation texts used for the main quality experiments were:
README.mdCHANGELOG.md- The
mlx_lmintegration guide.
Changing these files can slightly change the quality measurements because the model is evaluated on different input sequences.
The Qwen3-8B end-to-end speed results in Section 12.1 and the Qwen3-8B and Llama-3.2-3B compression estimates in Section 10.2 come from previously committed benchmark results under figures/.
This distinction matters when reproducing the article: not every result was measured again during the preparation of this particular experiment.
17. Conclusion: What did we learn from implementing KIVI?
KIVI is built around a relatively simple idea.
Instead of storing every key and value using full FP16 precision, divide them into groups and represent those groups using a smaller set of numerical values.
But the interesting part is how those groups are selected.
For keys, group values across tokens while keeping each channel separate.
This prevents unusually large channels from forcing other channels to use unnecessarily coarse quantization ranges.
For values, group channels within individual tokens.
Although this does not always minimize raw reconstruction error, it preserves the attention output more effectively in the experiments we conducted.
Keep the newest tokens in higher precision.
A residual window protects recent information from immediate quantization and allows the algorithm to process complete groups.
These decisions are supported by our experiments on real model tensors and next-token predictions.
However, the implementation also highlights an important distinction between demonstrating a quantization algorithm and building a practical memory-compression system.
What works today?
VeloxQuant-MLX currently provides:
- A deterministic implementation of KIVI's min-max quantization and reconstruction.
- Different grouping strategies for keys and values.
- Residual-window and quantization-frontier management.
- Integration with the MLX KV-cache interface.
- Custom Metal kernels for both key and value quantization.
- Bit-identical outputs between the Metal and pure-MLX paths.
- Opt-in packed storage that reduces cache memory without changing the output.
- Measurements of numerical error, model quality, and execution performance.
What does not work yet?
The default cache still stores reconstructed values as FP16, so its compression ratios describe a potential packed representation, not the memory it occupies.
Packed storage fixes that, but it decodes more slowly, and it still rebuilds each layer's cache in FP16 for attention.
We also found that 2-bit precision introduces significant prediction differences in our Llama-3.2-1B experiments, while 4-bit precision produces substantially smaller differences.
Finally, making the quantization operation faster does not automatically make the complete language model faster. End-to-end performance depends on the interaction between cache management, attention, GPU utilisation, and the rest of the model.
Our practical recommendation
If you want to experiment with KIVI in VeloxQuant-MLX:
- Start with 4-bit precision rather than immediately choosing 2 bits.
- Use a residual window appropriate for your context length.
- Make sure your evaluation prompt is long enough to trigger quantization.
- Use teacher-forced evaluation when measuring the direct impact on model quality.
- If memory is what limits you, try
kivi_packed_storage=Trueand check that the slower decoding is acceptable. Measure actual memory rather than relying on the default cache's estimate. - Compare end-to-end generation speed rather than relying only on isolated kernel benchmarks.
The broader lesson is that model compression involves more than reducing the number of bits used to represent a tensor.
A successful implementation needs to preserve the information that matters to the model, use memory efficiently, and perform well on the hardware where it runs.
That is what makes KV-cache quantization an interesting engineering problem, particularly for local AI systems running on consumer hardware.
KIVI gives us a promising approach. VeloxQuant-MLX gives us a way to investigate it on Apple Silicon, and now to save real memory with it. Making that fast is the next step.
References and further reading
1. KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
Zirui Liu, Jiayi Yuan, Hongye Jin, Shaochen Zhong, Zhaozhuo Xu, Vladimir Braverman, Beidi Chen and Xia Hu. ICML 2024.
Read the original research paper (arXiv:2402.02750).
2. Original KIVI implementation
The reference implementation released by the paper's authors.
Explore jy-yuan/KIVI on GitHub.
3. KIVI in VeloxQuant-MLX
Explore the implementation and its integration into the project.
4. A 5.65× Metal Kernel That Made My LLM Exactly 0% Faster
A closer look at the custom Metal kernels, their isolated performance improvements, and why those improvements did not translate into faster end-to-end generation.
Read the Metal kernel benchmark post.
5. Qwen3-8B KIVI benchmark
The benchmark results used for the end-to-end speed comparison in Section 12.1.
