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

Allow more object types for model input and labels #29

Merged
merged 2 commits into from
Apr 18, 2020
Merged
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
8 changes: 5 additions & 3 deletions torch_lr_finder/lr_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,14 @@ def _train_batch(self, iter_wrapper, accumulation_steps):

def _move_to_device(self, inputs, labels):
def move(obj, device):
if isinstance(obj, tuple):
return tuple(move(o, device) for o in obj)
elif torch.is_tensor(obj):
if hasattr(obj, 'to'):
return obj.to(device)
elif isinstance(obj, tuple):
return tuple(move(o, device) for o in obj)
elif isinstance(obj, list):
return [move(o, device) for o in obj]
elif isinstance(obj, dict):
return {k: move(o, device) for k, o in obj.items()}
else:
return obj

Expand Down