Hi,
I’m using the pytorch example project and I want to use TinyML [1]. How can I do this? Is this something I can do with flower directly or do I have to go another way?
[1] Federated learning for IoT devices: Enhancing TinyML with on-board training - ScienceDirect
Welcome to the Flower community, @neonduck!
Great question. While Flower’s PyTorch example runs on devices with full Python (like laptops, Raspberry Pi, or Jetson), true TinyML requires tweaks.
Microcontrollers typically can’t run PyTorch or perform on-device training due to memory constraints (usually <256KB SRAM).
Flower does support clients in any language (like C++), but you’d need to implement a lightweight client and use a compatible TinyML framework for inference. Here’s a good reference on running FL on embedded devices.
Let us know more about your setup and we can help point you in the right direction!
1 Like
Thanks for the answer!
So I have to use some other ML framework that is also supported by Flower? As far as I understand is TensorFlow a better solution for that?
The goal of my experiment would be a FL model that is able to run on Smart Home devices that have similar ressources like devices that are used in the real-world. I have a Raspberry Pi 5 that acts like a gateway (DiyHue), an RPi that acts like a voice assisstant but also a motion sensor (Sonoff SNZB-03), Sonoff NS Panel Pro 120, Android 13 Device, and a Sonoff IP Security Camera.
@neonduck Thanks for clarifying your setup!
If your goal is to eventually deploy models to resource-constrained devices like the Sonoff units, you’re right that TensorFlow Lite Micro (TFLM) is often the go-to for true TinyML on microcontrollers. PyTorch itself can’t run directly on such low-memory devices, but you can:
-
Train in PyTorch (or another full ML framework) on more capable devices (like your Raspberry Pi 5 gateway or other edge nodes).
-
Export the trained model to a format supported by your target TinyML runtime (e.g., convert PyTorch → ONNX → TFLM, or train in TF and export directly to TFLM).
-
Run inference on the microcontrollers with TFLM (or similar) while keeping the heavier FL client logic on devices that can handle it.
-
Use the Pi(s) as Flower clients — they can participate in federated training, then push converted models down to your smaller devices for deployment.
So in short: Flower can still orchestrate the FL part for your capable devices, and you can integrate a conversion + deployment step for the smaller ones. TensorFlow (via TFLM) is indeed a solid choice for the final microcontroller stage, but you don’t have to switch your whole training pipeline to TF unless you want to simplify that conversion.
I figured out that PyTorch has a C++ framework. Could this be a possible solution with Flower’s C++ to use less resources? Further, it seems that PyTorch has a TinyML integration
sorry for delayed reply,
both links could provide possible solutions and we do need to update our C++ SDK anyway.
Did you try out if the any of the suggested links work? (some sort of minimal example) @neonduck
I will create one in the next weeks but I have to work on a paper before.
1 Like