Skip to content

Commit b9256b2

Browse files
committed
cr
1 parent 31322d6 commit b9256b2

3 files changed

Lines changed: 38 additions & 17 deletions

File tree

examples/nnunet_example/client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,19 @@ def main(
204204
args = parser.parse_args()
205205

206206
# Set the random seed for reproducibility
207-
set_all_random_seeds(args.seed, disable_torch_benchmarking=True, use_deterministic_torch_algos=True)
207+
208+
# NOTE: This implementation does not cover all sources of randomness in nnUNet, so complete
209+
# determinism cannot be achieved. The nnUNet maintainers have confirmed that full determinism
210+
# is not possible (see linked issue below). However, our current approach provides a reasonable
211+
# level of deterministic behavior for most practical purposes.
212+
# Reference: https://github.com/VectorInstitute/FL4Health/pull/411#:~:text=MIC%2DDKFZ/nnUNet%231906
213+
set_all_random_seeds(
214+
# NOTE: Setting seed comes at the cost of runtime performance. Benchmarking especially should be enabled
215+
# for long-running experiments.
216+
args.seed,
217+
disable_torch_benchmarking=True,
218+
use_deterministic_torch_algos=True,
219+
)
208220

209221
# Set the log level
210222
update_console_handler(level=args.logLevel)

examples/nnunet_pfl_example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To run a federated learning experiment with nnunet models, first ensure you are
1010
python -m examples.nnunet_pfl_example.server --config_path examples/nnunet_pfl_example/config.yaml
1111
```
1212

13-
Once the server has started, start the necessary number of clients specified by the n_clients key in the config file. Each client can be started by running the following command in a separate session. To view a list of optional flags use the --help flag.
13+
Once the server has started, start the necessary number of clients specified by the `n_clients` key in the config file. Each client can be started by running the following command in a separate session. To view a list of optional flags use the --help flag.
1414

1515
```bash
1616
python -m examples.nnunet_pfl_example.client --dataset_path examples/datasets/nnunet --personalized-strategy ditto

examples/nnunet_pfl_example/client.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,20 @@ def main(
8888
checkpoint_and_state_module = None
8989

9090
# Create client
91-
client_kwargs: dict[str, Any] = {}
92-
client_kwargs.update(
91+
client_kwargs: dict[str, Any] = {
9392
# Args specific to nnUNetClient
94-
dataset_id=dataset_id,
95-
fold=fold,
96-
always_preprocess=always_preprocess,
97-
verbose=verbose,
98-
compile=compile,
93+
"dataset_id": dataset_id,
94+
"fold": fold,
95+
"always_preprocess": always_preprocess,
96+
"verbose": verbose,
97+
"compile": compile,
9998
# BaseClient Args
100-
device=device,
101-
metrics=[dice],
102-
progress_bar=verbose,
103-
checkpoint_and_state_module=checkpoint_and_state_module,
104-
client_name=client_name,
105-
)
99+
"device": device,
100+
"metrics": [dice],
101+
"progress_bar": verbose,
102+
"checkpoint_and_state_module": checkpoint_and_state_module,
103+
"client_name": client_name,
104+
}
106105
if personalized_strategy in personalized_client_classes:
107106
log(INFO, f"Setting up client for personalized strategy: {personalized_strategy}")
108107
client = personalized_client_classes[personalized_strategy](**client_kwargs)
@@ -226,8 +225,18 @@ def main(
226225
args = parser.parse_args()
227226

228227
# Set the random seed for reproducibility
229-
set_all_random_seeds(args.seed, disable_torch_benchmarking=True, use_deterministic_torch_algos=True)
230-
228+
# NOTE: This implementation does not cover all sources of randomness in nnUNet, so complete
229+
# determinism cannot be achieved. The nnUNet maintainers have confirmed that full determinism
230+
# is not possible (see linked issue below). However, our current approach provides a reasonable
231+
# level of deterministic behavior for most practical purposes.
232+
# Reference: https://github.com/VectorInstitute/FL4Health/pull/411#:~:text=MIC%2DDKFZ/nnUNet%231906
233+
set_all_random_seeds(
234+
# NOTE: Setting seed comes at the cost of runtime performance. Benchmarking especially should be enabled
235+
# for long-running experiments.
236+
args.seed,
237+
disable_torch_benchmarking=True,
238+
use_deterministic_torch_algos=True,
239+
)
231240
# Set the log level
232241
update_console_handler(level=args.logLevel)
233242

0 commit comments

Comments
 (0)