Skip to content

callback

zeus.callback

Infrastructure for calling callbacks.

Callback

Base class for callbacks.

Source code in zeus/callback.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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

1
on_train_begin()

Called at the beginning of training.

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

on_train_end

1
on_train_end()

Called at the end of training.

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

on_epoch_begin

1
on_epoch_begin()

Called at the beginning of each epoch.

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

on_epoch_end

1
on_epoch_end()

Called at the end of each epoch.

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

on_step_begin

1
on_step_begin()

Called at the beginning of each step.

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

on_step_end

1
on_step_end()

Called at the end of each step.

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

on_evaluate

1
on_evaluate(metric)

Called after evaluating the model.

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

on_instruction_begin

1
on_instruction_begin(name)

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

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

on_instruction_end

1
on_instruction_end(name)

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

Source code in zeus/callback.py
47
48
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
 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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
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__

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

on_train_begin

1
on_train_begin()

Called at the beginning of training.

Source code in zeus/callback.py
58
59
60
61
def on_train_begin(self) -> None:
    """Called at the beginning of training."""
    for callback in self.callbacks:
        callback.on_train_begin()

on_train_end

1
on_train_end()

Called at the end of training.

Source code in zeus/callback.py
63
64
65
66
def on_train_end(self) -> None:
    """Called at the end of training."""
    for callback in self.callbacks:
        callback.on_train_end()

on_epoch_begin

1
on_epoch_begin()

Called at the beginning of each epoch.

Source code in zeus/callback.py
68
69
70
71
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

1
on_epoch_end()

Called at the end of each epoch.

Source code in zeus/callback.py
73
74
75
76
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

1
on_step_begin()

Called at the beginning of each step.

Source code in zeus/callback.py
78
79
80
81
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

1
on_step_end()

Called at the end of each step.

Source code in zeus/callback.py
83
84
85
86
def on_step_end(self) -> None:
    """Called at the end of each step."""
    for callback in self.callbacks:
        callback.on_step_end()

on_evaluate

1
on_evaluate(metric)

Called after evaluating the model.

Source code in zeus/callback.py
88
89
90
91
def on_evaluate(self, metric: float) -> None:
    """Called after evaluating the model."""
    for callback in self.callbacks:
        callback.on_evaluate(metric)

on_instruction_begin

1
on_instruction_begin(name)

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

Source code in zeus/callback.py
93
94
95
96
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

1
on_instruction_end(name)

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

Source code in zeus/callback.py
 98
 99
100
101
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)