1
Fork 0

refactor(log): extract w&b file sync

This commit is contained in:
Tibo De Peuter 2026-05-07 22:50:38 +02:00
parent 14d719fe74
commit a7db4c77bb
Signed by: tdpeuter
SSH key fingerprint: SHA256:u/h/LVoqKF1Iz02uOyxe6hcjmoZASCGV2HM0TG9ZMoU
2 changed files with 19 additions and 0 deletions

View file

@ -432,6 +432,21 @@ class UnifiedLogger:
except Exception as e:
self.error(f"Error saving final model: {e}")
def sync_file(self, path: Path) -> None:
"""Upload a file to W&B if tracking is enabled.
Best-effort: logs a warning on failure, never raises.
"""
if self.wandb_run is None:
return
try:
import wandb
# "Simple sync" behavior: wandb will copy this file into the run.
wandb.save(str(path), base_path=str(path.parent))
except Exception as e:
self.warning(f"Failed to sync file to W&B: {e}")
def finish(self):
"""Finalize logging and cleanup."""
# Flush remaining metrics