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 InputFeatures .to #193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions openprompt/data_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ def to_tensor(self, device: str = 'cuda'):
def to(self, device: str = "cuda:0"):
r"""move the tensor keys to runtime device, such as gpu:0
"""
for key in self.tensorable_keys:
value = getattr(self, key)
target = copy.deepcopy(self)
for key in target.tensorable_keys:
value = getattr(target, key)
if value is not None:
setattr(self, key, value.to(device))
return self
setattr(target, key, value.to(device))
return target

def cuda(self, device: str = "cuda:0"):
r"""mimic the tensor behavior
Expand Down