# Integers and quantization

> Why Pearl mines with whole numbers from −64 to 64, why noisy entries fit a byte and sums never overflow 32 bits, and how AI numbers are squeezed to 7 bits.

Source: https://pearlcodex.com/technical/math/integers-and-quantization/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

Pearl’s mining multiplies matrices of small whole numbers, between −64 and 64. Not fractions, not big numbers.

That choice does three jobs at once. Whole numbers make the arithmetic exact, so everyone agrees on every bit. Small ones fit in a single byte, even after noise is added, so GPUs can use their fastest circuits. And their sums fit comfortably in 32 bits, so nothing ever overflows.

## Why whole numbers and not fractions?

Because a mining ticket must come out identical on every computer that checks it.

Computers store fractions as floating-point numbers, which round after every operation. Add the same numbers in a different order and the last digits can differ. A GPU, a CPU and a proof circuit would sometimes disagree, and the ticket, a hash, would change completely.

Integer arithmetic has no rounding. 3 × (−4) + 7 is −5 on every machine, in any order. So Pearl’s rules define the work in integers: small inputs that fit in a byte, 32-bit running sums. The format is named in every certificate: Int7 × Int7 → Int32.

## What are the ranges, exactly?

_The ranges on one number line. Entries from −64 to 64 plus noise from −63 to 63 can reach ±127, which still fits a signed byte (−128 to 127)._

| Numbers                              | Range                  | Stored as                     |
| ------------------------------------ | ---------------------- | ----------------------------- |
| Entries of A and B                   | \[−64, 64], 129 values | one signed byte each          |
| Noise factors (the “thin” part)      | \[−32, 31]             | 6-bit random numbers          |
| Noise added to A and B               | \[−63, 63]             | one signed byte               |
| Noisy entries A′ = A + E, B′ = B + F | \[−127, 127]           | one signed byte (int8)        |
| Running sums of products             | far inside ±2³¹        | 32-bit signed integer (int32) |

The first row is enforced twice. The plain check a pool runs on a winning share rejects any revealed entry outside \[−64, 64], and the zero-knowledge circuit that every node verifies has the same range check built in. The noise ranges come from how the noise is built, on the [rank and noise](https://pearlcodex.com/technical/math/rank-and-noise/) page.

> **Note: Int7, not INT8**
>
> You’ll often read that Pearl mining is “INT8”. The inputs are actually 7-bit-plus-one: 129 values from −64 to 64. Only the noisy matrices use the full 8-bit range, which is what the GPU’s int8 tensor cores multiply.

## Why can’t the sums overflow?

A 32-bit signed integer holds values up to 2,147,483,647. Check the worst case:

$$
|A'_{il} \cdot B'_{lj}| \le 127 \times 127 = 16{,}129
$$

$$
\Big|\sum_{l=0}^{k-1} A'_{il} B'_{lj}\Big| \;\le\; 16{,}129 \times 65{,}536 \;=\; 1{,}057{,}030{,}144 \;<\; 2^{31} - 1
$$

_k is at most 2¹⁶ = 65,536 by consensus rule, so even the most extreme sum uses less than half of int32’s range._

So the GPU can accumulate a whole dot product in 32-bit registers without ever checking for overflow. This is one reason k has an upper limit at all.

**Make a guess:** If entries could go all the way to ±127 before noise, what range would the noisy entries need?

**Answer:** ±190, which no longer fits in a byte.

127 + 63 = 190, beyond int8’s 127. The noisy matrices would need a wider format, and the GPU would lose its fast 8-bit integer mode. Capping entries at 64 keeps the noisy matrices in one byte.

## What is quantization?

AI models are trained with fractional numbers, usually 16-bit floating point. [Quantization](https://pearlcodex.com/glossary/#quantization) squeezes them into a few integer levels, with a scale factor to convert back.

The common symmetric method: find the largest magnitude in a row, divide it into 63 steps, and round each number to the nearest step.

> **Scenario · made-up numbers: Quantizing five activations to 7 bits**
>
> Take a token’s activations 0.82, −1.37, 0.04, 2.10 and −0.66 (made-up numbers).
>
> 1. The largest magnitude is 2.10, so the scale is 2.10 ÷ 63 ≈ 0.0333.
> 2. Divide by the scale and round: 24.6 → **25**, −41.1 → **−41**, 1.2 → **1**, 63 → **63**, −19.8 → **−20**.
> 3. To convert back, multiply by the scale: 0.833, −1.367, 0.033, 2.100, −0.667.
>
> The integers are what get multiplied. The small errors (0.82 became 0.833) are the price of speed.

Pearl’s official miner does this inside vLLM. In mining mode, each token’s activations are quantized to 7 bits, \[−63, 63], with one scale per token. The weights were quantized ahead of time, with one scale per output channel. After the integer multiplication and [denoising](https://pearlcodex.com/technical/mining/useful-output/), the result is multiplied by both scales and written back as 16-bit floating point, the layer’s normal output.

Pearl Research Labs describe this setup as W7A7 (7-bit weights and activations), prepared with the GPTQ and SmoothQuant methods. Their whitepaper reports Llama-3.3-70B accuracy scores (MMLU) of 0.8198 for the original 16-bit model and 0.8190 to 0.8198 for Pearl-certified runs: little or no loss on that test.

## How does the ticket read a negative sum?

As raw bits. Every 128 steps the miner XORs a tile’s running sums together into one 32-bit word, and XOR works on bits, not on values. A negative sum is read in [two’s complement](https://pearlcodex.com/glossary/#twos-complement).

In Pearl’s toy example, a tile’s first four running sums are 6, 1, −66 and 10:

| Sum                 | 32-bit pattern (hex) |
| ------------------- | -------------------- |
| 6                   | `00000006`           |
| 1                   | `00000001`           |
| −66                 | `ffffffbe`           |
| 10                  | `0000000a`           |
| **XOR of all four** | **`ffffffb3`**       |

That word is what goes into the ticket’s diary. See [tickets and target](https://pearlcodex.com/technical/mining/tickets-and-target/).

**Code: the range check and the casts**

The plain check of a share, which a pool or gateway runs, rejects any revealed entry outside the range in [`verify.rs`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/zk-pow/src/api/verify.rs#L114-L119) (the zero-knowledge circuit that nodes verify enforces the same range):

`zk-pow/src/api/verify.rs`

```rust
// Verify all strip values are in [-64, 64] (matching the ZK circuit's IRANGE7P1 range check)
for strip in private_params.s_a.iter().chain(private_params.s_b.iter()) {
    for &val in strip {
        ensure!((-64..=64).contains(&val), "Matrix value {} out of range [-64, 64]", val);
    }
}
```

In the tile loop, entries are widened to `i32` before multiplying, and the sums are reinterpreted as `u32` for the XOR (`x as u32`), exactly the two’s-complement reading above.

## In short

- Pearl mines with whole numbers, not fractions, so every computer gets bit-for-bit identical running sums.
- Matrix entries are limited to \[−64, 64] (Pearl calls the format Int7). The noise adds at most ±63, so noisy entries land in \[−127, 127] and still fit in one signed byte.
- Each product is at most 127² = 16,129 in size, and k is at most 65,536, so a running sum never exceeds 1,057,030,144: safely inside a 32-bit integer.
- Quantization squeezes an AI model’s fractional numbers into small integers, with a scale factor to undo it afterwards. Pearl’s miner quantizes activations to 7 bits, \[−63, 63], per token.
- The ticket reads each 32-bit running sum as raw bits (two’s complement) when it XORs them together.

## Read the code

- [Every revealed entry must be in \[−64, 64\]](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/zk-pow/src/api/verify.rs#L114-L119) `zk-pow/src/api/verify.rs:114-119`
- [MAX_VAL_7BIT = 63: the activations' range](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/miner/vllm-miner/src/vllm_miner/quantization_operators.py#L4-L5) `miner/vllm-miner/src/vllm_miner/quantization_operators.py:4-5`
- [Mining mode quantizes activations to 7 bits](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/miner/vllm-miner/src/vllm_miner/vllm_kernels.py#L198-L224) `miner/vllm-miner/src/vllm_miner/vllm_kernels.py:198-224`
- [Products in i32, XOR-folded as u32](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/zk-pow/src/circuit/chip/jackpot/helper.rs#L9-L35) `zk-pow/src/circuit/chip/jackpot/helper.rs:9-35`

## Sources

### Pearl docs

- [Pearl INT whitepaper, §4.2, §4.4 and §4.8](https://pearlresearch.ai/research/int-whitepaper)
- [Proof of Useful Work from the Ground Up (overhead figures, W7A7 quantization)](https://pearlresearch.ai/research/blog/proof-of-useful-work)

### Papers

- [Jacob et al., Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference (arXiv 1712.05877)](https://arxiv.org/abs/1712.05877)
