(tensors, device)
| 15 | |
| 16 | |
| 17 | def to_device(tensors, device): |
| 18 | if isinstance(tensors, torch.Tensor): |
| 19 | return tensors.to(device=device) |
| 20 | elif isinstance(tensors, dict): |
| 21 | return dict( |
| 22 | (key, to_device(tensor, device)) for (key, tensor) in tensors.items() |
| 23 | ) |
| 24 | else: |
| 25 | raise NotImplementedError("Unknown type {0}".format(type(tensors))) |