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 training contract 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 training contract
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 training contract 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
state_dict
¶
Return the mutable trainer state required for exact continuation.
Source code in geno_lewm/training/trainer.py
load_state_dict
¶
Restore a closed trainer-state payload after validating its horizon.
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 training contract 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 training contract 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 | |
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, source_tree: str | None = None, preflight_report: TrainingPreflightReport | None = None, resume_from: Path | None = None, stop_after_step: int | None = None) -> CarbonTrainingReport
Run a single-process Carbon-backed training job.
Source code in geno_lewm/training/real.py
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 training contract 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 training contract 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 training contract WSD learning-rate multiplier for a 1-indexed step.