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 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.2.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.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: universal_cuda_tools-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 993e24f34b82284830ff70855e0fb593b1a0714e485276511670e4a01cd77697
MD5 513ba8c486eee3f2c5d784478aaa1ec7
BLAKE2b-256 57f3dcad68b44e70b183243b3c6dfdad4b488cf99839395e7eea0ed20eceb530

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for universal_cuda_tools-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b07feda256baacb248710d9b3876541889267fbfc0b2034925a536ff024cb4
MD5 1ec2e979b0fad436a3cbdf00bac6a8b7
BLAKE2b-256 91d06972aa8c0d76753f80ecd3733a0766f76b2a0985d7232fecfbd9c509f040

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