refactor(log): extract w&b file sync
This commit is contained in:
parent
14d719fe74
commit
a7db4c77bb
2 changed files with 19 additions and 0 deletions
|
|
@ -71,6 +71,10 @@ class SimpleLogger:
|
||||||
def save_final_model(self, params: Any, metadata: Optional[Dict[str, Any]] = None):
|
def save_final_model(self, params: Any, metadata: Optional[Dict[str, Any]] = None):
|
||||||
print("[SAVE] Final model would be saved (SimpleLogger: No-Op)")
|
print("[SAVE] Final model would be saved (SimpleLogger: No-Op)")
|
||||||
|
|
||||||
|
def sync_file(self, path: Any):
|
||||||
|
"""No-op for SimpleLogger."""
|
||||||
|
pass
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
print(f"[FINISH] SimpleLogger finished for run: {self.run_name}")
|
print(f"[FINISH] SimpleLogger finished for run: {self.run_name}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -432,6 +432,21 @@ class UnifiedLogger:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.error(f"Error saving final model: {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):
|
def finish(self):
|
||||||
"""Finalize logging and cleanup."""
|
"""Finalize logging and cleanup."""
|
||||||
# Flush remaining metrics
|
# Flush remaining metrics
|
||||||
|
|
|
||||||
Reference in a new issue