codes.train package#
Submodules#
codes.train.tasks module#
Run individual training tasks independently of their scheduler.
- codes.train.tasks.execute_training_task(task, *, device='cpu', position=0, cpu_threads=1)#
Configure a worker process and train and save exactly one model.
taskcontains(surrogate, mode, metric, training_id, seed, epochs), as produced bycreate_task_list_for_surrogate. The saved configuration is read fromtrained/<training_id>/config.yaml.deviceis a logical device string within the worker’s allocation;cpu_threadssets PyTorch’s intra-operation thread count.Local spawned processes and future external workers can both call this function. It propagates errors and does not update pending-task files or completion markers; those belong to the scheduler invoking it.
- codes.train.tasks.train_and_save_model(surr_name, mode, metric, training_id, seed=None, epochs=None, device='cpu', position=1, threadlock=None)#
Train and save a model for a specific benchmark mode.
- Parameters:
surr_name (
str) – The name of the surrogate model.mode (
str) – The benchmark mode.metric (
int) – The metric for the benchmark mode.training_id (
str) – The training ID for the current training session.seed (
int|None) – Random seed for training.epochs (
int|None) – Number of training epochs.device (
str) – Device to run training on.position (
int) – Model position in the task list.threadlock (optional) – Legacy lock used around seeded initialisation.
- codes.train.tasks.validate_execution_settings(device, cpu_threads)#
Validate worker settings without selecting a CUDA context.
CUDA indices are logical indices within the process’s visible devices. CPU threads must fit within both its affinity mask and any Slurm allocation.
codes.train.train_fcts module#
- exception codes.train.train_fcts.TrainingRunError#
Bases:
RuntimeErrorOne or more local training tasks did not complete successfully.
- codes.train.train_fcts.create_task_list_for_surrogate(config, surr_name)#
Creates a list of training tasks for a specific surrogate model based on the configuration file.
- Parameters:
config (dict) – The configuration dictionary taken from the config file.
surr_name (
str) – The name of the surrogate model.
- Returns:
A list of training tasks for the surrogate model.
- Return type:
list
- codes.train.train_fcts.parallel_training(tasks, device_list, task_list_filepath, *, cpu_threads=1, progress='auto')#
Run each task in a fresh process, with one process per device slot.
- codes.train.train_fcts.sequential_training(tasks, device_list, task_list_filepath, *, cpu_threads=1, progress='auto')#
Run each task in a fresh process using the first device slot.
Module contents#
- exception codes.train.TrainingRunError#
Bases:
RuntimeErrorOne or more local training tasks did not complete successfully.
- codes.train.create_task_list_for_surrogate(config, surr_name)#
Creates a list of training tasks for a specific surrogate model based on the configuration file.
- Parameters:
config (dict) – The configuration dictionary taken from the config file.
surr_name (
str) – The name of the surrogate model.
- Returns:
A list of training tasks for the surrogate model.
- Return type:
list
- codes.train.execute_training_task(task, *, device='cpu', position=0, cpu_threads=1)#
Configure a worker process and train and save exactly one model.
taskcontains(surrogate, mode, metric, training_id, seed, epochs), as produced bycreate_task_list_for_surrogate. The saved configuration is read fromtrained/<training_id>/config.yaml.deviceis a logical device string within the worker’s allocation;cpu_threadssets PyTorch’s intra-operation thread count.Local spawned processes and future external workers can both call this function. It propagates errors and does not update pending-task files or completion markers; those belong to the scheduler invoking it.
- codes.train.parallel_training(tasks, device_list, task_list_filepath, *, cpu_threads=1, progress='auto')#
Run each task in a fresh process, with one process per device slot.
- codes.train.sequential_training(tasks, device_list, task_list_filepath, *, cpu_threads=1, progress='auto')#
Run each task in a fresh process using the first device slot.
- codes.train.train_and_save_model(surr_name, mode, metric, training_id, seed=None, epochs=None, device='cpu', position=1, threadlock=None)#
Train and save a model for a specific benchmark mode.
- Parameters:
surr_name (
str) – The name of the surrogate model.mode (
str) – The benchmark mode.metric (
int) – The metric for the benchmark mode.training_id (
str) – The training ID for the current training session.seed (
int|None) – Random seed for training.epochs (
int|None) – Number of training epochs.device (
str) – Device to run training on.position (
int) – Model position in the task list.threadlock (optional) – Legacy lock used around seeded initialisation.