Skip to content

v18.0 — Every trainable model audited: what was learning by accident, and the fixes

Choose a tag to compare

@danmcleran danmcleran released this 10 Nov 17:04
· 36 commits to master since this release
6d383af

v18.0 — Every trainable model audited: what was learning by accident, and the fixes

v17.0 found that LSTM and GRU gates had never trained while the examples still looked good. That raised the question of what else was producing good results without training correctly, so every trainable component in tinymind was audited. Each parameter's update was compared with central finite differences of the library's own forward pass, every parameter group was checked to move during training, each example was compared with a trivial baseline and with the same model training only its readout, and every check was shown to catch a planted defect before it was trusted.

The core held up: plain gradient descent for feed-forward networks, single-layer LSTM, GRU and Elman networks, the convolution, pooling and attention layers, KAN, the PINN and its automatic differentiation, LTC, CfC, the ANFIS trainer and the PyTorch and tree importers all train every parameter with the correct gradient. The defects were in the add-ons around that core, and four published results depended on them.

This is a major release: some APIs changed and some removed features never worked. If you trained a model with Adam, RMSprop, batching, stacked recurrent layers, Q-learning or DQN, retrain it.

Results that depended on a bug

  • elman_vowels: 96.76% → 92.97%. Its per-utterance reset stopped working in v17.0, so context leaked from one utterance into the next during training and evaluation. With a real reset, float, Q16.16 and Q8.8 agree on all 370 test utterances at 92.97%.
  • maze and dqn_maze found shortest paths with the wrong Q values. The update learned from the exploring policy's random next action instead of the best one, and the DQN skipped training whenever its error was inside the fixed-point zero tolerance, which froze it after about 200 of 10,000 episodes. Both now learn the optimal Q values (maze within 0.0007, dqn_maze 0.0017 RMS, against 2.15 and 3.07 before) and still take a shortest path in 100 of 100 runs.
  • energy_efficiency lost to linear regression because it skipped training on any sample within the zero tolerance. Without that gate: test R² 0.903 / 0.883 → 0.958 / 0.924 (heating / cooling), MAE 2.80 / 2.77 → 1.69 / 1.95.
  • lstm_sinusoid_float stopped training for the same reason, so training only the readout beat training everything. Training every step: one-step RMS 0.044 → 0.0058.

Library fixes

  • Fixed-point momentum never let a weight change decay. The momentum terms were rounded with the format's own rounding policy, so 0.5 times a one-LSB change rounded back to one LSB and repeated forever: affected weights drifted by an LSB on every step whatever the gradient, which saturated long recurrent runs. The momentum products now round toward zero; floating-point results are bit-identical. Every fixed-point example that trains with momentum was re-measured: gas_sensor_drift on its most-drifted batch 0.734 → 0.792, optical_digits 1729 → 1732 of 1797, predictive_maintenance F1 0.805 → 0.798 on synthetic data and 0.657 → 0.692 on the real UCI CSV, air_quality MAE 0.0672 → 0.0692, gru_xor 0.0606 → 0.0590.
  • Adam and RMSprop never updated any bias, including gate biases; Adam advanced its timestep once per layer instead of once per update; weight decay was ignored under both. All fixed. Fixed-point defaults are now correct in every Q format (they were Q8.8 raw values, giving Adam β1 = 0.0035 in Q16.16), fixed-point Adam's bias correction no longer stops at step 100, and gradient clipping is symmetric and covers biases. Fixed-point Adam now defaults to β2 = 0.99 and ε = sqrt(LSB/(1−β2)) because the textbook constants round small gradients to zero; the float optimizer keeps the textbook values.
  • Stacked recurrent layers (HiddenLayers<A,B> with LSTM, GRU or Elman) now train every weight; before, the inner layers' gates and input weights never moved and their recurrent weights were never initialised. resetState() clears every layer, setWeights copies every weight, and weight files keep every weight at full precision.
  • BatchSize > 1 now applies the mean gradient once per batch, biases included. Before, it applied a stale average on every sample and did not compile under -Werror.
  • Activations: the softmax classifier output trained in the wrong direction; GELU's derivative was taken at the output instead of the input; CappedReluActivationPolicy did not cap. All fixed.
  • Layers: BatchNorm1D returned the wrong input gradient and normalised across one sample's features; it now has a batch API with per-feature statistics and an exact gradient, and its single-sample path computes the same function in training and inference. BinaryDense clips latent weights to [−1, 1] so they cannot freeze. Xavier "normal" initialisation now draws from a normal distribution.
  • Q-learning: updateFromExperience uses experience.state; exploration probability is exactly p/100; learning rate and discount factor of 1.0 are accepted; the DQN target network starts as a copy of the online network; ties between two actions are broken at random.
  • std::vector<QValue> compiles at C++17 and C++20.

Breaking changes

  • cpp/truncatedBPTT.hpp is removed. It trained once every K steps on the last target only; training uses one-step truncation.
  • RecurrentConnectionDepth other than 1 no longer compiles; it never had any effect.
  • BatchNorm1D gains a MaxBatchSize parameter and forwardBatch/backwardBatch; its single-sample path normalises with running statistics.
  • resetState() moved to the base network class.
  • Weight files for recurrent networks, and for feed-forward networks whose hidden layers differ in size, use a new layout (the old files were missing weights).
  • Fixed-point Adam, RMSprop, learning-rate schedule and weight-decay defaults changed.

Export and import

  • PyTorch GRU export produced a model that tinymind computed differently (PyTorch 4/4 on XOR, tinymind 1/4). The exporter now converts the update-gate convention and keeps the one bias tinymind cannot represent at zero during training; parity is 3e-13 in double.
  • ONNX importer silently produced no layers for ONNX Runtime's default QDQ format and dropped dense layers in QOperator models. It now reads both, emits the layouts tinymind's layers expect, and refuses anything it cannot map exactly; int8 outputs match ONNX Runtime within 1 LSB.

Examples made honest

  • har_activity could be solved without recurrence. Two of its classes are now time-reversals of each other: 92.5% test accuracy, against 50% for readout-only and 52.5% for a nearest-centroid baseline.
  • lstm_sinusoid is now scored on a held-out signal: one-step RMS 0.0076, free-run 0.011.
  • cfc_sequence now needs its time step: the full model beats one that ignores it by 11.4x.
  • anfis_mackey_glass_int8 calibrates from the training split only (int8 RMSE 0.008566); import_demo trains properly (held-out MSE 2.3e-6); kan_xor now fails when it does not learn.

Docs

  • docs/size-comparison.md is now generated by tools/size_report/. Instance sizes are unchanged; a ratio table that divided by the wrong network is corrected, and the GCC/Clang code-size snapshot, stale since August, is current.
  • Every changed example has its README, Pages page and dark-theme plot updated.

How the fixes are verified

  • Every fix has a regression test that fails when the fix is reverted.
  • New finite-difference gradient checks cover stacked recurrent networks, Adam and RMSprop on every weight and bias, softmax and GELU outputs and BatchNorm1D. Q-learning is checked against value-iteration optimal values, and fixed-point momentum is checked to decay to zero.

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

Full changelog: v17.0...v18.0