A small collection of Python shortcut scripts for common tasks.
Project description
pycuts
pycuts is a small Python library that provides a collection of shortcut functions for common operations across various libraries, particularly for PyTorch and Hugging Face Hub environments.
Installation
You can install pycuts directly from PyPI:
pip install pycuts
Shortcuts
Function | Return Type | Description |
---|---|---|
device() |
torch.device |
Determines the best device to use (cuda , mps , or cpu ). |
gpu() |
bool |
Returns True if a GPU ("cuda" or "mps") is available, otherwise False . |
torch_dtype() |
torch.dtype |
Determines the appropriate tensor precision based on the device. |
synchronize() |
None |
Waits for all kernels in all streams on the given device to complete. |
empty_cache() |
None |
Clears the GPU memory to prevent out-of-memory errors. |
device_count() |
int |
Returns the number of available devices (e.g., number of GPUs). |
manual_seed(seed) |
None |
Sets the random seed for reproducible behavior across CPU/GPU. |
is_spaces() |
bool |
Returns True if running in a Hugging Face Space, otherwise False . |
is_zero_gpu_space() |
bool |
Returns True if running in a zero-GPU Hugging Face Space. |
Examples
import pycuts
print(f"current device is: {pycuts.device()}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycuts-1.0.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
pycuts-1.0.0-py3-none-any.whl
(4.8 kB
view hashes)