Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stats_sender to MonaiAlgo for FL stats #6984

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion monai/fl/client/monai_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
import time
from collections.abc import Mapping, MutableMapping
from typing import Any, cast
from typing import Any, Callable, cast

import torch
import torch.distributed as dist
Expand Down Expand Up @@ -359,6 +359,7 @@
eval_workflow_name: str = "train",
train_workflow: BundleWorkflow | None = None,
eval_workflow: BundleWorkflow | None = None,
stats_sender: Callable | None = None,
wyli marked this conversation as resolved.
Show resolved Hide resolved
):
self.logger = logger
self.bundle_root = bundle_root
Expand Down Expand Up @@ -390,6 +391,7 @@
if not isinstance(eval_workflow, BundleWorkflow) or eval_workflow.get_workflow_type() is None:
raise ValueError("train workflow must be BundleWorkflow and set type.")
self.eval_workflow = eval_workflow
self.stats_sender = stats_sender

self.app_root = ""
self.filter_parser: ConfigParser | None = None
Expand Down Expand Up @@ -478,6 +480,12 @@
if len(config_filter_files) > 0:
self.filter_parser.read_config(config_filter_files)

# set stats sender for nvflare
self.stats_sender = extra.get(ExtraItems.STATS_SENDER, self.stats_sender)
if self.stats_sender is not None:
self.stats_sender.attach(self.trainer)
self.stats_sender.attach(self.evaluator)

Check warning on line 487 in monai/fl/client/monai_algo.py

View check run for this annotation

Codecov / codecov/patch

monai/fl/client/monai_algo.py#L486-L487

Added lines #L486 - L487 were not covered by tests

# Get filters
self.pre_filters = self.filter_parser.get_parsed_content(
FiltersType.PRE_FILTERS, default=ConfigItem(None, FiltersType.PRE_FILTERS)
Expand Down
1 change: 1 addition & 0 deletions monai/fl/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ExtraItems(StrEnum):
MODEL_TYPE = "fl_model_type"
CLIENT_NAME = "fl_client_name"
APP_ROOT = "fl_app_root"
STATS_SENDER = "fl_stats_sender"


class FlPhase(StrEnum):
Expand Down
Loading