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

Optional import of tf or pt in tb receiver #2597

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion nvflare/app_opt/tracking/tb/tb_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
import os
from typing import List, Optional

from torch.utils.tensorboard import SummaryWriter
from nvflare.fuel.utils.import_utils import optional_import

torch, torch_ok = optional_import(module="torch")
if torch_ok:
from torch.utils.tensorboard import SummaryWriter

tf, tf_ok = optional_import(module="tensorflow")
if tf_ok and not torch_ok:
# flake8: noqa: F811
from tensorflow.summary import SummaryWriter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the TF SummaryWriter has the same functions such as add_scalar()


from nvflare.apis.analytix import AnalyticsData, AnalyticsDataType
from nvflare.apis.dxo import from_shareable
Expand Down
6 changes: 3 additions & 3 deletions nvflare/job_config/fed_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
from nvflare.app_opt.tf.model_persistor import TFModelPersistor

tb, tb_ok = optional_import(module="tensorboard")
if torch_ok and tb_ok:
from nvflare.app_opt.tracking.tb.tb_receiver import TBAnalyticsReceiver


class FilterType:
Expand Down Expand Up @@ -320,6 +318,8 @@ def _create_server_app(self):
self.app.add_component("model_selector", component)

# TODO: make different tracking receivers configurable
if torch_ok and tb_ok:
if (torch_ok or tf_ok) and tb_ok:
from nvflare.app_opt.tracking.tb.tb_receiver import TBAnalyticsReceiver

component = TBAnalyticsReceiver(events=["fed.analytix_log_stats"])
self.app.add_component("receiver", component)
Loading