Skip to content

callback

zeus.callback

Infrastructure for calling callbacks.

Callback

Base class for callbacks.

Source code in zeus/callback.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Callback:
    """Base class for callbacks."""

    def on_train_begin(self) -> None:
        """Called at the beginning of training."""

    def on_train_end(self) -> None:
        """Called at the end of training."""

    def on_epoch_begin(self) -> None:
        """Called at the beginning of each epoch."""

    def on_epoch_end(self) -> None:
        """Called at the end of each epoch."""

    def on_step_begin(self) -> None:
        """Called at the beginning of each step."""

    def on_step_end(self) -> None:
        """Called at the end of each step."""

    def on_evaluate(self, metric: float) -> None:
        """Called after evaluating the model."""

    def on_instruction_begin(self, name: str) -> None:
        """Called at the beginning of pipeline instructions like forward or backward."""

    def on_instruction_end(self, name: str) -> None:
        """Called at the end of pipeline instructions like forward or backward."""

on_train_begin

on_train_begin()

Called at the beginning of training.

Source code in zeus/callback.py
 9
10
def on_train_begin(self) -> None:
    """Called at the beginning of training."""

on_train_end

on_train_end()

Called at the end of training.

Source code in zeus/callback.py
12
13
def on_train_end(self) -> None:
    """Called at the end of training."""

on_epoch_begin

on_epoch_begin()

Called at the beginning of each epoch.

Source code in zeus/callback.py
15
16
def on_epoch_begin(self) -> None:
    """Called at the beginning of each epoch."""

on_epoch_end

on_epoch_end()

Called at the end of each epoch.

Source code in zeus/callback.py
18
19
def on_epoch_end(self) -> None:
    """Called at the end of each epoch."""

on_step_begin

on_step_begin()

Called at the beginning of each step.

Source code in zeus/callback.py
21
22
def on_step_begin(self) -> None:
    """Called at the beginning of each step."""

on_step_end

on_step_end()

Called at the end of each step.

Source code in zeus/callback.py
24
25
def on_step_end(self) -> None:
    """Called at the end of each step."""

on_evaluate

on_evaluate(metric)

Called after evaluating the model.

Source code in zeus/callback.py
27
28
def on_evaluate(self, metric: float) -> None:
    """Called after evaluating the model."""

on_instruction_begin

on_instruction_begin(name)

Called at the beginning of pipeline instructions like forward or backward.

Source code in zeus/callback.py
30
31
def on_instruction_begin(self, name: str) -> None:
    """Called at the beginning of pipeline instructions like forward or backward."""

on_instruction_end

on_instruction_end(name)

Called at the end of pipeline instructions like forward or backward.

Source code in zeus/callback.py
33
34
def on_instruction_end(self, name: str) -> None:
    """Called at the end of pipeline instructions like forward or backward."""

CallbackSet

Bases: Callback

A set of callbacks.

Source code in zeus/callback.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class CallbackSet(Callback):
    """A set of callbacks."""

    def __init__(self, callbacks: list[Callback]) -> None:
        """Initialize the callback set."""
        self.callbacks = callbacks

    def on_train_begin(self) -> None:
        """Called at the beginning of training."""
        for callback in self.callbacks:
            callback.on_train_begin()

    def on_train_end(self) -> None:
        """Called at the end of training."""
        for callback in self.callbacks:
            callback.on_train_end()

    def on_epoch_begin(self) -> None:
        """Called at the beginning of each epoch."""
        for callback in self.callbacks:
            callback.on_epoch_begin()

    def on_epoch_end(self) -> None:
        """Called at the end of each epoch."""
        for callback in self.callbacks:
            callback.on_epoch_end()

    def on_step_begin(self) -> None:
        """Called at the beginning of each step."""
        for callback in self.callbacks:
            callback.on_step_begin()

    def on_step_end(self) -> None:
        """Called at the end of each step."""
        for callback in self.callbacks:
            callback.on_step_end()

    def on_evaluate(self, metric: float) -> None:
        """Called after evaluating the model."""
        for callback in self.callbacks:
            callback.on_evaluate(metric)

    def on_instruction_begin(self, name: str) -> None:
        """Called at the beginning of pipeline instructions like forward or backward."""
        for callback in self.callbacks:
            callback.on_instruction_begin(name)

    def on_instruction_end(self, name: str) -> None:
        """Called at the end of pipeline instructions like forward or backward."""
        for callback in self.callbacks:
            callback.on_instruction_end(name)

__init__

__init__(callbacks)
Source code in zeus/callback.py
40
41
42
def __init__(self, callbacks: list[Callback]) -> None:
    """Initialize the callback set."""
    self.callbacks = callbacks

on_train_begin

on_train_begin()

Called at the beginning of training.

Source code in zeus/callback.py
44
45
46
47
def on_train_begin(self) -> None:
    """Called at the beginning of training."""
    for callback in self.callbacks:
        callback.on_train_begin()

on_train_end

on_train_end()

Called at the end of training.

Source code in zeus/callback.py
49
50
51
52
def on_train_end(self) -> None:
    """Called at the end of training."""
    for callback in self.callbacks:
        callback.on_train_end()

on_epoch_begin

on_epoch_begin()

Called at the beginning of each epoch.

Source code in zeus/callback.py
54
55
56
57
def on_epoch_begin(self) -> None:
    """Called at the beginning of each epoch."""
    for callback in self.callbacks:
        callback.on_epoch_begin()

on_epoch_end

on_epoch_end()

Called at the end of each epoch.

Source code in zeus/callback.py
59
60
61
62
def on_epoch_end(self) -> None:
    """Called at the end of each epoch."""
    for callback in self.callbacks:
        callback.on_epoch_end()

on_step_begin

on_step_begin()

Called at the beginning of each step.

Source code in zeus/callback.py
64
65
66
67
def on_step_begin(self) -> None:
    """Called at the beginning of each step."""
    for callback in self.callbacks:
        callback.on_step_begin()

on_step_end

on_step_end()

Called at the end of each step.

Source code in zeus/callback.py
69
70
71
72
def on_step_end(self) -> None:
    """Called at the end of each step."""
    for callback in self.callbacks:
        callback.on_step_end()

on_evaluate

on_evaluate(metric)

Called after evaluating the model.

Source code in zeus/callback.py
74
75
76
77
def on_evaluate(self, metric: float) -> None:
    """Called after evaluating the model."""
    for callback in self.callbacks:
        callback.on_evaluate(metric)

on_instruction_begin

on_instruction_begin(name)

Called at the beginning of pipeline instructions like forward or backward.

Source code in zeus/callback.py
79
80
81
82
def on_instruction_begin(self, name: str) -> None:
    """Called at the beginning of pipeline instructions like forward or backward."""
    for callback in self.callbacks:
        callback.on_instruction_begin(name)

on_instruction_end

on_instruction_end(name)

Called at the end of pipeline instructions like forward or backward.

Source code in zeus/callback.py
84
85
86
87
def on_instruction_end(self, name: str) -> None:
    """Called at the end of pipeline instructions like forward or backward."""
    for callback in self.callbacks:
        callback.on_instruction_end(name)