"""Diagnostics parsed from what the trainer actually wrote. The log is the source of truth. Nothing in this module estimates a step that did not happen, and every number carries its **unit** and **where it came from**, because a metric without provenance is a rumour. It reads three things TRL/transformers emit and one thing mindXtrain does: 1. step dicts — ``{'loss': .., 'grad_norm': .., 'learning_rate': .., 'entropy': .., 'num_tokens': .., 'mean_token_accuracy': .., 'epoch': ..}`` 2. eval dicts — ``{'eval_loss': .., 'eval_runtime': .., 'eval_entropy': .., 'eval_num_tokens': .., 'eval_mean_token_accuracy': ..}`` 3. the closing dict — ``{'train_runtime': .., 'train_loss': .., 'train_samples_per_second': ..}`` 4. tqdm — ``24%|███ | 28/116 [14:55<46:01, 31.38s/it]`` (progress, ETA, seconds per step) and it raises the warnings that actually cost runs: packing without a flash-attention backend, a throttle that is not being honoured, a loss that stopped moving, an eval that has drifted above train (memorising), and gradient norms that are collapsing or exploding. """ from __future__ import annotations import ast import math import re import time from dataclasses import dataclass, field from pathlib import Path from typing import Any _DICT = re.compile(r"\{'(?:loss|eval_loss|train_runtime)'.*?\}") _TQDM = re.compile(r"(?:(?P