Skip to content

v18.6 — Lookup tables that hold across the whole format, logit-ranked classifiers, and a wider ONNX importer

Latest

Choose a tag to compare

@danmcleran danmcleran released this 21 Nov 01:28
· 11 commits to master since this release
65c6160

v18.6 — Lookup tables that hold across the whole format, logit-ranked classifiers, and a wider ONNX importer

Fixes

  • The exp table no longer wraps in narrow formats (#288). The table generator converted each value straight to the table's storage type, which wrapped when the format could not hold it. In Q8.8 the last nine exp entries were garbage, so exp(5.0) came out negative; the same overflow hit every format with fewer than 10 integer bits, stored cos(0) as -1 in every Q1 format and overflowed log in the Q1 and Q2 formats. Entries now saturate, and every in-range entry is unchanged.
  • log, sin and cos reduce their input instead of clamping it (#291, fixes #289 and #290). These three used the same 96-knot table over [-6, 6) as the activations. log interpolated every input below 0.125 toward 0, so the cross-entropy loss fell as a prediction became more confidently wrong (0.166 at p = 0.01 instead of 4.605), and sin and cos returned the value at 5.875 for every input of 6 or more. The new cpp/lookupFunctions.hpp writes x as m * 2^e and reads log(m) from a 65-entry table over [1, 2], and it reduces sin and cos by pi/2 into a 65-entry quarter-wave table. In Q16.16, log is within 8e-5 of std::log for every positive input, and sin and cos are within 1.2e-4 of std::sin and std::cos over the whole range of the format. CrossEntropyLossCalculator and the fixed-point dual numbers use them.

New features

  • getPredictedClass() ranks classifier outputs by their logits (#293). The fixed-point sigmoid table is flat beyond ±6, so confident outputs tie there and an argmax over getLearnedValues() can only pick the first of them. NeuralNetwork::getOutputPreActivations() returns the output layer's logits, bit-exact with what the layer computed and at no extra memory, and getPredictedClass() returns their argmax. The gas_sensor_drift, iris, optical_digits and har_activity examples now use it. Over 10 seeds, gas_sensor_drift's batch-10 accuracy rises from 0.726 to 0.766 and improves on every seed; optical_digits improves slightly, and iris and har_activity are unchanged.
  • The ONNX importer covers residual CNNs (#286). It now maps depthwise convolution to QDepthwiseConv2D, MaxPool to QMaxPool2D, average and global average pooling to a QDepthwiseConv2D that averages and changes grid in one rounding, a residual Add to QAdd, and QLinearSoftmax to a softmax record. A new layer-graph check refuses a model in which a layer reads a tensor in a different grid from the one the previous layer wrote, which used to import silently and compute something else, and each record lists the layers it reads. This was contributed as a patch from the tinymind-rs port of the importer.

Removed

  • The 128-bit lookup tables (#292, fixes #287). They did not compile, and no format could read them, since QValue caps a format at 64 bits. The six cpp/*Values128Bit.hpp headers are deleted, and cpp/lookupTables.cpp shrinks from about 145,000 lines to 59,000. All 8- to 64-bit tables are byte-identical.

Upgrade notes

  • log, sin and cos now return different, correct values outside the old table range, and the log and trig tables hold 65 entries instead of 96. Cross-entropy losses reported during training change accordingly.
  • Code that included a *Values128Bit.hpp header directly no longer compiles; no build could have used those tables.

Docs

  • docs/activation-luts.md describes saturation, the log and trig table layout and the table sizes; docs/neural-networks.md explains how to pick a class; the README and the Pages index give the real 64-bit format ceiling and the table sizes (#294).

Documentation, architecture guides, and example gallery: https://danmcleran.github.io/tinymind/

Full changelog: v18.5...v18.6