ml.utils.device.base
Utilities for working with devices.
This module contains utilities for working with devices, such as moving tensors and modules to devices, and getting prefetchers for non-blocking host-to-device transfers.
The typical flow for using this module is:
from ml.utils.device.auto import detect_device
device = detect_device()
device.module_to(some_module)
device.tensor_to(some_tensor)
device.get_prefetcher(some_dataloader)
device.recursive_apply(some_container, some_func)
- class ml.utils.device.base.Prefetcher(to_device_func: Callable[[Any], Any], dataloader: DataLoader[T_co], raise_stop_iter: bool = False)[source]
Bases:
Iterable
[T_co
],Generic
[T_co
]Helper class for pre-loading samples into device memory.
- property dataloader_iter: _BaseDataLoaderIter
- class ml.utils.device.base.InfinitePrefetcher(prefetcher: Prefetcher[T_co])[source]
Bases:
Iterable
[T_co
]
- class ml.utils.device.base.base_device[source]
Bases:
ABC
Base mixin for different trainer device types.
- abstract classmethod has_device() bool [source]
Detects whether or not the device is available.
- Returns:
If the device is available
- abstract get_torch_compile_backend() str | Callable [source]
Returns the backend to use for Torch compile.
- Returns:
The backend
- get_prefetcher(dataloader: DataLoader) Prefetcher [source]