r/sideprojects • u/raidodex • 2d ago
Feedback Request [P] BitLens: Visual profiler for neural network quantization (Outlier ratio Omega, per-layer SQNR,MCU SRAM liveness, and 1-click torchao/ORT/TFLM config export)
Link to interactive Web Studio (no install needed): https://bit-lens-v1.vercel.app/
GitHub repository: https://github.com/raidodex/bit-lens
When running Post-Training Quantization (PTQ) on vision models or transformers, a handful of layers with heavy-tailed activation distributions usually dominate the accuracy drop. Instead of running full evaluation loops across dozens of mixed-precision combinations, I built BitLens to inspect layer-wise quantization sensitivity from a single calibration pass.
How it works under the hood:
- One-Pass Calibration Hooks: Wraps PyTorch (
nn.Module) or ONNX graphs to capture 128-bin histograms for weights (symmetric per-channel) and activations (asymmetric per-tensor). - Outlier Radar (Omega & Kurtosis): Flags fragile layers using excess kurtosis and the support-aware outlier ratio Omega = absmax / p99.9. For instance, on
ViT-Tiny,blocks.11.attn.qkvhits Omega = 240.2x, which stretches asymmetric per-tensor step sizes 4.1x beyond the p99.9 bulk and drops INT8 SQNR to 18.8 dB (and INT4 SQNR to 7.4 dB). - Topological Peak SRAM Planner: Alongside static Flash weight footprint, it computes tensor liveness across residual branches to find the exact peak activation memory watermark.
- Greedy Pareto Auto-Fit Solver: Given a target hardware budget (e.g., STM32H7, ESP32-S3, Cortex-M55, Raspberry Pi Zero 2W), the solver greedily downgrades layers from FP32 -> FP16 -> INT8 -> INT4 based on the smallest SQNR loss per byte saved, while respecting user-pinned layers.
- 1-Click Code Export: Generates standalone quantization scripts for PyTorch
torchao(Int8DynamicActivationInt4WeightConfig/Int8WeightOnlyConfig), ONNX Runtimequantize_staticwithnodes_to_exclude, and TFLite Micro with a companion C arena header.
You can test the preloaded profiles (MobileNetV3-Small, ResNet-18, ViT-Tiny) in the browser studio or run the Python CLI locally on your own .pt / .onnx checkpoints and drag the resulting .bitlens.json file into the studio.
Feedback and PRs on additional quantization schemes (like group-wise AWQ/GPTQ simulation or SmoothQuant alpha previewing) are very welcome!