MCPcopy Create free account
hub / github.com/microsoft/TRELLIS / recursive_to_device

Function recursive_to_device

trellis/utils/data_utils.py:9–24  ·  view source on GitHub ↗

Recursively move all tensors in a data structure to a device.

(
    data: Any,
    device: torch.device,
    non_blocking: bool = False,
)

Source from the content-addressed store, hash-verified

7
8
9def recursive_to_device(
10 data: Any,
11 device: torch.device,
12 non_blocking: bool = False,
13) -> Any:
14 """
15 Recursively move all tensors in a data structure to a device.
16 """
17 if hasattr(data, "to"):
18 return data.to(device, non_blocking=non_blocking)
19 elif isinstance(data, (list, tuple)):
20 return type(data)(recursive_to_device(d, device, non_blocking) for d in data)
21 elif isinstance(data, dict):
22 return {k: recursive_to_device(v, device, non_blocking) for k, v in data.items()}
23 else:
24 return data
25
26
27def load_balanced_group_indices(

Callers 3

snapshot_datasetMethod · 0.85
load_dataMethod · 0.85
run_snapshotMethod · 0.85

Calls 1

toMethod · 0.45

Tested by

no test coverage detected