Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Resuming Training gives CheckpointMismatchError #1310

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/pykeen/trackers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ class JSONResultTracker(FileResultTracker):
extension = "jsonl"

def _write(self, obj) -> None:
obj = obj.copy()
for key, value in obj.items():
# Check if value is JSON serializable
try:
json.dumps(value)
except TypeError:
obj[key] = value.__class__.__name__
print(json.dumps(obj), file=self.file, flush=True) # noqa:T201

# docstr-coverage: inherited
Expand Down
9 changes: 8 additions & 1 deletion src/pykeen/trackers/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def __init__(
raise ValueError("Weights & Biases requires a project name.")
self.project = project

if "allow_val_change" not in kwargs:
kwargs["allow_val_change"] = None

if offline:
os.environ[self.wandb.env.MODE] = "dryrun" # type: ignore
self.kwargs = kwargs
Expand Down Expand Up @@ -80,4 +83,8 @@ def log_params(self, params: Mapping[str, Any], prefix: Optional[str] = None) ->
if self.run is None:
raise AssertionError("start_run must be called before logging any metrics")
params = flatten_dictionary(dictionary=params, prefix=prefix)
self.run.config.update(params)

if self.kwargs["allow_val_change"]:
self.run.config.update(params, allow_val_change=True)
else:
self.run.config.update(params)
12 changes: 6 additions & 6 deletions src/pykeen/training/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,11 +1238,7 @@ def _load_state(

logger.info(f"=> loading checkpoint '{path}'")
checkpoint = torch.load(path)
if checkpoint["checksum"] != self.checksum:
raise CheckpointMismatchError(
f"The checkpoint file '{path}' that was provided already exists, but seems to be "
f"from a different training loop setup.",
)

# Cuda requires its own random state, which can only be set when a cuda device is available
torch_cuda_random_state = checkpoint["torch_cuda_random_state"]
if torch_cuda_random_state is not None and torch.cuda.is_available():
Expand Down Expand Up @@ -1306,5 +1302,9 @@ def _load_state(
np.random.set_state(checkpoint["np_random_state"])
torch.random.set_rng_state(checkpoint["torch_random_state"])
logger.info(f"=> loaded checkpoint '{path}' stopped after having finished epoch {checkpoint['epoch']}")

if checkpoint["checksum"] != self.checksum:
raise CheckpointMismatchError(
f"The checkpoint file '{path}' that was provided already exists, but seems to be "
f"from a different training loop setup.",
)
return best_epoch_model_file_path, best_epoch