Trainer
pamiq_core.trainer.Trainer ¶
Trainer(
training_condition_data_user: str | None = None,
min_buffer_size: int = 0,
min_new_data_count: int = 0,
)
Bases: ABC
, PersistentStateMixin
, ThreadEventMixin
Abstract base trainer class.
The run
method is called repeatedly in the training thread.
Override the following methods
on_training_models_attached
: Callback method for when training models are attached to the trainer.on_data_users_attached
: Callback method when data_users are attached to the trainer.is_trainable
: Return whether the training can be executed.setup
: To setup before training starts.train
: The training process.teardown
: To teardown after training.
Models and data buffers become available after the thread has started.
Initialize a trainer.
PARAMETER | DESCRIPTION |
---|---|
training_condition_data_user
|
Name of the data user to check for trainability. If None, trainer is always trainable.
TYPE:
|
min_buffer_size
|
Minimum total data points required in the buffer.
TYPE:
|
min_new_data_count
|
Minimum number of new data points required since last training.
TYPE:
|
Source code in src/pamiq_core/trainer/base.py
attach_training_models ¶
Attaches TrainingModelsDict to this trainer.
on_training_models_attached ¶
Callback method for when training models are attached to the trainer.
Use :meth:get_training_model
to retrieve the model that will be trained.
attach_data_users ¶
on_data_users_attached ¶
Callback method when data users are attached to the trainer.
Use :meth:get_data_user
to obtain the data user class for dataset.
get_training_model ¶
Retrieves the training model.
If the specified model includes an inference model, it is automatically synchronized after training.
Source code in src/pamiq_core/trainer/base.py
get_data_user ¶
is_trainable ¶
Determines if the training can be executed.
Checks if training can proceed based on data availability when a training condition data user is specified.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if training can be executed, False otherwise. |
Source code in src/pamiq_core/trainer/base.py
setup ¶
train
abstractmethod
¶
Train models.
Please build the models, optimizers, dataset, and other components in this method. This method is called repeatedly.
After this method, :meth:sync_models
to be called.
Source code in src/pamiq_core/trainer/base.py
sync_models ¶
teardown ¶
run ¶
Runs the training process if the trainer is trainable.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if training was executed, False if skipped due to conditions not met.
TYPE:
|
Source code in src/pamiq_core/trainer/base.py
save_state ¶
Save the trainer state to the specified path.
PARAMETER | DESCRIPTION |
---|---|
path
|
Directory path where to save the trainer state.
TYPE:
|
Source code in src/pamiq_core/trainer/base.py
load_state ¶
Load the trainer state from the specified path.
PARAMETER | DESCRIPTION |
---|---|
path
|
Directory path from where to load the trainer state.
TYPE:
|