# PyTorch example clients into TinyML

**URL:** <https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066>\
**Category:** Flower Help - Beginners\
**Created:** [August 1, 2025, 9:44am UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066 "2025-08-01T09:44:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![neonduck](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@neonduck](https://discuss.flower.ai/u/neonduck)\
**Post date:** [August 1, 2025, 9:44am UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/1 "2025-08-01T09:44:21Z")

</div>

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](https://www.sciencedirect.com/science/article/pii/S1566253523005055)

---

<div class="post-metadata">

**Author:** ![williamlm](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/williamlm/32/162_2.png) [@williamlm](https://discuss.flower.ai/u/williamlm)\
**Post date:** [August 1, 2025, 5:17pm UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/2 "2025-08-01T17:17:39Z")

</div>

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](https://github.com/adap/flower/tree/main/examples/embedded-devices).

Let us know more about your setup and we can help point you in the right direction!

---

<div class="post-metadata">

**Author:** ![neonduck](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@neonduck](https://discuss.flower.ai/u/neonduck)\
**Post date:** [August 6, 2025, 7:44am UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/3 "2025-08-06T07:44:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![williamlm](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/williamlm/32/162_2.png) [@williamlm](https://discuss.flower.ai/u/williamlm)\
**Post date:** [August 11, 2025, 6:21pm UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/4 "2025-08-11T18:21:54Z")

</div>

@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:

1. **Train in PyTorch (or another full ML framework) on more capable devices** (like your Raspberry Pi 5 gateway or other edge nodes).

2. **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).

3. **Run inference on the microcontrollers** with TFLM (or similar) while keeping the heavier FL client logic on devices that can handle it.

4. **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.

---

<div class="post-metadata">

**Author:** ![neonduck](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@neonduck](https://discuss.flower.ai/u/neonduck)\
**Post date:** [September 1, 2025, 7:33am UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/5 "2025-09-01T07:33:49Z")

</div>

I figured out that PyTorch has a [C++ framework](https://docs.pytorch.org/docs/stable/cpp_index.html). Could this be a possible solution with Flower’s C++ to use less resources? Further, it seems that PyTorch has a [TinyML](https://www.codegenes.net/blog/pytorch-tinyml/) integration

---

<div class="post-metadata">

**Author:** ![williamlm](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/williamlm/32/162_2.png) [@williamlm](https://discuss.flower.ai/u/williamlm)\
**Post date:** [September 15, 2025, 11:43am UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/6 "2025-09-15T11:43:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![neonduck](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@neonduck](https://discuss.flower.ai/u/neonduck)\
**Post date:** [September 15, 2025, 4:13pm UTC](https://discuss.flower.ai/t/pytorch-example-clients-into-tinyml/1066/7 "2025-09-15T16:13:51Z")

</div>

I will create one in the next weeks but I have to work on a paper before.
