Expand description
§ruvector-dither
Deterministic, low-discrepancy pre-quantization dithering for low-bit inference on tiny devices (WASM, Seed, STM32).
§Why dither?
Quantizers at 3 / 5 / 7 bits can align with power-of-two boundaries and produce idle tones / limit cycles — sticky activations and periodic errors that degrade accuracy. A sub-LSB pre-quantization offset:
- Decorrelates the signal from grid boundaries.
- Pushes quantization error toward high frequencies (blue-noise-like), which average out downstream.
- Uses no RNG — outputs are deterministic, reproducible across platforms (WASM / x86 / ARM), and cache-friendly.
§Sequences
| Type | State update | Properties |
|---|---|---|
GoldenRatioDither | frac(state + φ) | Best 1-D equidistribution |
PiDither | table of π bytes | Reproducible, period = 256 |
§Quick start
use ruvector_dither::{GoldenRatioDither, PiDither, quantize_dithered};
// Quantize with golden-ratio dither, 8-bit, ε = 0.5 LSB
let mut gr = GoldenRatioDither::new(0.0);
let q = quantize_dithered(0.314, 8, 0.5, &mut gr);
assert!(q >= -1.0 && q <= 1.0);
// Quantize with π-digit dither
let mut pi = PiDither::new(0);
let q2 = quantize_dithered(0.271, 5, 0.5, &mut pi);
assert!(q2 >= -1.0 && q2 <= 1.0);Re-exports§
pub use golden::GoldenRatioDither;pub use pi::PiDither;pub use quantize::quantize_dithered;pub use quantize::quantize_slice_dithered;pub use channel::ChannelDither;
Modules§
- channel
- Per-channel and per-layer dither management.
- golden
- Golden-ratio quasi-random dither sequence.
- pi
- π-digit dither: cyclic table of the first 256 digits of π scaled to [-0.5, 0.5].
- quantize
- Drop-in quantization helpers that apply dither before rounding.
Traits§
- Dither
Source - Trait implemented by any deterministic dither source.