spt-dither
Deterministic low-discrepancy dithering for low-bit quantization
Overview
spt-dither provides pre-quantization dithering using deterministic, low-discrepancy sequences (golden-ratio and pi-digit) to break quantization grid alignment at 3/5/7-bit levels. It uses no RNG, produces reproducible outputs across platforms (WASM, x86, ARM), and has zero runtime dependencies. This crate targets tiny inference devices and the SPT quantized ML pipeline.
Key Features
- Golden-ratio dither -- best 1-D equidistribution via fractional golden-ratio stepping
- Pi-digit dither -- reproducible 256-period sequence from pi digit tables
- Channel dither -- per-channel dithering for multi-dimensional vectors
- No RNG required -- fully deterministic and reproducible across platforms
- no_std compatible -- works on bare-metal, WASM, and embedded targets
Dependencies
No runtime dependencies. Fully self-contained and no_std compatible.
Usage
rust
use spt_dither::{GoldenRatioDither, quantize_dithered};
let mut gr = GoldenRatioDither::new(0.0);
let quantized = quantize_dithered(0.314, 8, 0.5, &mut gr);
assert!(quantized >= -1.0 && quantized <= 1.0);API Reference
Core Types
| Type | Description |
|---|---|
DitherSource | Trait for deterministic dither sequence generators |
GoldenRatioDither | Golden-ratio fractional stepping dither source |
PiDither | Pi-digit table dither source (period 256) |
ChannelDither | Per-channel dithering wrapper |
quantize_dithered | Quantize a single value with dithered offset |
quantize_slice_dithered | Quantize a slice of values with dithered offsets |