Spaces:
Running on Zero
Running on Zero
Download fdanyone/device.py from rerun/4danyone-rerun: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/rerun/4danyone-rerun/resolve/1b2e96f9bdb4bdc32148870859e16da0ad533680/fdanyone/device.py
- Command line
-
hf download hf://spaces/rerun/4danyone-rerun@1b2e96f9bdb4bdc32148870859e16da0ad533680/fdanyone/device.py
-
curl -L -o device.py https://huggingface.co/spaces/rerun/4danyone-rerun/resolve/1b2e96f9bdb4bdc32148870859e16da0ad533680/fdanyone/device.py
1 kB
| """CUDA device selection shared by pipeline and isolated workers.""" | |
| from __future__ import annotations | |
| from fdanyone.errors import ConfigurationError | |
| def select_cuda_device(device: str) -> tuple[str, int]: | |
| """Validate, select, and normalize one CUDA device.""" | |
| import torch | |
| try: | |
| requested = torch.device(device) | |
| except (RuntimeError, TypeError, ValueError) as exc: | |
| raise ConfigurationError(f"Invalid CUDA device {device!r}.") from exc | |
| if requested.type != "cuda" or not torch.cuda.is_available(): | |
| raise ConfigurationError(f"4DAnyone requires an available CUDA device, got {device!r}.") | |
| index = torch.cuda.current_device() if requested.index is None else requested.index | |
| if index < 0 or index >= torch.cuda.device_count(): | |
| raise ConfigurationError( | |
| f"CUDA device index {index} is unavailable; visible device count is {torch.cuda.device_count()}." | |
| ) | |
| torch.cuda.set_device(index) | |
| return f"cuda:{index}", index | |