Skip to main content

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

universal_cuda_tools-0.1.3.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

universal_cuda_tools-0.1.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file universal_cuda_tools-0.1.3.tar.gz.

File metadata

  • Download URL: universal_cuda_tools-0.1.3.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for universal_cuda_tools-0.1.3.tar.gz
Algorithm Hash digest
SHA256 19fddc68939e288d1440d9d6d1a813cf91ffedd64782c2c7de0c6040e9f7c593
MD5 0280ad86cb78246bdbf5b96d21c87f3f
BLAKE2b-256 93997901a4bd2176da44edf3a9d46175299c954384add1fe416a5a9cdd519bb6

See more details on using hashes here.

File details

Details for the file universal_cuda_tools-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for universal_cuda_tools-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9ab40673419972091a5e7e0a1ed003d9b445e3e1bd8f08fb2943e27530e19334
MD5 d7d0a6dc8fa3b67a195d2716484144f4
BLAKE2b-256 50fa2bb7543d8c97f68411bcfab39b71cfc30ad5c101bfc5bac9623bed8f2636

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page