kempnerforge.metrics.tracker¶
Metrics collection, accumulation, and reporting.
MetricsTracker aggregates per-step metrics (loss, grad norm, throughput, MFU, memory) and dispatches them to configured logging backends (stdout, WandB, TensorBoard, MLflow) at a configurable interval.
Classes
Collects, smooths, and reports training metrics. |
|
Metrics for a single training step. |
|
TensorBoard logging backend. |
|
Weights & Biases logging backend. |
- class kempnerforge.metrics.tracker.StepMetrics[source]¶
Bases:
objectMetrics for a single training step.
- __init__(loss=0.0, grad_norm=0.0, lr=0.0, tokens_per_sec=0.0, mfu=0.0, step_time_sec=0.0, allocated_gb=0.0, peak_gb=0.0, reserved_gb=0.0, total_gb=0.0, mem_utilization=0.0)¶
- class kempnerforge.metrics.tracker.MetricsTracker[source]¶
Bases:
objectCollects, smooths, and reports training metrics.
Timing is handled internally — call
start_step()before andend_step()after each training step. Metrics are logged to all configured backends at the configured interval.- Parameters:
config – Full job config (used for MFU calculation and backend selection).
num_gpus – Number of GPUs for MFU denominator.
gpu_peak_tflops – Per-GPU peak TFLOPS. If None, auto-detected.
- end_step(step, loss, grad_norm, lr, tokens_in_step)[source]¶
Mark the end of a training step and optionally log metrics.
A logging step reads GPU memory once, from the current device. The tracker never resets the peak, so
peak_gbis the most allocated since the process started, or since areset_peak_memoryelsewhere (DeviceMemoryMonitor.reportmakes one).- Parameters:
step (int) – Current training step number.
loss (float) – Loss value for this step.
grad_norm (float) – Total gradient norm before clipping (what
clip_grad_norm_returns); under pipeline parallelism, the whole model’s norm.lr (float) – Current learning rate.
tokens_in_step (int) – Total tokens processed in this step (across all GPUs).
- Returns:
StepMetrics if this step was a logging step, None otherwise.
- Return type:
StepMetrics | None
- init_backends(config)[source]¶
Initialize logging backends (call after distributed setup).
- Parameters:
config (JobConfig)
- Return type:
None
- tracking_entries()[source]¶
One record per backend with a live run, for a checkpoint’s
metadata.json.Empty once
close()has begun. Reads only what the backends already hold, so it never waits on a server. Each entry is copied once into a plain dict; a backend that cannot describe itself, or whose entry is not strings under a namedbackend, is skipped with a warning and costs no other backend its entry.
- checkpoint_fields(step)[source]¶
What each backend with a live run adds to its tracking entry of the save at
step.Keyed by backend name; this tracker is what
run_traininghands toCheckpointManager.set_checkpoint_registrar. Reads only what the backends hold, so it never waits on a server; a backend that fails costs only its own fields. Empty onceclose()has begun.
- register_checkpoint(step, directory, record)[source]¶
Hand a committed checkpoint to each backend with a live run; never blocks.
Each backend gets
recordbound to its own name, so it can amend only its own tracking entry, then or later from another thread. A backend that fails costs only its own registration. Nothing is registered onceclose()has begun.
- class kempnerforge.metrics.tracker.WandBBackend[source]¶
Bases:
_LoggingBackendWeights & Biases logging backend.
Initializes a WandB run on first log call.
- __init__(config)[source]¶
- Parameters:
config (MetricsConfig)
- Return type:
None
- class kempnerforge.metrics.tracker.TensorBoardBackend[source]¶
Bases:
_LoggingBackendTensorBoard logging backend.
- __init__(config)[source]¶
- Parameters:
config (MetricsConfig)
- Return type:
None