fedbiomed.node.history_monitor

Module: fedbiomed.node.history_monitor

Send information from node to researcher during the training

Classes

HistoryMonitor

CLASS
HistoryMonitor(job_id, researcher_id, client)

Send information from node to researcher during the training

Parameters:

Name Type Description Default
job_id str

TODO

required
researcher_id str

TODO

required
client Messaging

TODO

required
Source code in fedbiomed/node/history_monitor.py
def __init__(self,
             job_id: str,
             researcher_id: str,
             client: Messaging):
    """Simple constructor for the class.

    Args:
        job_id: TODO
        researcher_id: TODO
        client: TODO
    """
    self.job_id = job_id
    self.researcher_id = researcher_id
    self.messaging = client

Attributes

job_id instance-attribute
job_id = job_id
messaging instance-attribute
messaging = client
researcher_id instance-attribute
researcher_id = researcher_id

Functions

add_scalar(metric, iteration, epoch, total_samples, batch_samples, num_batches, num_samples_trained=None, train=False, test=False, test_on_global_updates=False, test_on_local_updates=False)

Adds a scalar value to the monitor, and sends an 'AddScalarReply' response to researcher.

Parameters:

Name Type Description Default
metric Dict[str, Union[int, float]]

recorded value

required
iteration int

current epoch iteration.

required
epoch int

current epoch

required
total_samples int

TODO

required
batch_samples int

TODO

required
num_batches int

TODO

required
num_samples_trained int

TODO

None
train bool

TODO

False
test bool

TODO

False
test_on_global_updates bool

TODO

False
test_on_local_updates bool

TODO

False
Source code in fedbiomed/node/history_monitor.py
def add_scalar(
        self,
        metric: Dict[str, Union[int, float]],
        iteration: int,
        epoch: int,
        total_samples: int,
        batch_samples: int,
        num_batches: int,
        num_samples_trained: int = None,
        train: bool = False,
        test: bool = False,
        test_on_global_updates: bool = False,
        test_on_local_updates: bool = False
) -> None:
    """Adds a scalar value to the monitor, and sends an 'AddScalarReply'
        response to researcher.

    Args:
        metric:  recorded value
        iteration: current epoch iteration.
        epoch: current epoch
        total_samples: TODO
        batch_samples: TODO
        num_batches: TODO
        num_samples_trained: TODO
        train: TODO
        test: TODO
        test_on_global_updates: TODO
        test_on_local_updates: TODO

    """

    self.messaging.send_message(NodeMessages.reply_create({
        'node_id': environ['NODE_ID'],
        'job_id': self.job_id,
        'researcher_id': self.researcher_id,
        'train': train,
        'test': test,
        'test_on_global_updates': test_on_global_updates,
        'test_on_local_updates': test_on_local_updates,
        'metric': metric,
        'iteration': iteration,
        'epoch': epoch,
        'num_samples_trained': num_samples_trained,
        'total_samples': total_samples,
        'batch_samples': batch_samples,
        'num_batches': num_batches,
        'command': 'add_scalar'
    }).get_dict(), client='monitoring')