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

Add experiment flag to pickle only on checkpoints #224

Closed
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
14 changes: 11 additions & 3 deletions flambe/experiment/tune_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import shutil

import ray
import torch
import dill

from flambe.compile import load_state_from_file, Schema, Component
from flambe.compile.extensions import setup_default_modules, import_modules
Expand Down Expand Up @@ -153,13 +155,19 @@ def _train(self) -> Dict:
def _save(self, checkpoint_dir: str) -> str:
"""Subclasses should override this to implement save()."""
path = os.path.join(checkpoint_dir, "checkpoint.flambe")
self.block.save(path, pickle_only=self.pickle_checkpoints, overwrite=True)
if self.pickle_checkpoints:
torch.save(self.block, path, pickle_module=dill)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no overrite here?

Also still no way of selecting torch instead of dill?

else:
self.block.save(path, overwrite=True)
return path

def _restore(self, checkpoint: str) -> None:
"""Subclasses should override this to implement restore()."""
state = load_state_from_file(checkpoint)
self.block.load_state(state)
if self.pickle_checkpoints:
self.block = torch.load(checkpoint, pickle_protocol=dill)
else:
state = load_state_from_file(checkpoint)
self.block.load_state(state)

def _stop(self):
"""Subclasses should override this for any cleanup on stop."""
Expand Down