MCPcopy Index your code
hub / github.com/apple/ml-pointersect / to_device

Function to_device

plib/utils.py:76–93  ·  view source on GitHub ↗

Send each torch.Tensor in arr to device.

(
        arr: T.Union[torch.Tensor, T.List[torch.Tensor], T.Dict[str, T.Any]],
        device: torch.device,
)

Source from the content-addressed store, hash-verified

74
75
76def to_device(
77 arr: T.Union[torch.Tensor, T.List[torch.Tensor], T.Dict[str, T.Any]],
78 device: torch.device,
79) -> T.Union[torch.Tensor, T.List[torch.Tensor], T.Dict[str, T.Any]]:
80 """
81 Send each torch.Tensor in arr to device.
82 """
83 if isinstance(arr, torch.Tensor):
84 arr = arr.to(device=device)
85 return arr
86 elif isinstance(arr, (list, tuple)):
87 return [to_device(x, device=device) for x in arr]
88 elif isinstance(arr, dict):
89 for key, val in arr.items():
90 arr[key] = to_device(val, device=device)
91 return arr
92 else:
93 return arr
94
95
96def to_dtype(

Callers

nothing calls this directly

Calls 1

toMethod · 0.45

Tested by

no test coverage detected