#!/usr/bin/env python3 """TensorBoard scalars for both trainers, without patching either one. # attach to a run that is already going (no restart, no lost progress) ./scripts/tb_logger.py --policy act --log ~/caring/logs/act.log --out ~/caring/tb/act tensorboard --logdir ~/caring/tb WHY NOT PATCH THE TRAINER ------------------------- lerobot ships only a wandb logger, and Isaac hardcodes ``report_to="wandb" if use_wandb else "none"``. The previous answer to that was ``tb_patch.py``: a script that rewrote five anchors inside ``lerobot_train.py`` in the installed checkout. It worked, and it was one more piece of configuration living outside version control that a container rebuild would silently take with it. It is also unnecessary. Both trainers already print every scalar worth plotting, and ``train.py`` already reads that stream line by line for early stopping. So the numbers are parsed out of the log instead — no source edits, one code path for both families, and it works equally well tailing the log of a run that is already in flight. STEP AXIS --------- Neither log line carries an unambiguous global step: ACT prints ``step:54K`` (rounded) and GR00T prints no step at all. Both, however, log at a FIXED interval — lerobot ``log_freq`` (200) and Isaac ``logging_steps`` (10) — so the step is the count of log records times that interval. That is exact as long as the interval matches the run, which is why it is passed in rather than guessed. """ from __future__ import annotations import argparse import ast import logging import re import sys import time from pathlib import Path logger = logging.getLogger(__name__) ACT = "act" GROOT = "groot" #: Default log intervals, read from each trainer's own config default: #: lerobot configs/train.py log_freq=200; Isaac training_config.py logging_steps=10. DEFAULT_INTERVAL = {ACT: 200, GROOT: 10} #: ACT prints flat ``key:value`` pairs. Keys may contain / and _ (``smp/s``, #: ``l1_loss``); values may carry a K/M suffix (``smpl:435K``) or be #: exponential (``lr:1.0e-05``). _ACT_PAIR = re.compile(r"([A-Za-z][A-Za-z0-9_/]*):(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)([KM]?)\b") _SUFFIX = {"": 1, "K": 1_000, "M": 1_000_000} #: logging's ".py:" token, e.g. "ot_train.py:611". #: Deliberately NOT anchored to the start of the line: lerobot's tqdm bar writes #: with \r and no newline, so a log record routinely arrives with the whole #: progress bar glued in front of it ("Training: 1%|...| 1800/300000 [...]INFO #: 2026-07-27 ... ot_train.py:611 step:2K ..."). An anchored prefix strip matches #: none of those, and every record then grows a "py" scalar holding the source #: line number. _LOG_PREFIX = re.compile(r"\S+\.py:\d+") #: GR00T prints a Python dict literal, so it can be parsed as one. _GROOT_DICT = re.compile(r"\{'loss':[^}]*\}") def scalars_from_line(line: str, policy: str) -> dict: """Every numeric scalar on this line, or {} if it carries none.""" if policy == GROOT: match = _GROOT_DICT.search(line) if match is None: return {} try: data = ast.literal_eval(match.group(0)) except (ValueError, SyntaxError): return {} return {k: float(v) for k, v in data.items() if isinstance(v, (int, float))} if policy == ACT: # Only lines that actually carry a loss are training records; the # startup banner also has key:value shapes. if "loss:" not in line: return {} # Drop logging's own "INFO