# Quintrit

**Run ternary (1.58-bit) language models fast on *ordinary CPUs.***

A command-line program, an HTTP server with a subset of the OpenAI API, and libraries for Python, C, C++ and Rust.
Open source under the Apache License 2.0.

```bash
pip install quintrit
```

![A matrix of ternary weights: 18 by 18 squares with the values -1, 0 and +1](https://velurex-labs.com/trit-grid.svg)
*A ternary weight matrix: violet −1, dark 0, teal +1.*

## Specialization

- **Encoding.** [Velurex encoding](https://velurex-labs.com/quintrit/velurex-encoding/index.html.md) puts five ternary weights into one byte, and **the weights
  are decoded without division**.
- **Memory.** Weights take 1.60 bits each instead of 2.00, which means up to 20 % less memory traffic per token. On a
  single slow core the arithmetic can become the limit.
- **Kernels.** Kernels for AVX2, AVX-512 and ARM NEON are chosen when the program starts. An optional backend runs on
  NVIDIA GPUs of compute capability 8.0 or newer.
- **Same results.** A GPU or a different instruction set changes the speed, not the result: on the same operating system
  the computation is bit-identical.
- **Models.** GGUF files with `I2_S`, `TQ1_0`, `TQ2_0` and `Q2_0` weights are loaded directly, for example BitNet
  b1.58, Falcon3, Falcon-E, Llama 3 1.58, Ternary Bonsai and Nemotron-H.

## Limits

- Ternary models only, no ordinary 4-bit or 8-bit models.
- Prebuilt programs exist for Linux x86-64, Linux ARM64 and Windows x86-64. macOS is not tested yet.
- The GPU backend is built from source with the CUDA toolkit.
- Models are not part of the project. Take them from their publishers and read their terms.

## Links

- [Source code](https://github.com/velurex-labs/quintrit)
- [Latest release](https://github.com/velurex-labs/quintrit/releases/latest)
- [Python package](https://pypi.org/project/quintrit/)
- [Rust crate](https://crates.io/crates/quintrit-runtime)
- [Guides](https://github.com/velurex-labs/quintrit/tree/main/docs/guides)
- [Benchmarks](https://github.com/velurex-labs/quintrit/blob/main/docs/benchmarks.md)
- [Speed of the models](https://github.com/velurex-labs/quintrit/blob/main/model_benchmarks/README.md)
- [How to cite](https://github.com/velurex-labs/quintrit/blob/main/CITATION.cff)
- [Velurex encoding](https://velurex-labs.com/quintrit/velurex-encoding/index.html.md)
- [Instructions for agents](https://velurex-labs.com/quintrit/for-agents.md)
