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
Metadata
Release files for devicer 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| devicer-0.1.1.tar.gz | 2.5 kB | Without provenance | Details for devicer-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| devicer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for devicer-0.1.1-py3-none-any.whl |
Total release size: 6.0 kB
Release files / devicer-0.1.1.tar.gz
| Download URL | devicer-0.1.1.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1568bfcab9bf687452bf4dea1c7beed52d9d926a533a6248b1dd92d2a9dc156f
|
|
BLAKE2b-256 checksum How to use checksums |
8c7a72244570a812e200dff1904c0cace93a0465a5fd720e6faa76937c1423a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.8
|
Release files / devicer-0.1.1-py3-none-any.whl
| Download URL | devicer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fac7b4e55510a165184fce6315b03f05cfa094131da43e77fe22114bd92498f4
|
|
BLAKE2b-256 checksum How to use checksums |
01a44c3f53f6837494df02b2e496d96dde4973f49a88771cd2753df78f7e888c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.8
|
Security for devicer 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.