# How to Train on a Fixed Number of Mini-Batches per Round

**URL:** <https://discuss.flower.ai/t/how-to-train-on-a-fixed-number-of-mini-batches-per-round/553>\
**Category:** Flower Help - Beginners\
**Created:** [January 7, 2025, 6:32pm UTC](https://discuss.flower.ai/t/how-to-train-on-a-fixed-number-of-mini-batches-per-round/553 "2025-01-07T18:32:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luikalu](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@luikalu](https://discuss.flower.ai/u/luikalu)\
**Post date:** [January 7, 2025, 6:32pm UTC](https://discuss.flower.ai/t/how-to-train-on-a-fixed-number-of-mini-batches-per-round/553/1 "2025-01-07T18:32:03Z")

</div>

Hi everyone,

I’m working on a federated learning setup using Flower and would like to train each client on a fixed number of mini-batches per round instead of a full epoch. I noticed that the `pyproject.toml` file allows setting `local_epochs`, and the Flower documentation mentions that training can be limited to “as little as a few steps (mini-batches)” in each round

However, I’m unsure how to implement this efficiently:

1. Is there a built-in way to specify a fixed number of mini-batches per round using `pyproject.toml` or client configuration?
2. Or would I need to manually define an iterator within the client class to handle this?

Any guidance or best practices would be greatly appreciated!

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![daniel](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/daniel/32/77_2.png) [@daniel](https://discuss.flower.ai/u/daniel)\
**Post date:** [January 9, 2025, 6:50pm UTC](https://discuss.flower.ai/t/how-to-train-on-a-fixed-number-of-mini-batches-per-round/553/2 "2025-01-09T18:50:06Z")

</div>

Hi there, welcome to the Flower community!

Instead of specifying `local_epochs` in `pyproject.toml`, you could specify `num_batches` and then use that value in your local training pipeline to control the number of mini batches (e.g., in your PyTorch training function). Flower doesn’t control the local training function, it merely provides a way to communicate hyper-parameters from server to client.

Does this answer your question?

---

<div class="post-metadata">

**Author:** ![luikalu](https://avatars.discourse-cdn.com/v4/letter/l/ccd318/32.png) [@luikalu](https://discuss.flower.ai/u/luikalu)\
**Post date:** [January 14, 2025, 4:16pm UTC](https://discuss.flower.ai/t/how-to-train-on-a-fixed-number-of-mini-batches-per-round/553/3 "2025-01-14T16:16:35Z")

</div>

Thanks for the reply.  
I solved it how you propsed, and with an interator class.
