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

torch init #33

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions d6tflow/targets/torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from d6tflow.targets import DataTarget
import torch


class PyTorchModel(DataTarget):


def load(self, cached=False, **kwargs):
"""
Load saved model

Args:
cached (bool): keep data cached in memory
**kwargs: arguments to pass to pd.read_parquet

Returns: pandas dataframe

"""
return super().load(torch.load, cached, **kwargs)



def save(self, model, **kwargs):
"""
Save torch model

Args:
model (obj): python object
kwargs : additional arguments to pass to torch.save

Returns: filename

"""

(self.path).parent.mkdir(parents=True, exist_ok=True)
torch.save(model, self.path, **kwargs)
return self.path
10 changes: 10 additions & 0 deletions d6tflow/tasks/torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from d6tflow.tasks import TaskData
from d6tflow.targets.torch import PyTorchModel

class PyTorch(TaskData):
"""
Task which saves to .pt models
"""
target_class = PyTorchModel
target_ext = '.pt'

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ toolz
dask[dataframe]
d6tcollect
pyarrow
torch