Skip to content

Commit

Permalink
Fix global writer usage in utils.py
Browse files Browse the repository at this point in the history
Remove global variable `writer` and initialize `writer` directly in `write_metric` function across multiple files.

* **AggregatorBasedWorkflow/101_torch_cnn_mnist/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **AggregatorBasedWorkflow/102_aggregator_validation/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **AggregatorBasedWorkflow/104_keras_mnist/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **AggregatorBasedWorkflow/301_torch_cnn_mnist_watermarking/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **AggregatorBasedWorkflow/501_pytorch_tinyimagenet_transfer_learning/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **AggregatorBasedWorkflow/vertical_fl_two_party/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **torch_cnn_mnist/src/utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **torch_cnn_mnist_eden_compression/src/mnist_utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **torch_cnn_mnist_fed_eval/src/mnist_utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **torch_cnn_mnist_straggler_check/src/mnist_utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

* **torch_llm_horovod/src/emotion_utils.py**
  - Remove global variable `writer`
  - Remove `get_writer` function
  - Initialize `writer` directly in `write_metric` function

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/payalcha/openfl?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
payalcha committed Dec 10, 2024
1 parent 44614b3 commit a7e0c21
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
from torch.utils.tensorboard import SummaryWriter


writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
from torch.utils.tensorboard import SummaryWriter


writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
from tensorflow.summary import SummaryWriter


writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@
from torch.utils.tensorboard import SummaryWriter


writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
from torch.utils.tensorboard import SummaryWriter


writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
from torch.utils.tensorboard import SummaryWriter


writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
11 changes: 1 addition & 10 deletions openfl-workspace/torch_cnn_mnist/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@

from torch.utils.tensorboard import SummaryWriter

writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@

logger = getLogger(__name__)

writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)


Expand Down
11 changes: 1 addition & 10 deletions openfl-workspace/torch_cnn_mnist_fed_eval/src/mnist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@

logger = getLogger(__name__)

writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@

logger = getLogger(__name__)

writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter('./logs/cnn_mnist', flush_secs=5)
writer.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)


Expand Down
11 changes: 1 addition & 10 deletions openfl-workspace/torch_llm_horovod/src/emotion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@

logger = getLogger(__name__)

writer = None


def get_writer():
"""Create global writer object."""
global writer
if not writer:
writer = SummaryWriter("./logs/llm", flush_secs=5)


def write_metric(node_name, task_name, metric_name, metric, round_number):
"""Write metric callback."""
get_writer()
writer = SummaryWriter("./logs/llm", flush_secs=5)
writer.add_scalar(f"{node_name}/{task_name}/{metric_name}", metric, round_number)


Expand Down

0 comments on commit a7e0c21

Please sign in to comment.