Send tensor into the device of the module. Args: m (torch.nn.Module): Torch module. x (Tensor): Torch tensor. Returns: Tensor: Torch tensor located in the same place as torch module.
(m, x)
| 10 | |
| 11 | |
| 12 | def to_device(m, x): |
| 13 | """Send tensor into the device of the module. |
| 14 | |
| 15 | Args: |
| 16 | m (torch.nn.Module): Torch module. |
| 17 | x (Tensor): Torch tensor. |
| 18 | |
| 19 | Returns: |
| 20 | Tensor: Torch tensor located in the same place as torch module. |
| 21 | |
| 22 | """ |
| 23 | if isinstance(m, torch.nn.Module): |
| 24 | device = next(m.parameters()).device |
| 25 | elif isinstance(m, torch.Tensor): |
| 26 | device = m.device |
| 27 | else: |
| 28 | raise TypeError("Expected torch.nn.Module or torch.tensor, " f"bot got: {type(m)}") |
| 29 | return x.to(device) |
| 30 | |
| 31 | |
| 32 | def pad_list(xs, pad_value): |
no test coverage detected
searching dependent graphs…