geno_lewm.training¶
training
¶
Training helpers for GenoLeWM.
CollapseAlert
dataclass
¶
One tripped collapse criterion.
CollapseCheck
dataclass
¶
Metrics and alerts produced by one collapse-monitor observation.
CollapseMetrics
dataclass
¶
CollapseMetrics(pred_cos_mean: float, pred_l2_mean: float, target_var_per_dim: float, pred_var_per_dim: float, pred_target_corr: float, pairwise_pred_dist_mean: float, kl_reg: float)
Scalar RFC-0005 §3.6 collapse diagnostics for one batch.
CollapseMonitor
dataclass
¶
CollapseMonitor(log_every_steps: int = 500, thresholds: CollapseThresholds = CollapseThresholds(), initial_pairwise_pred_dist_mean: float | None = None)
Compute, register, and optionally log collapse diagnostics.
observe returns None on non-logging steps, otherwise a
:class:CollapseCheck. The first logged batch establishes the
pairwise-distance baseline unless the caller supplies one.
should_log
¶
Return whether step is a scheduled collapse-monitor step.
observe
¶
observe(prediction: object, target: object, *, kl_reg: float, step: int, logger: GenoLeWMLogger | None = None, force: bool = False) -> CollapseCheck | None
Observe a validation batch at step.
Metrics are computed, written to the registry, and logged only
when step is a scheduled monitoring step unless force is
true.
Source code in geno_lewm/training/collapse.py
CollapseThresholds
dataclass
¶
CollapseThresholds(pred_var_to_target_var: float = 0.5, pairwise_to_initial: float = 0.5, kl_reg_max: float = 10.0)
Alert thresholds from RFC-0005 §3.6.
FixtureTrainingReport
dataclass
¶
FixtureTrainingReport(run_id: str, run_dir: Path, steps_requested: int, steps_completed: int, resumed_from_step: int, final_loss: float, checkpoint_path: Path, metrics_path: Path, log_path: Path, config_path: Path, dataset_manifest_path: Path, training_metadata_path: Path)
Summary returned by the deterministic fixture trainer.
AcceleratorProbe
dataclass
¶
AcceleratorProbe(requested_device: str | None, required: bool, available: bool, device_count: int, device_name: str | None, total_memory_bytes: int | None, min_memory_bytes: int, reason: str, issue_code: str | None = None)
CUDA accelerator readiness probe for Carbon-backed training.
DependencyProbe
dataclass
¶
DependencyProbe(import_name: str, package: str, required: bool, available: bool, version: str | None, reason: str)
Importability probe for one training dependency.
TrainingPreflightIssue
dataclass
¶
One preflight issue.
TrainingPreflightReport
dataclass
¶
TrainingPreflightReport(schema_version: str, generated_by: str, generated_at: str, ok: bool, dataset_snapshot_id: str | None, training_config: dict[str, object], run_dir: dict[str, object], dataset: dict[str, object], carbon: dict[str, object], accelerator: AcceleratorProbe, dependencies: tuple[DependencyProbe, ...], issues: tuple[TrainingPreflightIssue, ...])
Machine-readable readiness evidence for the real training path.
TrainingPreflightRequest
dataclass
¶
TrainingPreflightRequest(dataset_dir: Path, carbon_model_dir: Path, training_config: Path, run_dir: Path, allow_fixture_dataset: bool = False, require_native_runtime: bool = True, require_accelerator: bool = True, min_cuda_vram_gb: float = MIN_CUDA_VRAM_GB)
Inputs needed before launching a Carbon-backed training run.
CarbonTrainingReport
dataclass
¶
CarbonTrainingReport(run_id: str, run_dir: Path, dataset_snapshot_id: str, steps_requested: int, steps_completed: int, resumed_from_step: int, sample_count: int, final_loss: float, checkpoint_path: Path, resume_checkpoint_path: Path | None, metrics_path: Path, log_path: Path, config_path: Path, preflight_path: Path | None, training_metadata_path: Path)
Summary emitted by the real Carbon-backed trainer.
EditTypeWeight
dataclass
¶
One RFC-0005 edit-type sampling weight.
RolloutStepWeight
dataclass
¶
One rollout-step-count sampling weight.
TorchDeterminismReport
dataclass
¶
TorchDeterminismReport(seed: int, deterministic: bool, cublas_workspace_config: str | None, torch_deterministic_algorithms: bool)
Runtime settings applied before a torch training run.
TorchTrainer
¶
TorchTrainer(*, predictor: object, action_encoder: object, optimizer: object, config: GenoLeWMConfig, total_steps: int)
Minimal optimizer loop for Carbon-state predictor training.
Source code in geno_lewm/training/trainer.py
train_step
¶
Run one optimizer step over an encoded Carbon-state batch.
Source code in geno_lewm/training/trainer.py
TorchTrainerBatch
dataclass
¶
TorchTrainerBatch(state: Tensor, target: Tensor, rel_edits: tuple[tuple[RelEdit, ...], ...], action_mask: Tensor, window_ids: tuple[str, ...])
One encoded minibatch consumed by :class:TorchTrainer.
TorchTrainerStepResult
dataclass
¶
TorchTrainerStepResult(step: int, lr_multiplier: float, loss: float, pred_loss: float, kl_reg: float, action_count: int, pred_var_per_dim: float)
Scalar outputs from one optimizer step.
TrainerSeeds
dataclass
¶
Distinct RNG seeds consumed by the real training stack.
compute_collapse_metrics
¶
Compute RFC-0005 §3.6 collapse metrics for one [N, D] batch.
Source code in geno_lewm/training/collapse.py
detect_collapse
¶
detect_collapse(metrics: CollapseMetrics, *, thresholds: CollapseThresholds | None = None, initial_pairwise_pred_dist_mean: float | None = None) -> tuple[CollapseAlert, ...]
Return the RFC-0005 §3.6 alert criteria tripped by metrics.
Source code in geno_lewm/training/collapse.py
record_collapse_metrics
¶
record_collapse_metrics(metrics: CollapseMetrics, *, alerts: Iterable[CollapseAlert] = (), logger: GenoLeWMLogger | None = None, step: int | None = None) -> None
Write collapse metrics to the registry and optional structured logs.
Source code in geno_lewm/training/collapse.py
run_fixture_training
¶
run_fixture_training(*, config: GenoLeWMConfig, run_dir: Path, steps: int = 50, resume_from: Path | None = None, command: str, commit_sha: str, package_version: str) -> FixtureTrainingReport
Run a deterministic scalar smoke trainer and write release artifacts.
steps is the target total step count. When resume_from is
supplied, the checkpoint's current step must be lower than steps;
the resumed run continues with the same deterministic sample stream.
Source code in geno_lewm/training/fixture.py
build_training_preflight_report
¶
build_training_preflight_report(request: TrainingPreflightRequest, *, generated_at: str | None = None, dependency_probe: DependencyProbeFn | None = None, accelerator_probe: AcceleratorProbeFn | None = None) -> TrainingPreflightReport
Build clean-machine readiness evidence for Carbon-backed training.
Source code in geno_lewm/training/preflight.py
write_training_preflight_report
¶
write_training_preflight_report(request: TrainingPreflightRequest, output: Path | None = None, *, generated_at: str | None = None, dependency_probe: DependencyProbeFn | None = None, accelerator_probe: AcceleratorProbeFn | None = None) -> TrainingPreflightReport
Write training_preflight_report.json and return the report.
Source code in geno_lewm/training/preflight.py
run_carbon_training
¶
run_carbon_training(*, config: GenoLeWMConfig, dataset_dir: Path, carbon_model_dir: Path, run_dir: Path, steps: int, command: str, commit_sha: str, package_version: str, preflight_report: TrainingPreflightReport | None = None, resume_from: Path | None = None) -> CarbonTrainingReport
Run a single-process Carbon-backed training job.
Source code in geno_lewm/training/real.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
draw_edit_type_counts
¶
draw_edit_type_counts(n: int, *, rng: Random, weights: Sequence[EditTypeWeight] = DEFAULT_EDIT_TYPE_WEIGHTS) -> dict[EditType, int]
Draw n edit types and return counts by :class:EditType.
Source code in geno_lewm/training/sampling.py
draw_rollout_step_counts
¶
draw_rollout_step_counts(n: int, *, rng: Random, mix: Sequence[RolloutStepWeight] = DEFAULT_ROLLOUT_STEP_MIX) -> dict[int, int]
Draw n rollout lengths and return counts by step count.
Source code in geno_lewm/training/sampling.py
sample_edit_type
¶
sample_edit_type(rng: Random, *, weights: Sequence[EditTypeWeight] = DEFAULT_EDIT_TYPE_WEIGHTS) -> EditType
Sample one edit type from the RFC-0005 edit-balanced distribution.
Source code in geno_lewm/training/sampling.py
sample_rollout_steps
¶
sample_rollout_steps(rng: Random, *, mix: Sequence[RolloutStepWeight] = DEFAULT_ROLLOUT_STEP_MIX) -> int
Sample a rollout length K from the Phase-1 RFC-0005 mix.
Source code in geno_lewm/training/sampling.py
build_adamw_optimizer
¶
build_adamw_optimizer(*, predictor: object, action_encoder: object, config: GenoLeWMConfig) -> object
Build AdamW groups for predictor/action-encoder trainable parameters.
Source code in geno_lewm/training/trainer.py
configure_torch_reproducibility
¶
Seed Python/NumPy/PyTorch and optionally enable deterministic torch kernels.
Source code in geno_lewm/training/trainer.py
encode_training_batch
¶
encode_training_batch(*, encoder: object, tuples: Sequence[TrainingTuple], source_windows: Mapping[str, str], device: str | object | None = None, dtype: object | None = None) -> TorchTrainerBatch
Encode source/target windows for a real predictor-training minibatch.
Source code in geno_lewm/training/trainer.py
make_action_mask
¶
Return a boolean action mask for a ragged batch of relative edits.
Source code in geno_lewm/training/trainer.py
set_optimizer_lr
¶
set_optimizer_lr(optimizer: object, *, step: int, total_steps: int, warmup_steps: int, schedule: ScheduleName = 'wsd') -> float
Set optimizer group LRs from each group's initial_lr and return multiplier.
Source code in geno_lewm/training/trainer.py
wsd_lr_multiplier
¶
wsd_lr_multiplier(step: int, *, total_steps: int, warmup_steps: int, schedule: ScheduleName = 'wsd') -> float
Return the RFC-0005 WSD learning-rate multiplier for a 1-indexed step.