Skip to content
Open
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions python/keepsake/pl_callback.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from copy import deepcopy
from typing import Optional, Dict, Tuple, Any
from pathlib import Path

import keepsake
from pytorch_lightning.callbacks.base import Callback
Expand Down Expand Up @@ -56,15 +57,18 @@ def __init__(
"""

super().__init__()
self.filepath = filepath
self.filepath = Path(filepath).resolve()
self.params = params
self.primary_metric = primary_metric
self.period = period
self.save_weights_only = save_weights_only
self.last_global_step_saved = -1

def on_pretrain_routine_start(self, trainer, pl_module):
self.experiment = keepsake.init(path=".", params=self.params)
self.experiment = keepsake.init(
path=str(self.filepath.parent),
params=self.params,
)

def on_epoch_end(self, trainer, pl_module):
self._save_model(trainer, pl_module)
Expand All @@ -89,7 +93,7 @@ def _save_model(self, trainer, pl_module):
return

if self.filepath != None:
trainer.save_checkpoint(self.filepath, self.save_weights_only)
trainer.save_checkpoint(self.filepath.name, self.save_weights_only)

self.last_global_step_saved = global_step

Expand All @@ -99,7 +103,7 @@ def _save_model(self, trainer, pl_module):
metrics.update({"global_step": trainer.global_step})

self.experiment.checkpoint(
path=self.filepath,
path=self.filepath.name,
step=trainer.current_epoch,
metrics=metrics,
primary_metric=self.primary_metric,
Expand Down