A tiny, self-contained framework (Python 3 + numpy only — no WakeNet, no TFLM) that
trains a DS-CNN wake-word model, quantizes it to int8, and generates the C header the
ESP32-S3 firmware runs. The int8 inference reference is bit-exact with the on-device
C engine (firmware/core/src/kws_model.c), proven by a committed parity fixture.
kwslib/— library:quant.py/kernels.py— bit-exact mirrors offirmware/core/src/nn/{quant,kernels}.clayers.py/model.py/optim.py— float DS-CNN forward+backward + Adamquantize.py— float → int8 (TFLite-style per-channel/per-tensor)infer_int8.py— int8 inference reference (mirrorskws_model.c)codegen.py— emitskws_model_data.hfeatures.py/dataset.py— log-mel front-end + dataset/augmentation
tools/:train.py— dataset → train → quantize → codegengen_parity_case.py— regenerate the committed C↔Python parity fixture
# Train a demo model and emit a deployable C header
python3 tools/train.py --epochs 80 --out artifacts/kws_model_data.h
# Regenerate the parity fixture (committed under tests/host/generated/)
python3 tools/gen_parity_case.pyRun from the repo root with make test (Python tests are wired into CTest), or directly:
cd tests/py && for t in test_quant test_layers_gradcheck test_train_learns \
test_quantize_codegen test_parity_regen; do python3 $t.py; doneThe C parity test (tests/host/test_parity.c) asserts the C engine reproduces the Python
int8 logits from the committed fixture bit-for-bit.