device
optimus_dl.core.device
¶
Device and distributed setup utilities.
This module provides functions for automatically detecting and setting up the best available compute device (CUDA, MPS, XPU, or CPU) and initializing distributed training collectives.
DeviceSetup
¶
Bases: NamedTuple
Container for device and collective setup results.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
|
None
|
collective
|
Any
|
|
None
|
Source code in optimus_dl/core/device.py
get_best_device()
¶
Detect and return the best available compute device.
Checks for available devices in order of preference: 1. CUDA (NVIDIA GPUs) 2. MPS (Apple Silicon GPUs) 3. XPU (Intel GPUs) 4. CPU (fallback)
Returns:
| Type | Description |
|---|---|
device
|
The best available torch.device. Always returns a valid device, |
device
|
defaulting to CPU if no accelerators are available. |
Source code in optimus_dl/core/device.py
setup_device_and_collective(use_gpu, config)
¶
Setup compute device and distributed training collective.
This function initializes the training environment by: 1. Selecting the appropriate compute device (GPU or CPU) 2. Setting up distributed communication if multiple devices are available 3. Returning both the device and collective for use in training
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_gpu
|
bool
|
If True, attempts to use GPU if available. If False, uses CPU. |
required |
config
|
DistributedConfig
|
Distributed configuration specifying how to set up multi-GPU mesh. |
required |
Returns:
| Type | Description |
|---|---|
DeviceSetup
|
DeviceSetup namedtuple containing: |
DeviceSetup
|
|
DeviceSetup
|
|