Skip to content

v18.3 — on-device fine-tuning heads

Choose a tag to compare

@danmcleran danmcleran released this 13 Nov 14:43
· 24 commits to master since this release
3d89270

v18.3 — on-device fine-tuning heads

New features

  • Head-only fine-tuning. Two standalone heads adapt a frozen model on the device from a few labelled samples, without backpropagating through the model (#277).
    • DenseHead (cpp/densehead.hpp) is a trainable dense layer with a softmax cross-entropy loss (the default) or a squared-error loss. Its SGD step rounds learning rate × gradient to nearest like every other trainable layer, and the update is fused into the backward pass, so its RAM is only its parameters: 792 bytes for a 32-value embedding and 6 classes in Q16.16. backward() returns the gradient with respect to the embedding for callers that also adapt layers in front of the head. In fixed point the softmax gives probability 0 to classes more than 6 behind the largest logit, beyond the exp table; otherwise the gradient never reaches zero and a well-separated head grows its logits until the format wraps.
    • PrototypeHead (cpp/prototypehead.hpp) is a gradient-free nearest-class-mean classifier: one running mean per class, an optional count cap that turns it into a moving average, and squared-Euclidean or Manhattan distance. It needs no learning rate or epochs, and a class can be added at any time.
    • The squared-error DenseHead and both PrototypeHead distances run at TINYMIND_ENABLE_FLOAT=0, TINYMIND_ENABLE_STD=0, and are exercised in every embedded gate corner.

Examples

  • gas_sensor_drift now corrects the drift it shows. The trained 128→32→6 MLP is split into a frozen backbone and a head (bit-exact on the hidden layer), and seven ways to adapt to each drifted batch are compared from 1 to 20 labelled samples per class. Over data seeds 1 to 10, batch 10 accuracy rises from 0.766 unadapted to 0.985 with a PrototypeHead and to 0.936 with head-only fine-tuning from one sample per class (0.988 from five). Training the backbone's biases as well adds almost nothing, and re-normalizing the inputs from the whole unlabelled batch reaches 0.924, because by batch 10 the drift has flipped the sign of some features' gain. After adapting, the DenseHead still classifies the original batch perfectly while the PrototypeHead has partly forgotten it. The data is synthetic and cleanly separable, so this is a demonstration on one drift model, not a general ranking.

Docs

  • A new on-device fine-tuning guide covers the API, how to choose between the heads, memory against training the whole network (an inference-only model plus a head needs 28% of the RAM), and what the application still owns: saving the adapted head, forgetting, and label quality.
  • The heads are listed on the Pages landing table and the architectures overview (#278), and the gallery has the new adaptation plot.

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

Full changelog: v18.2...v18.3