Provides a helper to detect the best Pytorch device (env override, CUDA, MPS, XPU, or CPU) and to clear CUDA caches.
Project description
Pytorch Device Detection
Small utility to select a torch device at runtime and to clear CUDA caches.
Summary
Provides two functions:
-
get_device(strings=False, verbose=False): returns the best available device (torch.deviceby default, or a string whenstrings=True). Probes in this order:TORCH_DEVICE/DEVICEenvironment variables, CUDA, MPS, XPU (torch.xpu or intel_extension_for_pytorch.xpu), then CPU. Whenverbose=Truethe function emits debug-level messages through the logger. -
clear_torch(): callstorch.cuda.empty_cache().
Install
uv add devicer
If you want XPU:
uv add devicer[xpu]
Usage
from devicer import get_device
device = get_device()
print(device)
Environment variables:
- Set
TORCH_DEVICEorDEVICEto force a device, for examplecuda,cuda:0,mps,cpu, orxpu:
export TORCH_DEVICE=cuda
python myscript.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file devicer-0.1.1.tar.gz.
File metadata
- Download URL: devicer-0.1.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1568bfcab9bf687452bf4dea1c7beed52d9d926a533a6248b1dd92d2a9dc156f
|
|
| MD5 |
6eb62f9a0992aba0ba8552addfc3bb38
|
|
| BLAKE2b-256 |
8c7a72244570a812e200dff1904c0cace93a0465a5fd720e6faa76937c1423a3
|
File details
Details for the file devicer-0.1.1-py3-none-any.whl.
File metadata
- Download URL: devicer-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fac7b4e55510a165184fce6315b03f05cfa094131da43e77fe22114bd92498f4
|
|
| MD5 |
726bcfc44fecde757c6cdbda303a1972
|
|
| BLAKE2b-256 |
01a44c3f53f6837494df02b2e496d96dde4973f49a88771cd2753df78f7e888c
|