Skip to main content
Visitor II
August 17, 2026
Solved

On-device fine-tuning in 608 bytes — GravOptMini optimizer + W-Twin health monitor for STM32

  • August 17, 2026
  • 1 reply
  • 44 views

Built a minimal on-device training stack for STM32 — fits in 608 bytes RAM total.

The problem: Adam optimizer needs exp_avg + exp_avg_sq — 2× parameter RAM. On STM32F103 (20KB SRAM) with a 5K parameter model that's 40KB just for optimizer state. Doesn't fit.

What I built:

GravOptMini — momentum optimizer with quantile-based gradient freeze. Only exp_avg (1× param RAM). Freezes low-gradient parameters to reduce compute.

W-Twin Lite — power-law baseline fitted on early steps, tracks deviation. Pure float32, no scipy, no numpy. Rolling window of 20 values. ~240 bytes.

Benchmark (Python simulation, STM32 memory constraints):
- Model: 46 params, 184 bytes
- GravOptMini state: 368 bytes (exp_avg only)
- W-Twin Lite: 240 bytes
- Total: 608 bytes
- MNIST accuracy: 93.2% vs Adam 97.4%
- W-Twin overhead: 3.9% per step
- Detection: anomaly caught 96 steps before visible loss divergence, 0 false alarms on clean run

Next step is a real STM32 test with physical hardware. C port of both components is the plan.

Has anyone done on-device fine-tuning on STM32? Curious what optimizer you used and what constraints you hit.

Code: github.com/Kretski/WTwin

Best answer by Julian E.

Hi ​@Kretski,

 

As of today, the only On device fine tuning that we have is the Anomaly detection from NanoEdge AI Studio.

By importing “normal” and “abnormal” dataset to NanoEdge AI Studio, the AutoML tool will look for the best AI library (+ preprocessing) and give you an AI library ready to be deployed on any STM32.

 

With Anomaly detection projects, you can deploy the AI library with or without its knowledge and learn new data directly on the target to specialize on the final environment for example.

 

Depending on your project this could be a good start.

NanoEdge is mostly capable of managing Machine learning problems (time series data).

 

NanoEdge AI Studio - STMicroelectronics - STM32 AI

NanoEdge AI Studio - ST Edge AI documentation

 

Have a good day,

Julian

1 reply

Julian E.
Julian E.Best answer
ST Technical Moderator
October 1, 2026

Hi ​@Kretski,

 

As of today, the only On device fine tuning that we have is the Anomaly detection from NanoEdge AI Studio.

By importing “normal” and “abnormal” dataset to NanoEdge AI Studio, the AutoML tool will look for the best AI library (+ preprocessing) and give you an AI library ready to be deployed on any STM32.

 

With Anomaly detection projects, you can deploy the AI library with or without its knowledge and learn new data directly on the target to specialize on the final environment for example.

 

Depending on your project this could be a good start.

NanoEdge is mostly capable of managing Machine learning problems (time series data).

 

NanoEdge AI Studio - STMicroelectronics - STM32 AI

NanoEdge AI Studio - ST Edge AI documentation

 

Have a good day,

Julian

​In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.