Skip to main content

Comprehensive device management for PyTorch & TensorFlow

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 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.0.tar.gz (5.6 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.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: universal_cuda_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 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.0.tar.gz
Algorithm Hash digest
SHA256 7971216fe265cc533db664cfd07b280b13c4f6157aad55d5bbf8ee23d78824df
MD5 4e6cb1f815f9fab729c66fec9be70733
BLAKE2b-256 60ba30d5fd36e26a326a359e6fb5b69ad8edf986a40d704a8f0ce87dae521d2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for universal_cuda_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df2ee267601d56f815e365429432209dbfdb1833f29ae8aecc557e7bf9d186a6
MD5 05cbb939657b9f494f7f83d39ad8aaaf
BLAKE2b-256 2ff1597c049e80bd917e3106010c4963a71ff2a77a91cc0177b44a94f19dd04f

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