Observers

Olympus use a set of Observer objects to monitor a training in progress. This allow Olympus to keep the training code short and focused on its purpose.

For example, all metrics, validation, online accuracy, speed are computed through observer, making that logic easily reusable for different tasks.

Observer Pattern

Available Observers

More Observers are defined as metrics.

Observer Interface

olympus.observers.observer.Metric

alias of olympus.observers.observer.Observer

class olympus.observers.observer.Observer(frequency_new_epoch: int = 0, frequency_new_batch: int = 0, frequency_new_trial: int = 0, priority: int = 0) → None[source]

Bases: object

Metrics are observers that receives events periodically

Attributes:
frequency_epoch: int

Controls how often on_new_epoch is called, 0 disables it

frequency_batch: int

Controls how often on_new_batch is called, 0 disables it

frequency_trial: int

Controls how often on_new_trial is called, 0 disables it

priority: int

Controls which metric is called first

Methods

every(*args[, epoch, batch]) Define how often this metric should be called
load_state_dict(state_dict) Load a state dictionary to resume a previous training
on_end_train(task[, step]) Called at the end of training after the last epoch
on_new_batch(task, step[, input, context]) Called after a batch has been processed
on_new_epoch(task, epoch, context) Called at the end of an epoch, before a new epoch starts
on_new_trial(task, step, parameters, uid) Called after a trial has been processed
on_start_train(task[, step]) Called on ce the training starts
state_dict() Return a state dictionary used to checkpointing and resuming
value() Return the key values that metrics computes
every(*args, epoch=None, batch=None)[source]

Define how often this metric should be called

frequency_new_batch = 0
frequency_new_epoch = 0
frequency_new_trial = 0
load_state_dict(state_dict)[source]

Load a state dictionary to resume a previous training

on_end_train(task, step=None)[source]

Called at the end of training after the last epoch

on_new_batch(task, step, input=None, context=None)[source]

Called after a batch has been processed

on_new_epoch(task, epoch, context)[source]

Called at the end of an epoch, before a new epoch starts

on_new_trial(task, step, parameters, uid)[source]

Called after a trial has been processed

on_start_train(task, step=None)[source]

Called on ce the training starts

Notes

You should not rely on this function to initialize your metric as it will not be called if the training is resumed from a previous state

priority = 0
state_dict()[source]

Return a state dictionary used to checkpointing and resuming

value()[source]

Return the key values that metrics computes

Observer List

olympus.observers.MetricList

alias of olympus.observers.ObserverList

class olympus.observers.ObserverList(*args, task=None, name=None)[source]

Bases: object

MetricList relays the Event to the Metrics/Observers

Methods

append(m[, key]) Insert a new metric to compute
end_batch(step[, input, context]) Broadcast a new_batch event to all metrics
end_epoch(epoch[, context]) Broadcast a new_epoch event to all metrics
end_train() Broadcast a finish event to all metrics
get(key[, default]) Retrieve a metric from its key
load_state_dict(state_dict[, strict]) Resume all children metrics using a state_dict
new_batch(step[, input, context]) Broadcast a new_batch event to all metrics
new_epoch(epoch[, context]) Broadcast a new_epoch event to all metrics
new_trial(parameters, uid) Broadcast a new_trial event
report([pprint, print_fun]) Pretty prints all the metrics
resume_train(start_epoch) Broadcast a resume event to all metrics
start_train() Broadcast a start event to all metrics
state_dict([destination, prefix, keep_vars]) Save all the children states
value() Returns a dictionary of all computed metrics
broadcast_event  
should_run  
append(m: olympus.observers.observer.Observer, key=None)[source]

Insert a new metric to compute

Parameters:
m: Metric

new metric to insert

key: Optional[str]

optional key used to retrieve the metric by default the type name will be used as key

broadcast_event(event_name, task, step, *args, **kwargs)[source]
end_batch(step, input=None, context=None)[source]

Broadcast a new_batch event to all metrics

end_epoch(epoch, context=None)[source]

Broadcast a new_epoch event to all metrics

end_train()[source]

Broadcast a finish event to all metrics

get(key, default=None)[source]

Retrieve a metric from its key

Parameters:
key: Union[str, int]
default: any

default object returned if not found

load_state_dict(state_dict, strict=True)[source]

Resume all children metrics using a state_dict

new_batch(step, input=None, context=None)[source]

Broadcast a new_batch event to all metrics

new_epoch(epoch, context=None)[source]

Broadcast a new_epoch event to all metrics

new_trial(parameters, uid)[source]

Broadcast a new_trial event

report(pprint=True, print_fun=<built-in function print>)[source]

Pretty prints all the metrics

resume_train(start_epoch)[source]

Broadcast a resume event to all metrics

static should_run(name, step)[source]
start_train()[source]

Broadcast a start event to all metrics

state_dict(destination=None, prefix='', keep_vars=False)[source]

Save all the children states

value()[source]

Returns a dictionary of all computed metrics