# Efficient inference of ternary language models on *ordinary processors.*

Open source software that runs 1.58-bit language models on the processors people already have, from a Raspberry Pi to
a server. No GPU is needed, but NVIDIA GPUs are supported.

```bash
pip install quintrit
```

## Key figures

| 5 | 1.60 | 0 |
|---|---|---|
| ternary weights per byte | bits per weight | divisions to decode |

## Velurex encoding

Five ternary weights are packed into one byte. The radix 28 lets vector instructions separate them with shifts and one
rounded average, with no division.

[How velurex encoding works](https://velurex-labs.com/quintrit/velurex-encoding/index.html.md)

---

```text
B = d0 + 3*d1 + 9*d2 + 28*d3 + 84*d4
```

| Example: B = 61 | Value |
|---|---|
| `v11 = B >> 2` | 15 |
| `v15 = v11 >> 3` | 1 |
| **`v17 = (v11 + v15 + 1) >> 1`, one instruction: `vpavgb`, `URHADD`** | **8** |
| `U = v17 >> 2` | 2 |
| `L = B - (((U << 3) - U) << 2)` `// = B - 28*U` | 5 |

The scheme shows the principle. The implementation differs from architecture to architecture.

## Areas of work

- **Compact weights, no division.** [Velurex encoding](https://velurex-labs.com/quintrit/velurex-encoding/index.html.md) stores five ternary weights in
  one byte, and **decoding them needs no division**.
- **Same results.** On the same operating system, CPUs and NVIDIA GPUs compute bit-identical results.
- **Existing models.** Common ternary models in GGUF files are loaded directly, without converting them first.

## Quintrit

Quintrit runs ternary language models from the command line, as an HTTP server and from Python, C, C++ and Rust. It is
open source under the Apache License 2.0.

[About Quintrit](https://velurex-labs.com/quintrit/index.html.md)

## Who

Lukáš Velecký, author of Quintrit and of velurex encoding.

## Contact

[quintrit@velurex-labs.com](mailto:quintrit@velurex-labs.com)
