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

Introduce callbacks API #1195

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6fbbd77
Get rid of kwargs
MasterSkepticista Dec 5, 2024
fe5011a
Use module-level logger
MasterSkepticista Dec 5, 2024
edca03a
Reduce keras verbosity
MasterSkepticista Dec 5, 2024
31ad8ac
Remove all log_metric and log_memory_usage traces; add callback hooks
MasterSkepticista Dec 5, 2024
8857f03
Add `openfl.callbacks` module
MasterSkepticista Dec 5, 2024
49948cf
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 6, 2024
fc6b2cb
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 6, 2024
975e4ac
Include round_num for task callbacks
MasterSkepticista Dec 6, 2024
1267bf0
Add tensordb to callbacks
MasterSkepticista Dec 6, 2024
07e593d
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 9, 2024
2c84c88
No round_num on task callbacks
MasterSkepticista Dec 9, 2024
0a380c4
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 9, 2024
8d1aea3
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 10, 2024
e74b9bf
Remove task boundary callbacks
MasterSkepticista Dec 10, 2024
d63ced5
Remove tb/model_ckpt. Add memory_profiler
MasterSkepticista Dec 10, 2024
9ce8983
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 10, 2024
e103d63
Restore psutil and tbX
MasterSkepticista Dec 10, 2024
abb15da
Format code
MasterSkepticista Dec 10, 2024
5a2cd4b
Define default callbacks
MasterSkepticista Dec 10, 2024
23b8eb3
Add write_logs for bwd compat
MasterSkepticista Dec 10, 2024
4e32632
Add log_metric_callback for bwd compat
MasterSkepticista Dec 10, 2024
b501527
Migrate to module-level logger for collaborator
MasterSkepticista Dec 11, 2024
f5ebd1d
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 11, 2024
af0c40f
Review comments
MasterSkepticista Dec 11, 2024
2ed63ef
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 16, 2024
e8894d6
Merge branch 'develop' into karansh1/callbacks_api
MasterSkepticista Dec 21, 2024
aab8baf
Add metric_writer
MasterSkepticista Dec 21, 2024
3c5e525
Add collaborator side metric logging
MasterSkepticista Dec 21, 2024
fc76f18
Make log dirs on exp begin
MasterSkepticista Dec 21, 2024
c4eb30b
Do not print use_tls
MasterSkepticista Dec 21, 2024
9b3da0e
Assume reportable metric to be a scalar
MasterSkepticista Dec 21, 2024
1cffb9d
Add aggregator side callbacks
MasterSkepticista Dec 21, 2024
afd1bee
do_task test returns mock dict
MasterSkepticista Dec 21, 2024
25c00f1
Consistency changes
MasterSkepticista Dec 21, 2024
efbfdc7
Add documentation hooks
MasterSkepticista Dec 21, 2024
e7068e1
Update docstring
MasterSkepticista Dec 21, 2024
be06eda
Update docs hook
MasterSkepticista Dec 21, 2024
38f7c30
Remove all traces of log_metric_callback and write_metric
MasterSkepticista Dec 21, 2024
d01ec5e
Do on_round_begin if not time_to_quit
MasterSkepticista Dec 23, 2024
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
16 changes: 16 additions & 0 deletions docs/openfl.callbacks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
``openfl.callbacks`` module
===========================

.. currentmodule:: openfl.callbacks

.. automodule:: openfl.callbacks

.. autosummary::
:toctree: _autosummary
:recursive:

Callback
CallbackList
LambdaCallback
MetricWriter
MemoryProfiler
3 changes: 2 additions & 1 deletion docs/openfl.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. currentmodule:: openfl

Public API: ``openfl`` package
API Reference: ``openfl``
===========================

Subpackages
Expand All @@ -10,6 +10,7 @@ Subpackages
:maxdepth: 1

openfl.component
openfl.callbacks
openfl.cryptography
openfl.experimental
openfl.databases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.Aggregator
settings :
rounds_to_train : 1
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.Aggregator
settings :
rounds_to_train : 1
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.Aggregator
settings :
rounds_to_train : 1
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.Aggregator
settings :
rounds_to_train : 1
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.Aggregator
settings :
rounds_to_train : 1
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.aggregator.Aggregator
settings :
rounds_to_train : 1
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ aggregator :
template : openfl.experimental.workflow.component.aggregator.Aggregator
settings :
rounds_to_train : 10
log_metric_callback :
template : src.utils.write_metric


collaborator :
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ aggregator :
best_state_path : save/torch_cnn_mnist_best.pbuf
last_state_path : save/torch_cnn_mnist_last.pbuf
rounds_to_train : 10
log_metric_callback :
template : src.mnist_utils.write_metric


collaborator :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,11 @@
from logging import getLogger

import numpy as np
from torch.utils.tensorboard import SummaryWriter
from torchvision import datasets
from torchvision import transforms

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.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)


def one_hot(labels, classes):
"""
Expand Down
2 changes: 0 additions & 2 deletions openfl-workspace/torch_cnn_mnist_fed_eval/plan/plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ aggregator :
init_state_path : save/torch_cnn_mnist_init.pbuf
best_state_path : save/torch_cnn_mnist_best.pbuf
last_state_path : save/torch_cnn_mnist_last.pbuf
log_metric_callback :
template : src.mnist_utils.write_metric

collaborator :
defaults : plan/defaults/collaborator.yaml
Expand Down
16 changes: 0 additions & 16 deletions openfl-workspace/torch_cnn_mnist_fed_eval/src/mnist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,11 @@
from logging import getLogger

import numpy as np
from torch.utils.tensorboard import SummaryWriter
from torchvision import datasets
from torchvision import transforms

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.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)


def one_hot(labels, classes):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ aggregator :
best_state_path : save/torch_cnn_mnist_best.pbuf
last_state_path : save/torch_cnn_mnist_last.pbuf
rounds_to_train : 6
log_metric_callback :
template : src.mnist_utils.write_metric


collaborator :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,11 @@
from logging import getLogger

import numpy as np
from torch.utils.tensorboard import SummaryWriter
from torchvision import datasets
from torchvision import transforms

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.add_scalar(f'{node_name}/{task_name}/{metric_name}', metric, round_number)


def one_hot(labels, classes):
"""
Expand Down
2 changes: 0 additions & 2 deletions openfl-workspace/torch_llm_horovod/plan/plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ aggregator :
best_state_path : save/torch_llm_best.pbuf
last_state_path : save/torch_llm_last.pbuf
rounds_to_train : 5
log_metric_callback :
template : src.emotion_utils.write_metric


collaborator :
Expand Down
16 changes: 0 additions & 16 deletions openfl-workspace/torch_llm_horovod/src/emotion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,10 @@
from logging import getLogger

from datasets import Dataset, load_dataset
from torch.utils.tensorboard import SummaryWriter
from transformers import AutoTokenizer, DataCollatorWithPadding

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.add_scalar(f"{node_name}/{task_name}/{metric_name}", metric, round_number)


def get_emotion_dataset(tokenizer):
dataset = load_dataset("dair-ai/emotion", cache_dir="dataset", revision="9ce6303")
Expand Down
1 change: 0 additions & 1 deletion openfl-workspace/workspace/plan/defaults/aggregator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
template : openfl.component.Aggregator
settings :
db_store_rounds : 2
write_logs : true
Loading
Loading