# Quantized dot product

> How much work does it take to multiply by a row of two-bit weights? Quantize the row once, then score the same packed bytes three ways. Quantization changes the answer once. The choice of scoring loop changes the time and temporary storage.

How much work does it take to multiply by a row of two-bit weights? Quantize the row once, then score the same packed bytes three ways. Quantization changes the answer once. The choice of scoring loop changes the time and temporary storage.

## Result

> Scoring 65,539 two-bit weights took 64.7 µs directly from packed bytes and 162.6 µs with per-call expansion

## Modules

* [`knotkit/prng`](/modules/prng/): Generates seeded pseudorandom numbers and unbiased integers for reproducible simulations and tests
* [`knotkit/errors`](/modules/errors/): Provides the base error classes every Knotkit package throws from, discriminated by package, category, and cause

## Figures

* Four Float32 weights (16 bytes) pack into 1 byte, 0xe4.
* Reconstructed weights in input order: -0.75, -0.25, 0.25, 0.75.
* With activations \[2, -1, 3, 1], the dot product changes from -0.40 to 0.25.
* Expanded, scalar and grouped scoring give 0.25, 0.25, 0.25.

Hover or focus a chart for exact values. Drawn by [`demo.ts`](https://github.com/jkomyno/knotkit/blob/main/problems/quantized-dot-product/demo.ts) at build time, from the fixtures the benchmark uses; it reproduces the README figure.

## Reproduce

```bash
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:quantized-dot-product
```

[`problems/quantized-dot-product/README.md`](https://github.com/jkomyno/knotkit/blob/main/problems/quantized-dot-product/README.md) states the fixture, the seed, and the result table.
