# How to save local models?

**URL:** <https://discuss.flower.ai/t/how-to-save-local-models/1053>\
**Category:** Flower Help - Intermediate\
**Tags:** flower\
**Created:** [July 27, 2025, 11:26pm UTC](https://discuss.flower.ai/t/how-to-save-local-models/1053 "2025-07-27T23:26:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![john678](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@john678](https://discuss.flower.ai/u/john678)\
**Post date:** [July 27, 2025, 11:26pm UTC](https://discuss.flower.ai/t/how-to-save-local-models/1053/1 "2025-07-27T23:26:00Z")

</div>

Hello. I have studied how to save global model, but I also need to save/modify local models. After a client finishing its local epochs, how do I read/modify this model before it is aggregated? and I need to know ‘server round’ and ‘client id number’

---

<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:** [July 28, 2025, 2:09pm UTC](https://discuss.flower.ai/t/how-to-save-local-models/1053/2 "2025-07-28T14:09:29Z")

</div>

Hi @john678,

Thank you for your question. You could adjust a model before it is aggregated:

**On the client:** In a `Client/NumPyClient`, the `fit` method does three things: it deserialises the server‑sent parameters, updates the local model, trains for some epochs and then serialises the updated weights to send back to the server. You can insert your own logic here. For example, in a PyTorch client you could call `torch.save(model.state_dict(), …)` after `train(…)` to persist the local model or modify `ndarrays_updated` before converting them back to a Parameters object.

```python
class MyClient(fl.client.NumPyClient):
    def fit(self, parameters, config):
        # update local model
        ndarrays_original = fl.common.parameters_to_ndarrays(parameters)
        set_parameters(self.net, ndarrays_original)
        train(self.net, self.trainloader, epochs=config["local_epochs"])
        # get updated weights
        ndarrays_updated = get_parameters(self.net)

        # e.g. save a PyTorch checkpoint
        torch.save(self.net.state_dict(), f"client_{self.cid}_round_{config['server_round']}.pth")
        # or modify the update before sending it back
        # ndarrays_updated = clip_weights(ndarrays_updated)

        # send the (possibly modified) update back
        return ndarrays_updated, len(self.trainloader), {}

```

Hope this helps, I think it can be done on the server as well, just gave some initial thoughts.

---

<div class="post-metadata">

**Author:** ![john678](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@john678](https://discuss.flower.ai/u/john678)\
**Post date:** [July 29, 2025, 9:17am UTC](https://discuss.flower.ai/t/how-to-save-local-models/1053/3 "2025-07-29T09:17:10Z")

</div>

Thanks this is helpful.  
For others who has the same question, please check Sending/receiving arbitrary values to/from clients from [Use a federated learning strategy - Flower Framework](https://flower.ai/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html#Sending/receiving-arbitrary-values-to/from-clients)

and server can receive client’s values by handle\_fit\_metrics(), please study [Sending ClientApp Metrics - 2025 Tutorial: Federated AI Simulations with Flower - YouTube](https://www.youtube.com/watch?v=dZRDe1ldy5s)

---

<div class="post-metadata">

**Author:** ![john678](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@john678](https://discuss.flower.ai/u/john678)\
**Post date:** [July 29, 2025, 9:35am UTC](https://discuss.flower.ai/t/how-to-save-local-models/1053/4 "2025-07-29T09:35:26Z")

</div>

Ok I have studied that server should read client’s returned value in fit\_metrics\_aggregation\_fn, but it is not told explicitly in tutorial [Use a federated learning strategy - Flower Framework](https://flower.ai/docs/framework/tutorial-series-use-a-federated-learning-strategy-pytorch.html#Sending/receiving-arbitrary-values-to/from-clients)  
I think it’s better to tell people in the tutorial. Hope this is useful for others

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/flower/original/1X/bc7fe36843c391cbd0b4e8b6f48275961d356abc.png) [@system](https://discuss.flower.ai/u/system)\
**Post date:** [August 5, 2025, 9:35am UTC](https://discuss.flower.ai/t/how-to-save-local-models/1053/5 "2025-08-05T09:35:44Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
