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

Uploaded Python 3

File details

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

File metadata

  • Download URL: universal_cuda_tools-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7ae03cb5014dbb984b4e8dbda7dcb671559207fa2600ba85aa0cfb37ab032cab
MD5 4cd4c2956354820829efc3a9fa517fd5
BLAKE2b-256 8d15ad933795eb135da119326fc7b2da53369a15d24973d5d8d5cb9204e580c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for universal_cuda_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 262384407cacc1f20326b8817681a652425a29bc958a6ba321851e933df41003
MD5 5d9c5b61cf0769382e103e8cfdc528b4
BLAKE2b-256 5da248f736a0ddeb1ed54ccba4d63893d8c8079c63550c7c3cf16e330a1f0faf

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