Acoustic machine-health monitoring that runs entirely on an Arm CPU, offline.
Captured from a live run of scripts/run_demo.sh demo — no dataset and no
microphone needed, so you can reproduce this exact view from a bare clone in
about two minutes (Setup). The audio driving it is
assets/demo/synthetic_fan_normal_then_fault.wav, a 30-second clip this
repository generates from numpy primitives: it is a UI aid, not evidence.
No accuracy, threshold or quantization figure anywhere in this project is derived
from it — every accuracy number below comes from real DCASE2020 and ESC-50
recordings. The alarm threshold shown (12.710) is the shipped one, computed from
200 normal DCASE fan training clips. The per-stage latencies in the screenshot
are one live sample under screen capture; the benchmark figures below are the
measured ones.
A microphone listens to a running machine. Two LiteRT models score every second
of audio: YAMNet says what it is hearing (521 AudioSet classes), and a
DCASE2020-style dense autoencoder says whether it sounds normal. A 60-second
enrollment adapts the autoencoder and its alarm threshold to the specific machine
in front of you. A local Flask + websocket dashboard shows the whole thing live,
with a key that toggles FP32 and INT8 inference so the optimization is visible
while the system is running. No cloud, no accelerator, no network. What is
measured about that last claim: the dashboard page is one self-contained HTML
document that references no external asset — no CDN script, stylesheet, font or
image — and scripts/smoke_dashboard.py asserts this on every run by scanning
the served page for external URLs (benchmarks/dashboard_smoke.json, 28,531 B
page). Nothing in this repository measures the demo with the radio physically
switched off, so that is stated as a property of the page, not as a benchmark.
The motivation — not a measurement: condition monitoring today usually means either a technician who happens to walk past, or a vibration sensor and a gateway subscription per machine. A microphone plus an Arm CPU that is already on site looks like a cheaper place to put the first line of defence, but this project priced nothing and makes no cost claim. What it does measure is the thing that stands between "a model exists" and "it runs on the box": inference cost.
Submitted to the Arm Create: AI Optimization Challenge (Physical AI track). The contest story is an honest FP32 → INT8 optimization with before/after evidence, including the parts that did not work.
- docs/ARM_OPTIMIZATION.md — the Arm-specific work:
KleidiAI symbol inventory, ISA gating, an executed KleidiAI probe, macOS
sample(1)microkernel attribution and instruction-level disassembly of the kernels that actually run. Read this one first if you are an Arm engineer. - RUNNING.md — how to drive the demo, what the alert does.
- MODELS.md — per-artifact provenance and the licence each one carries. THIRD_PARTY.md, NOTICE, LICENSE (Apache-2.0, code).
- benchmarks/ — every raw measurement JSON.
scripts/report_numbers.pyre-derives the measured figures in this README straight from them, each with the file it came from — including the 41/41 self-test tally (section 9) and the threshold's z-test (section 11), plus section 11b for the synthetic demo clip, which is labelled UI-evidence-only so it can never be read as a DCASE result. Four groups of figures below are deliberately not re-derivable and each says so where it appears: the superseded1767.0 ips, whose JSON the re-run overwrote in place; two enrollment/self-test runs a verifier did on a fresh clone that wrote nothing into thisbenchmarks/; and the five sustained-throughput re-runs quoted under Sustained throughput to document that row's run-to-run spread, which were kept out ofbenchmarks/on purpose so they cannot be mistaken for the recorded measurement.
How the numbers are written. Every figure in this README is the JSON's own
value, rounded to nearest at 6 decimals — never truncated, never rounded in
the direction that flatters the result. The rule is exactly what
scripts/report_numbers.py does, and it does it with Python's
format(value, ".6f"): correct rounding of the IEEE-754 double the measurement
is stored as, ties to even. Ties essentially never arise, because a decimal that
ends in a 5 at the 7th place is almost never exactly representable in binary.
The three figures in this repository whose JSON text looks like a tie are all
strictly below the midpoint as stored, so they round down:
| JSON text | the double actually stored | printed |
|---|---|---|
2.1501245 |
2.150124499999999994059862729045562446117401123046875 | 2.150124 |
0.5558955 |
0.55589549999999998686206481579574756324291229248046875 | 0.555895 |
9.4297715 |
9.4297714999999993068513504113070666790008544921875 | 9.429771 |
Rounding those up — treating the shortest round-trip decimal as if it were an exact half — would move each away from the value that was measured, and all three are FP32 baselines, so up is the direction that would inflate an FP32→INT8 ratio. Down is both correct and conservative.
Ratios are computed from the full-precision values, not from the rounded ones printed here, which is why a quoted ratio can differ in the last digit from what you get by dividing two printed figures.
| CPU | Apple M1 Pro — Armv8-A, 6 P-cores + 2 E-cores |
| ISA features | FEAT_DotProd=1, FEAT_I8MM=0, FEAT_BF16=0, FEAT_SME=0, FEAT_SME2=0 |
| OS | Darwin 25.5.0 arm64 (macOS 26.5.2) |
| Runtime | ai-edge-litert 2.1.6, wheel cp312-cp312-macosx_12_0_arm64, XNNPACK delegate |
| Python | 3.12.13 |
| Threads | 1, for every latency number in this repository |
| Also verified on | native aarch64 Linux container, Ubuntu kernel 6.8.0-117, LiteRT 2.1.6 (see Portability) |
Sources: benchmarks/bench_yamnet_int8_xnnpack-default_1t.json (CPU, OS, Python),
benchmarks/kleidiai_inventory.json (ISA features, LiteRT version and wheel tag),
benchmarks/throughput_yamnet_fp32_1t.json (core counts),
benchmarks/portability_linux_arm64.json (the Linux container).
Model compute, counted by walking each graph's ops and tensor shapes
(scripts/count_tflite_macs.py → benchmarks/tflite_macs.json):
YAMNet 69,165,056 MACs per 0.96 s patch, autoencoder 264,192 MACs per
640-dim vector.
Requires an Arm64 machine (measured on macOS/Apple Silicon; the models are also
verified byte-identical on Arm64 Linux), Python 3.12, git, curl.
git clone <repository-url> machine-ear
cd machine-ear
scripts/setup.sh # venv + pinned deps + YAMNet sources + class map + weights
scripts/run_demo.sh demo # NO dataset, NO microphone — opens http://127.0.0.1:8000/scripts/setup.sh is idempotent and verifies what it downloads (sha256 of the
YAMNet class map, md5 and byte count of yamnet.h5).
What works on a bare clone, with no dataset and no microphone:
scripts/run_demo.sh demo. It plays
assets/demo/synthetic_fan_normal_then_fault.wav — a 30 s clip generated from
numpy primitives by scripts/make_synth_demo_clip.py (fixed seed, rebuilt
bit-for-bit if missing), 15 s of a synthetic fan hum then the same hum with a
bearing squeal. Everything on the page is live: the spectrogram, YAMNet's
labels, the anomaly score, the precision toggle and the latency panel. The clip
is a UI aid, not evidence — no accuracy, threshold or quantization number in
this repository is derived from it, and the alert banner in this mode is driven
by the DCASE-fitted default threshold, which was never fitted to synthetic audio.
The one thing that clip is evidence for — that the banner really walks
NORMAL → ALERT from the audio rather than on a timer — is measured, not
asserted: benchmarks/alert_transition_synthetic.json, re-derived as section
11b of scripts/report_numbers.py, which is labelled UI-evidence-only and
kept apart from the real-audio section 11 so the two can never be pooled. 675
INT8 frames over 70.0 s, the flip landing on the frame whose 1 s window ends at
clip time 15.6 s — 0.6 s past the 15 s fault boundary — on both loop passes,
spread 0.000 s, dropping back after the 4 s latch.
Everything committed that the demo needs — the four .tflite models, the
pretrained autoencoder weights models/ae_fp32.weights.h5 that ENROLL fine-tunes
from, and vendor/yamnet/yamnet_class_map.csv — is in the repository. Nothing in
demo mode reaches the network.
Live microphone (scripts/run_demo.sh) additionally needs a physical input
device and, on macOS, an interactive TCC permission grant that only a human at
the keyboard can click.
Rehearsing that live demo. scripts/rehearse_demo.py walks an operator
through the three phases of a microphone demo — enroll on the machine running
normally, apply a fault, remove it — and says in plain English whether the alarm
line separated them, before anyone points a camera at it. It runs the same
src/enrollment.py:enroll() the ENROLL button runs, prints every phase as a
multiple of that run's own alarm line, and writes only to the git-ignored
work/selftest/. A green result demonstrates the system working end to end on
one real machine; it is not a measurement of detection accuracy — one machine,
one fault, one room, no labels — and no number it prints belongs in an accuracy
claim. Every accuracy figure in this README comes from the labelled DCASE2020
and ESC-50 runs in Accuracy retention. RUNNING.md, Rehearsing a live demo,
has the usage and the exit codes.
ENROLL is not a microphone-only feature. It runs against whatever the
current audio source is, so it works in demo and file mode too, on a bare
clone, with no mic — the weights it fine-tunes from (models/ae_fp32.weights.h5)
are committed. The last recorded dashboard enrollment
(benchmarks/dashboard_enrollment_last.json) is a file-source run —
source.kind: "file", 10.0 s captured, 17.393219 s total — not a microphone run.
A verifier also ran one from demo mode on a fresh clone: 19.81 s wall clock,
kept: 11.4655 -> 9.1541, 20.16% better; that run wrote no file under
benchmarks/, so it is quoted here from the audit record and not from a
committed JSON. What is genuinely microphone-specific is the 60 s live
enrollment in Enrollment below — that one needs a mic, a real machine to
point it at, and 60 s of it running normally.
The two modes that play real machine audio need the 1.35 GB DCASE download:
scripts/fetch_data.sh # DCASE2020 fan + ESC-50; prints the NonCommercial
# terms and requires you to accept them first
scripts/run_demo.sh file # healthy DCASE fan clip, looped
scripts/run_demo.sh alert # healthy fan -> the SAME fan faultyscripts/run_demo.sh check # headless self-test, prints measured numberscheck runs either way. It uses the DCASE clip when the dataset is there and
the committed synthetic clip when it is not, and in the second case it prints an
explicit SKIPPED block naming the checks whose audio it could not supply,
so a synthetic run is never mistaken for a real-audio one. See Self-test below.
On the page: P toggles FP32/INT8, E starts an enrollment. Both are also
buttons. PORT=8001 moves it; OPEN_BROWSER=0 stops it opening a browser.
Do not press E in demo or alert mode unless you want to see what a bad
enrollment does. Half of each of those clips is the fault, so enrolling on them
teaches the autoencoder that the fault is normal and fits a threshold above it.
The alert banner already says this; it applies to demo for the same reason.
mic and file are the modes where an enrollment means something.
The dashboard streams one analysis frame every 100 ms; each frame analyses the most recent 1.0 s of audio.
| On screen | What it means |
|---|---|
| Log-mel spectrogram | 64 mel bands, newest column on the right. YAMNet's own frontend (25 ms window, 10 ms hop, 125–7500 Hz), computed in pure numpy. |
| Top-3 labels | YAMNet's three highest-scoring AudioSet classes for this second. This is context, not the detector — it tells you the mic is pointed at the machine and not at a conversation. |
| Anomaly score | Mean squared reconstruction error of the autoencoder over the 640-dim log-mel vectors in this second. Higher = further from what "normal" sounded like. It is an arbitrary scale, meaningful only against a threshold fitted on the same machine. |
| Alert statistic | Mean anomaly score over the last 5 non-overlapping 1 s windows. Every threshold in the system is fitted to this statistic, not to the raw per-second score. |
| Banner | WARMING UP until 5 windows exist; NORMAL/ALERT after that; NO THRESHOLD on a live mic before enrollment. An ALERT latches for 4 s so a single window cannot flicker the banner. |
| Latency panel | Per-stage p50 for this session: feature frontend, YAMNet, autoencoder, end-to-end, plus the real-time factor. The frontend is reported separately because it is precision-independent work. |
Threshold. The default is the p99.9 of the alert statistic over 200 normal
DCASE fan training clips: 12.710131 for the INT8 pair, 12.680812 for FP32
(benchmarks/dashboard_calib.json). Those 200 clips give 1,200 windows and the
windows inside a clip are correlated, so it is a percentile over 1,200 correlated
samples. Each precision has its own threshold and therefore its own operating
point, and /api/state reports them separately, so this README does too. On the
held-out evaluation subset — 100 normal and 100 anomalous clips, 600 windows per
class:
| precision | false alarms (normal) | detections (anomaly) | two-proportion z | p (two-sided) |
|---|---|---|---|---|
| FP32 | 27/600 = 4.5 % | 33/600 = 5.5 % | 0.79 | 0.43 |
| INT8 (shipped) | 27/600 = 4.5 % | 35/600 = 5.833 % | 1.04 | 0.30 |
The z = 1.04, p = 0.30 quoted elsewhere in this README and in What did not
work is the INT8 pair (35/600 vs 27/600) — the shipped one. FP32's own pair
is weaker still. Neither is statistically distinguishable from zero effect at
n = 600 windows per class. The threshold is tuned for a low false-alarm rate on
normal audio; it is not, on this evidence, a good detector. Both rates are shown
on the page. scripts/report_numbers.py section 11 recomputes this table,
including both z values, from dashboard_calib.json's own counts.
Enrollment is the answer to that. The DCASE threshold is meaningless for
your fan in your room, so on a live microphone alerts stay off until you
press ENROLL. Enrollment records the machine running normally, fine-tunes the
autoencoder on that capture, re-quantizes it to INT8 using the enrollment audio
as calibration data, and derives a mean + 3 sigma threshold from the same 5 s
statistic. Measured on the live microphone, 60 s requested
(benchmarks/enrollment_live_mic.json): 74.884 s total, 0 samples dropped,
thresholds 54.123 (INT8) / 55.250 (FP32), adaptation kept — held-out
enrollment loss 80.2576 → 9.9954, 87.55 % better.
Two fields in that JSON are easy to conflate and are stated apart here: it
captured 60.0 s of audio (seconds_captured) and that took 61.26114 s of
wall clock (timings_s.capture), because the dashboard's 10 Hz analysis loop
was running on the same microphone throughout. The 1.26 s gap is scheduling, not
dropped audio — dropped_samples is 0.
A keep-or-revert guard decides whether the fine-tune is used at all; see What did not work for the case where it correctly throws the fine-tune away.
Both models were converted to full-integer INT8 (int8 in, int8 out, per-axis
weights). YAMNet's quantization ranges come from 345 real log-mel patches — 225
from 150 ESC-50 clips and 120 from 40 DCASE fan clips — selected inside a
loudness percentile band of [15, 30], with a ±8.0 logit clamp
(benchmarks/calib_yamnet_int8.json). The autoencoder was calibrated on 512 real
training vectors.
Everything below is the shipped models/yamnet_int8.tflite (4,062,664 B,
sha256 7ff8ca6a…). The repository also contains
models/yamnet_int8_randcal.tflite, an earlier random-calibration artifact that
is faster (4.191x p50) but valid for latency only; it is never quoted as a
result and the dashboard never loads it.
| what was timed | FP32 | INT8 | ratio | source |
|---|---|---|---|---|
invoke() only, separate processes, p50 |
2.130313 ms | 0.516854 ms | 4.122x | bench_yamnet_{fp32,int8}_xnnpack-default_1t.json |
| the same runs, p99 | 2.417500 ms | 0.873875 ms | 2.766x | same |
invoke() only, interleaved in ONE process, real log-mel input |
2.150771 ms | 0.514417 ms | 4.181x | bench_fair_interleaved_kernelonly_realinput_1t.json |
deployed timed region (quantize input + invoke + dequantize 521 logits), interleaved, real input |
2.150124 ms | 0.528125 ms | 4.071x | bench_fair_interleaved_withio_realinput_1t.json |
| the same, p99 | 2.477750 ms | 0.666042 ms | 3.720x | same |
sustained throughput, completed invoke()s / wall clock over 30 s (±2 % run to run — see below) |
463.2 ips | 1891.9 ips | 4.084x | throughput_yamnet_{fp32,int8}_1t.json |
| file size | 14,936,744 B | 4,062,664 B | 3.677x | filesystem |
The interleaved rows alternate FP32 and INT8 in 10 blocks of 100 invokes inside one process, so thermal state and CPU frequency hit both models equally, and the "with-IO" rows put the float↔int8 conversion inside the timed region — work the deployed pipeline must do and the FP32 path does not. 4.071x is the most defensible single-model number in this project; the 4.122x kernel-only figure is the classic tflite benchmark protocol and is quoted alongside it, not instead of it.
The throughput row is measured, not derived: it is completed invokes divided by elapsed wall clock over 30 s, single stream, 1 thread, no batching. Deriving throughput as 1000/p50 would have said 1934.8 ips for INT8 and 469.4 for FP32 — overstating the real rate by 2.3 % and 1.3 % respectively, because a median ignores the tail. Both files also record the sha256 of the model the interpreter loaded; an earlier version of this measurement was disqualified by the provenance guard and re-run, which is described under What did not work.
Run-to-run spread on this row, measured — read this before you re-run it.
The throughput row is the least stable figure in this README and the only one
where a re-run has ever moved by more than 0.5 %. Three FP32 re-runs of exactly
the command in bench/power_load.py's docstring, same machine, same model
sha256, on 2026-08-02, gave 455.5, 459.6 and 455.0 ips — 0.8 % to 1.8 %
below the recorded 463.2 — and two INT8 re-runs gave 1898.8 and 1902.9 ips,
0.4 % to 0.6 % above the recorded 1891.9. An independent verifier's FP32 re-run
came back 2.2 % low. So the published pair sits at the conservative end: every
one of those re-runs puts the FP32→INT8 ratio between 4.13x and 4.18x, higher
than the 4.084x quoted above, and none of them lowers it.
The cause is in the JSON, which samples os.getloadavg()[0] once per second for
exactly this purpose: the committed runs saw 1-minute load 4.64–5.03 on 8 logical
CPUs, the re-runs 5.88–10.88. Treat 463.2 / 1891.9 / 4.084x as ±2 % on a laptop
that is doing anything else at the time. The five re-runs quoted here wrote to
work/selftest/ (git-ignored) and were deliberately not added to
benchmarks/, so they are not re-derivable by scripts/report_numbers.py;
reproduce them with bench/power_load.py ... --out <somewhere outside benchmarks/>. Every other row a verifier re-ran landed within 0.5 %.
Also true and worth a line: models/yamnet_int8.tflite and
models/yamnet_fp32.tflite do the same arithmetic — 69,165,056 MACs per
invoke in both (benchmarks/tflite_macs.json). Quantization changed the datatype,
not the op count, so nothing above is a smaller model doing less work.
| what was timed | FP32 | INT8 | ratio | source |
|---|---|---|---|---|
invoke() on one 640-dim vector, p50 |
0.015041 ms | 0.005125 ms | 2.935x | bench_ae_{fp32,int8}_xnnpack-default_1t.json |
| the AE stage inside the engine, per 1 s chunk (28 vectors) | 0.270334 ms | 0.105854 ms | 2.554x | smoke_engine.json |
| file size | 1,069,700 B | 318,104 B | 3.363x | filesystem |
The per-vector and per-chunk figures are different units. The autoencoder runs 28 times per second; YAMNet runs once. Adding a per-vector AE number to a per-patch YAMNet number would understate the AE's real cost by roughly 20x, so this repository never states a combined cost that way — it states the measured cost of a whole 1 s frame.
| stage, p50 per frame | FP32 | INT8 | ratio |
|---|---|---|---|
| feature frontend (numpy/librosa log-mel) | 1.668541 ms | 1.612334 ms | 1.035x |
| YAMNet | 2.210000 ms | 0.595667 ms | 3.710x |
| autoencoder | 0.282542 ms | 0.121000 ms | 2.335x |
| inference (YAMNet + AE) | 2.492416 ms | 0.720354 ms | 3.460x |
| end-to-end frame | 4.197375 ms | 2.388208 ms | 1.758x |
Client-measured against the running server, 60 INT8 frames and 59 FP32 frames in
one session, 10.00 / 10.00 Hz (benchmarks/dashboard_smoke.json, 41/41 checks
passed — see Self-test below). The loop emits one frame per 100 ms, so the
real-time factor is 0.023882 in INT8 and 0.041974 in FP32: 2.4 ms of compute
against a 100 ms budget. src/engine.py measured on its own, without a websocket
or a browser, gives the same picture on real DCASE audio: 3.841604 → 1.928250 ms
per chunk (1.992x), YAMNet stage 3.909x (benchmarks/smoke_engine.json).
Why the three ratios differ, in one line: the log-mel feature frontend is identical numpy code in both precisions (1.035x — that is noise, not a speedup), and the deployed path pays a float↔int8 conversion the kernel-only figure excludes; so 4.12x kernel → 4.07x deployed kernel → 3.46x inference stage → 1.76x end-to-end, and every one of those is a real measurement of a different thing.
The bottleneck moved. After quantization the un-quantizable numpy frontend (1.612334 ms) costs 2.24x as much as both models put together (0.720354 ms). The next optimization on this project is not a smaller model; it is the feature extractor. That is the most useful thing this exercise found.
Quantization is only interesting if the model still works. Two independent checks, both on the shipped artifacts.
All 1,875 labelled test clips. The INT8 reconstruction is scored in float against
the original, unquantized features, and both models are evaluated with
identical resizing, so quantization error degrades the score honestly instead of
cancelling itself out. pAUC uses sklearn max_fpr=0.1. Averages are the per-ID
arithmetic mean, matching the DCASE convention.
| machine | clips | AUC FP32 | AUC INT8 | Δ | pAUC FP32 | pAUC INT8 |
|---|---|---|---|---|---|---|
| id_00 | 507 | 0.535946 | 0.535725 | -0.000221 | 0.493211 | 0.493599 |
| id_02 | 459 | 0.731226 | 0.732117 | +0.000891 | 0.550652 | 0.549919 |
| id_04 | 448 | 0.610603 | 0.612586 | +0.001983 | 0.529946 | 0.530248 |
| id_06 | 461 | 0.736288 | 0.736731 | +0.000443 | 0.526170 | 0.527628 |
| average | 1,875 | 0.653516 | 0.654290 | +0.000774 | 0.524995 | 0.525349 |
Source: benchmarks/auc_ae_fp32.json, benchmarks/auc_ae_int8.json. INT8 is not
"better" — every per-ID delta is ≤ 0.002 and the sign flips between IDs. The
claim is retention, not improvement.
This is not accuracy; no ground-truth label is involved. It measures how much quantization changed the model's behaviour.
| corpus | clips | clip top-1 agree | FP32 top-1 inside INT8 top-5 | patches | patch top-1 agree |
|---|---|---|---|---|---|
| ESC-50, all 5 folds | 2,000 | 93.55 % | 100.00 % | 20,000 | 84.98 % |
| ESC-50, held-out folds 2–5 | 1,600 | 93.69 % | 100.00 % | 16,000 | 85.14 % |
| DCASE2020 fan test (deployment domain) | 1,875 | 84.05 % | 99.73 % | 37,500 | 70.18 % |
Sources: benchmarks/agreement_yamnet_int8{,_heldout,_fan}.json. The calibration
set drew from ESC-50 fold 1, and folds 2–5 are higher, so the recipe did not
overfit its calibration data. Where FP32 is confident — top-1 minus top-2 margin
≥ 0.1 — agreement is 100.00 % on all three corpora (n = 946 / 750 / 596 clips).
Disagreements are concentrated where FP32 itself was undecided, which is what you
want, but the fan-domain patch figure of 70.18 % is the honest cost of INT8 here
and is stated as such.
benchmarks/ablation_yamnet_int8_calibration.json contains 21 calibration
variants. Real audio with plain min/max calibration produced 19.5 % clip
agreement (ESC-50 first-200-by-filename) — far worse than random calibration on
the same subset (91.0 %). Diagnosis
(scripts/diagnose_yamnet_quant.py → benchmarks/diag_yamnet_quant.json): real
audio has such a wide cross-patch dynamic range that a min/max range leaves a
median patch about 3 of 255 levels. Selecting calibration patches inside a
loudness percentile band fixed it. On the one subset where both were measured —
ESC-50 fold 1, 400 clips — the comparable pair is random calibration 87.50 %
→ band [15, 30] 93.00 %.
A quantization write-up with no negative results is a write-up that stopped measuring early.
KleidiAI is present, reachable, and slower than what we ship. The LiteRT
wheel contains 225 KleidiAI microkernels and 111 XNNPACK wrappers that call them.
On this silicon 160 of the 225 are dead code (FEAT_SME=0, FEAT_SME2=0,
FEAT_I8MM=0), and only 9 of the 111 wrappers are reachable — all in the
dynamic-quantization family. We built a dynamic-range probe model to execute that
path rather than assert it, confirmed by profile that KleidiAI kernels really ran
(75.7 % of kernel samples in kai_run_matmul_clamp_f32_qai8dxp4x4_..._neon_dotprod),
and measured it: 0.970688 ms vs 0.516854 ms for the static-INT8 model we ship —
the KleidiAI path is 1.878x slower here. Full analysis, including why a source
rebuild with XNNPACK_ENABLE_KLEIDIAI=ON cannot help (the static int8→int8
kernels exist upstream only for SME/SME2), is in
docs/ARM_OPTIMIZATION.md §1.
Threading barely pays and then hurts. Best-of-5 p50, fresh subprocess per
cell, on the shipped models/yamnet_int8.tflite (benchmarks/thread_sweep.json;
every cell records the sha256 of the file the interpreter loaded, and the
provenance guard passes on all of them): FP32 2.1185 ms at 1 thread → 1.0512 ms
at 4 threads (2.015x, parallel efficiency 0.504) → 1.2221 ms at 8. INT8
0.5134 ms at 1 thread → 0.3524 ms at 2 → 0.4684 at 4 → 0.6965 ms at 8, i.e.
0.737x — slower than single-threaded. A 69 M-MAC model at sub-millisecond
latency does not have enough work per thread to pay for the barriers. The project
ships 1 thread, and every latency number here is 1 thread. An independent repeat
of the whole sweep (benchmarks/thread_sweep_recheck.json) reproduces the shape:
INT8 0.5169 → 0.3992 → 0.4678 → 0.6957 ms, i.e. 0.743x at 8 threads.
Fine-tuning is not always an improvement, so it is guarded. Enrollment
compares the held-out enrollment loss before and after the fine-tune and reverts
the weights unless it improves by more than 1 %. On DCASE machine id_02 — which
the pretrained autoencoder had already trained on — fine-tuning made it worse
(9.1867 → 9.3626) and the guard reverted. It reverted again on the dashboard's
own 10 s file-source enrollment (8.7467 → 8.8764,
benchmarks/dashboard_enrollment_last.json). On a machine the model had never
heard (an ESC-50 washing machine) the same code adapts: 87.4959 → 43.7827,
49.96 % better, in 7.398 s of fitting.
Sources: benchmarks/smoke_enroll.json, benchmarks/dashboard_enrollment_last.json.
The revert is a weight restore, so the FP32 model an enrollment exports after a
revert is byte-identical to models/ae_fp32.tflite. That is checked on the
author's machine (MODELS.md §5 records the hashes) but cannot be checked from
a clone: the four enrolled_ae_* / unseen_ae_* .tflite files are not in
this repository at all — not in the working tree and not anywhere in the git
object database, because they were purged by a history rewrite rather than
merely untracked forward. MODELS.md §5 gives the commands that verify that by
walking every object of every commit, and the licensing reason for doing it. Run
an enrollment yourself on a machine the autoencoder already knows and compare the
two files if you want the check.
The tail is worse than the median. The headline p50 ratio is 4.122x; the p99 ratio on the same runs is 2.766x. Quoting only medians hides that.
The detector is baseline-grade. Per-ID mean ROC-AUC 0.653516 is DCASE2020-fan-baseline territory, and the shipped alert threshold's detection and false-alarm rates are not statistically distinguishable at n = 600 windows per class (INT8 pair, 35/600 vs 27/600: z = 1.04, p = 0.30; the FP32 pair is weaker at z = 0.79, p = 0.43 — see Threshold). The contribution here is the optimization and the end-to-end system, not a better anomaly detector.
Three measurements were disqualified by our own tooling, and had to be
re-run. scripts/report_numbers.py cross-checks the model byte size recorded
inside every benchmark JSON against the file that name refers to today. Three
files failed: throughput_yamnet_int8_1t.json and both thread-sweep files
recorded 4,060,280 B under the name yamnet_int8.tflite — that size is the
randcal artifact, so those runs had measured a different file from the one they
were labelled with. They were re-run against the shipped model on 2026-08-02 and
the guard now passes on all of them; every cell also records the sha256 of the
file the interpreter actually loaded, taken inside scripts/bench_litert.py, so
a name alone can no longer stand in for an artifact. The numbers changed: INT8
sustained throughput went from the disqualified 1767.0 ips to 1891.9 ips
measured on the shipped file. 1767.0 is quoted from the audit record, not from
benchmarks/ — the re-run overwrote throughput_yamnet_int8_1t.json in place,
so no committed JSON holds the old value any more and report_numbers.py cannot
source it. Only the 1891.9 ips is re-derivable — and it carries the ±2 %
run-to-run spread documented under Sustained throughput, which is far smaller
than the 7 % gap between the two artifacts and does not blur them. The guard's
full output is
section 0 and section 17 of scripts/report_numbers.py --format markdown, which
today reports no provenance warnings and no MISSING values.
An earlier draft of this section said "no committed script regenerates those
three files". That was wrong, and it is corrected here rather than deleted.
Both are committed: scripts/thread_sweep.py regenerates the two thread-sweep
JSONs (--out defaults to benchmarks/thread_sweep.json), and
bench/power_load.py regenerates the three sustained-throughput JSONs — its own
docstring carries the exact commands, and the Reproduce table below repeats
them. Every file the guard flagged has a one-line regenerator.
Energy was never measured. bench/power.sh, bench/power_load.py and
bench/power_parse.py exist. power_load.py was used — it is the load generator
that produced the sustained-throughput JSONs above — but the powermetrics half
was never run, no energy or power JSON exists anywhere in benchmarks/, and this
project therefore makes no claim about watts or joules per inference. Latency
and size are what was measured; energy is not.
The claim "an INT8 tflite built on a Mac runs unchanged on an Arm64 gateway" is
easy to assert and was instead tested. Both shipped INT8 models were executed on
the macOS/arm64 host and inside a native aarch64 Linux container (colima on
Apple's Virtualization.framework — not QEMU emulation; Docker reports
29.5.2 linux/aarch64, kernel 6.8.0-117-generic), same LiteRT 2.1.6, same seeded
input bytes.
| result | |
|---|---|
| output tensors | bit-identical: 0 elements differing, max abs diff 0.00000000, both models |
| graph contents | TFLite builtin ops only, 0 custom/Flex ops, int8 in and out |
| INT8 speedup, host | 4.127x (2.127583 → 0.515583 ms) |
| INT8 speedup, container | 3.223x (9.429771 → 2.925395 ms) |
Source: benchmarks/portability_linux_arm64.json, regenerated by
scripts/verify_portability_linux_arm64.sh. Caveat, stated in the JSON
itself: the container runs in a VM on the same M1 Pro silicon and is bounded by
the VM's CPU allocation, so its absolute latency is not a gateway measurement.
What is claimed is that the artifact and the FP32→INT8 win survive the OS change,
not that a gateway performs this way.
One field in those JSONs was edited by hand and says so. The uname -a
strings recorded for the macOS side carried the author's machine hostname. The
nodename token — and only that token — was replaced with <hostname-redacted> in
benchmarks/portability_linux_arm64.json, work/portability/side_host.json and
work/portability/side_host_fp32.json; each file now carries a
uname_a_redaction note recording the edit. Sysname, kernel release, kernel
build string and architecture are byte-identical to what uname -a printed, and
no measured value was touched. Re-running
scripts/verify_portability_linux_arm64.sh will write the real hostname back.
scripts/report_numbers.py is the single source of truth. It reads every JSON in
benchmarks/ plus the files in models/, prints every figure with the file it
came from, prints MISSING rather than a default when something is absent, and
runs the provenance guard described above. Its own header line reports how many
benchmark files it read, so that count is never stale in this README.
.venv/bin/python scripts/report_numbers.py --format markdownscripts/smoke_dashboard.py drives the running server over its own websocket and
asserts 41 things about it: the page, the frame schema, the precision toggle,
the latency panel, the threshold plumbing, and a real enrollment. The last
recorded full run (benchmarks/dashboard_smoke.json, 2026-08-02T00:34:51+0800)
is 41 passed, 0 failed, including enrollment ran through src/enrollment.py
(used_module=True, module='src/enrollment.py:enroll()', unavailable=False)
and dashboard swapped in the enrolled autoencoder
(ae_fp32.tflite -> enrolled_ae_fp32.tflite).
Two things a fresh clone needs to know — one caveat, one correction:
-
The enrollment checks pass in a fresh clone only because
models/ae_fp32.weights.h5is committed.src/enrollment.py:enroll()loads it as the starting point for the fine-tune. Without it the server's fallback path takes over, and it now reports itself asENROLLMENT UNAVAILABLEon the page and in the streamed frame rather than silently substituting a degraded threshold — which means the two checks above would fail loudly, giving 39/41, not a quiet pass. That failure mode is why the weights ship. -
The self-test does not need the DCASE download. An earlier draft of this README said it did. That was wrong and it is corrected here rather than deleted.
scripts/smoke_dashboard.pydrives whatever server you point it at, so on a bare clone — no dataset, no microphone — these two commands are enough:scripts/run_demo.sh demo # terminal 1, synthetic clip, port 8000 .venv/bin/python scripts/smoke_dashboard.py \ --url http://127.0.0.1:8000 --enroll-seconds 10 # terminal 2
A verifier ran exactly that on a fresh clone and got 41 passed, 0 failed — the enrollment checks included, because
models/ae_fp32.weights.h5ships. That run is quoted from the audit record: it wrote its own JSON, not the committedbenchmarks/dashboard_smoke.json, which is the DCASE-fed run above. What changes without the dataset is the audio, not the number of checks.scripts/run_demo.sh checkwraps the same client. It prefersdata/fan/test/normal_id_00_00000000.wavwhen the dataset is present and falls back to the committed synthetic clip when it is not, printing an explicit SKIPPED block for the parts that genuinely need DCASE audio so a synthetic run can never be mistaken for a real-audio one. Only the DCASE-fed run is evidence about audio; both are evidence about the plumbing. -
The self-test modifies nothing that is tracked. Everything it produces is run-specific — a fresh enrollment, a fresh websocket capture — and goes to the git-ignored
work/selftest/, sogit statusis still clean when it finishes. That is a deliberate property: the publish checklist forbids pushing with a modified working tree, and until 2026-08-02 runningcheckbroke that rule by overwritingmodels/enrollment.json,benchmarks/dashboard_smoke.json,benchmarks/dashboard_enrollment_last.jsonandbenchmarks/alert_transition*.jsonin place. The committedbenchmarks/*.jsonare now purely the recorded runs thatscripts/report_numbers.pyreads; diffwork/selftest/against them to see what your machine measured, and pass--out benchmarks/<name>.jsonwhen you actually mean to re-record one.
| Claim | Regenerate with |
|---|---|
| YAMNet / AE kernel-only latency | scripts/bench_litert.py models/yamnet_int8.tflite --threads 1 --invokes 1000 |
| Interleaved fair benchmark, deployed timed region, real input | scripts/bench_litert.py models/yamnet_fp32.tflite --interleave models/yamnet_int8.tflite --measure-io --real-input data/fan/test/normal_id_02_00000000.wav --threads 1 --invokes 1000 --blocks 10 --out bench_fair_interleaved_withio_realinput_1t.json |
Thread scaling sweep (both thread_sweep*.json) |
scripts/thread_sweep.py (--out defaults to benchmarks/thread_sweep.json) |
Sustained 30 s throughput (throughput_yamnet_*_1t.json) |
bench/power_load.py models/yamnet_int8.tflite --seconds 30 --threads 1 --out benchmarks/throughput_yamnet_int8_1t.json (same for yamnet_fp32 and yamnet_int8_randcal) |
| MAC counts | scripts/count_tflite_macs.py models/yamnet_fp32.tflite models/yamnet_int8.tflite models/ae_fp32.tflite models/ae_int8.tflite (model paths are required; --out defaults to benchmarks/tflite_macs.json) |
| INT8 export and calibration ablation | scripts/export_yamnet.py, then scripts/requantize_yamnet.py |
| Why plain min/max calibration failed | scripts/diagnose_yamnet_quant.py |
| YAMNet FP32-vs-INT8 agreement | scripts/eval_yamnet_agreement.py --corpus esc50 / --corpus esc50 --folds 2,3,4,5 / --corpus fan |
| Autoencoder training data | scripts/prepare_dcase.py, then scripts/train_ae.py |
| Autoencoder ROC-AUC / pAUC | scripts/eval_ae.py models/ae_fp32.tflite and scripts/eval_ae.py models/ae_int8.tflite |
| Default alert threshold and its rates | scripts/calib_dashboard.py |
| Engine per-stage latency on real audio | scripts/smoke_engine.py |
| Live dashboard latency, 41 checks, precision toggle | scripts/smoke_dashboard.py --url http://127.0.0.1:8021 --enroll-seconds 10 --out benchmarks/dashboard_smoke.json |
| Alert transition and latch | scripts/verify_alert_transition.py --seconds 45 --out benchmarks/alert_transition.json, scripts/smoke_dashboard_alert.py --out benchmarks/dashboard_alert_smoke.json |
| Alert transition on the committed synthetic clip (no dataset needed) | scripts/verify_alert_transition.py --seconds 70 --clip assets/demo/synthetic_fan_normal_then_fault.wav --out benchmarks/alert_transition_synthetic.json |
| Enrollment on a seen and an unseen machine | scripts/smoke_enroll.py |
| Arm64 Linux portability | scripts/verify_portability_linux_arm64.sh |
| KleidiAI inventory and ISA gating | work/kleidiai_inventory.py |
| Microkernel attribution + disassembly | work/microkernel_probe.sh MODEL TAG, then work/summarize_profiles.py |
| KleidiAI probe models | work/export_drq_probe.py |
Run everything from the repository root with .venv/bin/python. Scripts that
need audio require scripts/fetch_data.sh first. The work/ directory holds the
Arm investigation's probes, raw sample(1) profiles and probe models; it is the
appendix to docs/ARM_OPTIMIZATION.md.
| Path | What |
|---|---|
app/server.py, app/templates/ |
Flask + websocket dashboard, one self-contained HTML page, no external assets |
src/engine.py |
the real-time core: both log-mel frontends, both models, per-stage timing |
src/enrollment.py |
capture → fine-tune → re-quantize → threshold, with the keep-or-revert guard |
src/audio_source.py |
microphone and file sources, resampling, drop accounting |
models/ |
the four shipped .tflite artifacts, the latency-only randcal one, and ae_fp32.weights.h5 (the Keras weights ENROLL fine-tunes from) |
vendor/yamnet/ |
yamnet_class_map.csv verbatim from Google, plus its LICENSE and a README.md recording where it came from |
assets/demo/ |
the synthetic clip scripts/run_demo.sh demo plays — generated from numpy, no dataset audio, a UI aid and not evidence |
scripts/ |
setup, data fetch, export, quantization, evaluation, benchmarks, smoke tests, and rehearse_demo.py (operator rehearsal of a live demo — a demonstration, not a measurement) |
benchmarks/ |
every raw measurement JSON |
docs/ARM_OPTIMIZATION.md |
the Arm-specific investigation |
work/ |
its probes, profiles and probe models |
Code in this repository is Apache-2.0 (LICENSE, NOTICE).
The model binaries are not all under that licence and
MODELS.md states the terms per artifact.
models/yamnet_fp32.tflite is a conversion of Google's Apache-2.0 YAMNet
weights. models/ae_*.tflite were trained on the DCASE2020 Task 2 fan dataset
and models/yamnet_int8.tflite took its quantization ranges from DCASE and
ESC-50 audio, so those carry the datasets' NonCommercial terms (CC BY-NC-SA
4.0 / CC BY-NC 3.0). No audio from either dataset is committed: data/ is
git-ignored and a pre-commit hook refuses to stage it. Full licence texts,
citations and attributions: THIRD_PARTY.md.
Built solo with AI-assisted development (Anthropic Claude) for code drafting and documentation; all optimization design, Arm-platform implementation, benchmarks, and final verification are my own original work.
