codes.train package#
Submodules#
codes.train.progress module#
Progress messages from training workers and their parent-owned display.
- class codes.train.progress.EventProgress(iterable, desc='')#
Bases:
objectSmall tqdm-compatible iterable that reports completed epochs to the parent.
- close()#
- Return type:
None
- set_postfix(ordered_dict=None, refresh=True, **kwargs)#
- Return type:
None
- update(n=1)#
- Return type:
None
- class codes.train.progress.ProgressDisplay(tasks, slots, mode='auto', stream=None, log_dir=None)#
Bases:
objectRender worker events centrally, with stable bars or plain log lines.
- close()#
- Return type:
None
- property elapsed: float#
- event(slot, payload)#
- Return type:
None
- finish(slot, success, detail='')#
- Return type:
None
- log(slot, text)#
- Return type:
None
- start(slot, task, device)#
- Return type:
None
- codes.train.progress.current_reporter()#
Return the current worker’s message callback, if reporting is enabled.
- Return type:
Callable[[Any],None] |None
- codes.train.progress.worker_reporting(send)#
Route a worker’s progress and Python output to its parent process.
- Return type:
Generator[None,None,None]
codes.train.slurm module#
Prepare and execute fixed training assignments for scheduler arrays.
- codes.train.slurm.prepare_training(config_path, manifest_path)#
Freeze configuration and deterministic task assignments for one run.
- Return type:
None
- codes.train.slurm.run_worker(manifest_path, device='cpu', index=None)#
Run one array task and atomically record completion after checkpointing.
- Return type:
None
- codes.train.slurm.training_lock(training_id, *, shared=False)#
Coordinate local runs, preparation, and external workers for one run.
- Return type:
Iterator[None]
- codes.train.slurm.training_status(manifest_path)#
Report completed and retryable assignment indices.
- Return type:
None
- codes.train.slurm.unfinished_training_indices(manifest_path, *, manifest=None)#
Return assignments without both completion state and saved artifacts.
- Return type:
list[int]
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.
- Return type:
None
- 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|float|str) – 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 (
AbstractContextManager[Any] |None) – Legacy lock used around seeded initialisation.
- Return type:
None
- 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.
- Return type:
device
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[str,Any]) – 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[tuple[str,str,int|float|str,str,int|None,int|None] |list[str|int|float|None]]
- 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.
- Return type:
float
- 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.
- Return type:
float
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[str,Any]) – 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[tuple[str,str,int|float|str,str,int|None,int|None] |list[str|int|float|None]]
- 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.
- Return type:
None
- 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.
- Return type:
float
- 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.
- Return type:
float
- 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|float|str) – 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 (
AbstractContextManager[Any] |None) – Legacy lock used around seeded initialisation.
- Return type:
None