kempnerforge.training.entry¶
Library entry point for a KempnerForge training job.
scripts/train.py is a thin CLI wrapper over run_training(): it
parses argv, loads the config, and calls in. Each phase below is a
separate function so an experiment can reuse the scaffold — or swap one
phase — without editing the shared script.
Functions
|
Create the checkpoint manager, scoping DCP to the PP stage when needed. |
|
Build the model with the full parallelism stack applied. |
|
Auto-resume from |
|
Run a full training job: build every phase, run the loop, tear down. |
- kempnerforge.training.entry.build_model(config, runtime, loss_fn)[source]¶
Build the model with the full parallelism stack applied.
With
distributed.pp > 1this builds this rank’s pipeline stage plus its schedule (which is whyloss_fnis needed here); otherwise it delegates tobuild_parallel_modeland returns no pipeline.- Parameters:
config (JobConfig)
runtime (RuntimeContext)
loss_fn (Callable[[torch.Tensor, torch.Tensor], torch.Tensor])
- Return type:
tuple[torch.nn.Module, PipelineBundle | None]
- kempnerforge.training.entry.build_checkpoint_manager(config, runtime, model, optimizer, pipeline)[source]¶
Create the checkpoint manager, scoping DCP to the PP stage when needed.
With PP, each stage has different parameters — DCP needs a group scoped to ranks within the same PP stage (all non-PP mesh dimensions), and each stage saves DCP shards to its own subdirectory to avoid file collisions.
- Parameters:
config (JobConfig)
runtime (RuntimeContext)
model (torch.nn.Module)
optimizer (torch.optim.Optimizer)
pipeline (PipelineBundle | None)
- Return type:
- kempnerforge.training.entry.restore_checkpoint(config, model, scheduler, ckpt_mgr)[source]¶
Auto-resume from
latest(orcheckpoint.load_path).Returns
(step, tokens_seen)—(0, 0)when there is nothing to resume from. Also restores the metrics run ids, runs the MoT warm-start hook, and re-applies the effective freeze at the resumed step.- Parameters:
config (JobConfig)
model (torch.nn.Module)
scheduler (object)
ckpt_mgr (CheckpointManager)
- Return type:
- kempnerforge.training.entry.run_training(config, *, step_fn=None, hooks=None)[source]¶
Run a full training job: build every phase, run the loop, tear down.
step_fnandhookslet an experiment own the step body or register hooks without copying the build phases. Both default to whatscripts/train.pyuses.- Parameters:
config (JobConfig)
step_fn (Callable[[TrainingSession, int], StepResult] | None)
hooks (HookRunner | None)
- Return type:
None