Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/nn_core/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ def _is_nnlogger(trainer: Trainer) -> bool:

def on_train_start(self, trainer: pl.Trainer, pl_module: pl.LightningModule) -> None:
if self._is_nnlogger(trainer):
trainer.logger: NNLogger
trainer.logger.upload_source()
trainer.logger.log_configuration(model=pl_module)
trainer.logger.watch_model(pl_module=pl_module)

def on_train_end(self, trainer: pl.Trainer, pl_module: pl.LightningModule) -> None:
if self._is_nnlogger(trainer):
trainer.logger: NNLogger
trainer.logger.upload_run_files()

def on_save_checkpoint(
self, trainer: pl.Trainer, pl_module: pl.LightningModule, checkpoint: Dict[str, Any]
) -> None:
Expand Down
12 changes: 11 additions & 1 deletion src/nn_core/model_logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import logging
import os
import shutil
from pathlib import Path
from typing import Any, Dict, Optional, Union

Expand Down Expand Up @@ -55,7 +56,7 @@ def watch_model(self, pl_module: LightningModule):

def upload_source(self) -> None:
if self.logging_cfg.upload.source and self.wandb:
pylogger.info("Uploading source code to wandb")
pylogger.info("Uploading source code to W&B")
self.wrapped.experiment.log_code(
root=PROJECT_ROOT,
name=None,
Expand Down Expand Up @@ -201,3 +202,12 @@ def log_configuration(
# send hparams to all loggers
pylogger.debug("Logging 'cfg'")
self.wrapped.log_hyperparams(cfg)

def upload_run_files(self):
if self.logging_cfg.upload.run_files:
if self.wandb:
pylogger.info("Uploading run files to W&B")
shutil.copytree(self.run_dir, f"{self.wrapped.experiment.dir}/run_files")

# FIXME: symlink not working for some reason
# os.symlink(self.run_dir, f"{self.wrapped.experiment.dir}/run_files", target_is_directory=True)