Comprehensive device management for PyTorch & TensorFlow & Universal
Project description
universal-cuda-tools
Universal device management for Python, PyTorch, TensorFlow and NumPy. Supports automatic device selection, mixed precision, retry, timeout, telemetry, checkpointing, and full GPU acceleration even for pure Python math via CuPy.
Provides decorators and context managers for:
- Automatic device selection
- Mixed precision (AMP)
- Memory profiling
- Timeout watchdog
- Telemetry
- TPU & Distributed (experimental)
Installation
pip install universal-cuda-tools
Example Usage
Simple Decorator
from cuda_tools import cuda
@cuda(device='cuda:0', use_amp=True)
def infer(model, x):
return model(x)
Advanced decorator
from cuda_tools import cuda
@cuda.advanced(auto_benchmark=True, use_amp=True, retry=2, timeout=300)
def train_step(model, x, y):
# training logic
loss = model(x).mean()
return loss
Context manager
from cuda_tools.context import DeviceContext
with DeviceContext(device='cuda:0', use_amp=True):
output = model(input)
Universal Python Code on CUDA
If you want any pure-Python or NumPy-based math to run on GPU, use auto_tensorize=True:
from cuda_tools import cuda
@cuda(auto_tensorize=True, device='cuda:0')
def pure_python_math(x, y):
# x,y can be int, float, list or numpy array
import numpy as np
a = np.array(x) * np.array(y)
return np.sin(a) + 5
print(pure_python_math([1,2,3], 10))
Or with context manager:
from cuda_tools.context import DeviceContext
with DeviceContext(device='cuda:0', universal=True):
import numpy as np
result = np.linspace(0,5,1000)**2 # will be computed with CuPy under the hood
src/universal_cuda_tools/decorators.py:Simple and advanced decorators for device management. src/universal_cuda_tools/context.py: Context manager for device and precision setup/teardown. src/universal_cuda_tools/utils.py: Utility functions for device management.
Project details
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 universal_cuda_tools-0.8.0.tar.gz.
File metadata
- Download URL: universal_cuda_tools-0.8.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ef6c5424525e2b1d709567f9453b5822dda40c4b7a0c61100131d748bb1412
|
|
| MD5 |
7d4eff0c687c0e14c0a3df90782f970b
|
|
| BLAKE2b-256 |
598468e58e005477b6ffa1d915db0bc0bdc334193480537ef7ae6f444c73a0dd
|
File details
Details for the file universal_cuda_tools-0.8.0-py3-none-any.whl.
File metadata
- Download URL: universal_cuda_tools-0.8.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abd00afce3a6642ae3ce87537edfa3d08f0c88d081299de7959373fd6482ca63
|
|
| MD5 |
0e36f024fa36f9b029117d239dfae633
|
|
| BLAKE2b-256 |
71dfbcdaec903421d31295bcc9e3f7fed0b56e45d4da1c36ad24adb992b8cdf7
|