# Implement Custom FL Strategy

**URL:** https://discuss.flower.ai/t/implement-custom-fl-strategy/202
**Category:** Flower Help - Beginners
**Created:** [April 17, 2024, 2:49pm UTC](https://discuss.flower.ai/t/implement-custom-fl-strategy/202 "2024-04-17T14:49:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ruhul5347](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@ruhul5347](https://discuss.flower.ai/u/ruhul5347)
#### Post date: [April 17, 2024, 2:49pm UTC](https://discuss.flower.ai/t/implement-custom-fl-strategy/202/1 "2024-04-17T14:49:24Z")

</div>

I want to implement an FL algorithm and run it like [flower-simulation-step-by-step-pytorch](https://github.com/adap/flower/tree/main/examples/flower-simulation-step-by-step-pytorch/Part-I). Therefore, I have to change the strategy from the line 55 to 78 in the **main.py** file. Suppose my strategy name is FedNew. What steps should I follow to do this type of strategy implementation? If there is any example code available please share.

Thank you

---

<div class="post-metadata">

### Author: ![yan-gao](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/yan-gao/32/39_2.png) [@yan-gao](https://discuss.flower.ai/u/yan-gao)
#### Post date: [April 29, 2024, 4:36am UTC](https://discuss.flower.ai/t/implement-custom-fl-strategy/202/2 "2024-04-29T04:36:38Z")

</div>

Hi @ruhul5347, you could customise a new strategy (e.g., inherited from FedAvg) as below:

```auto
class FedNew(flwr.server.strategy.FedAvg):
    def __init__ (**kwargs: Any,)
        # define any new arguments
        super(). __init__ (**kwargs)

    def aggregate_fit(
        self,
        server_round: int,
        results: List[Tuple[ClientProxy, FitRes]],
        failures: List[Union[Tuple[ClientProxy, FitRes], BaseException]],
    ) -> Tuple[Optional[Parameters], Dict[str, Scalar]]:
        # define new aggregation methods here

    def configure_fit(
        self, rnd: int, parameters: Parameters, client_manager: ClientManager
    ) -> List[Tuple[ClientProxy, FitIns]]:
        # override client sampling method if needed

```

Note that `aggregate_fit()` and `configure_fit()` are for training. If doing changes for evaluation, then override `aggregate_evaluate()` and `configure_evaluate()`.

Then, call this new `FedNew` strategy similar to line 68 in main.py.  
`strategy = FedNew(...)`

---

<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 1, 2025, 3:32pm UTC](https://discuss.flower.ai/t/implement-custom-fl-strategy/202/3 "2025-08-01T15:32:47Z")

</div>

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