# tff.simulation.run_training_process

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Runs a federated `training_process`.

    tff.simulation.run_training_process(
        training_process: https://www.tensorflow.org/federated/api_docs/python/tff/templates/IterativeProcess,
        training_selection_fn: Callable[[int], Any],
        total_rounds: int,
        evaluation_fn: Optional[Callable[[Any, Any], MetricsType]] = None,
        evaluation_selection_fn: Optional[Callable[[int], Any]] = None,
        rounds_per_evaluation: int = 1,
        program_state_manager: Optional[https://www.tensorflow.org/federated/api_docs/python/tff/program/ProgramStateManager] = None,
        rounds_per_saving_program_state: int = 1,
        metrics_managers: Optional[Iterable[release_manager_lib.ReleaseManager]] = None
    )

The following [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) types signaures are required:

- `training_process.initialize`: `( -> state)`.
- `training_process.next`: `<state, client_data> -> <state, metrics>`
- `evaulation_fn`: `<state, client_data> -> metrics`

This function performs up to `total_rounds` updates to the `state` of the
given `training_process`. At each training round, this update occurs by
invoking `training_process.next` with `state` and the output of
`training_selection_fn`. Depending on `rounds_per_evaluation` and
`rounds_per_saving_program_state`, each training round may be followed by an
invocation of the `evaluation_fn` and by saving the program state.

> [!NOTE]
> **Note:** Round 0 represents saving an initial program model state and computing initial evaluation metrics and round 1 through total_rounds + 1 represent the training rounds.

In addition to the training metrics and evaluation metrics, this function adds
the following performance metrics (key and descriptions):

- tff.simulation.ROUND_NUMBER_KEY: The round number.
- tff.simulation.TRAINING_TIME_KEY: The amount of time (in seconds) it takes to run one round of training.
- tff.simulation.EVALUATION_TIME_KEY: The amount of time (in seconds) it takes to run one round of evaluation.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `training_process` | A [`tff.templates.IterativeProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/IterativeProcess) to run for training. |
| `training_selection_fn` | A `Callable` accepting an integer round number, and returning a list of client data to use for trainig in that round. |
| `total_rounds` | The number of training rounds to run. |
| `evaluation_fn` | An optional callable accepting the state of `training_process` and the output of `evaluation_selection_fn`, and returning a mutable mapping with string-valued keys. |
| `evaluation_selection_fn` | A optional `Callable` accepting an integer round number, and returning a list of client data to use for evaluation in that round. |
| `rounds_per_evaluation` | The number of training rounds to run between each invocation of `evaluation_fn`. |
| `program_state_manager` | An optional [`tff.program.ProgramStateManager`](https://www.tensorflow.org/federated/api_docs/python/tff/program/ProgramStateManager) to use to save program state for fault tolerance. |
| `rounds_per_saving_program_state` | The number of training rounds to run between saving program state. |
| `metrics_managers` | An optional list of `tff.program.ReleaseManagers`s to use to save metrics. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The `state` of the training process after training. ||

<br />