pycuts


Namepycuts JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryA small collection of Python shortcut scripts for common tasks.
upload_time2024-09-27 11:23:38
maintainerNone
docs_urlNone
authorDaniel Ialcin Misser Westergaard
requires_pythonNone
licenseMIT
keywords shortcuts pycuts utilities
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pycuts

<div style="display: flex; gap: 7px;">
  <a href="https://pypi.org/project/pycuts/" target="_blank"><img alt="PyPI" src="https://img.shields.io/pypi/v/pycuts"></a>
  <a href="https://huggingface.co/spaces/dwancin/" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace-%23097EFF?style=flat&logoColor=black"></a>
  <a href="https://github.com/dwancin/pycuts" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Repository-white?logo=github&logoColor=black"></a>
</div>

**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:

```bash
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

```python
import pycuts
print(f"current device is: {pycuts.device()}")
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pycuts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "shortcuts, pycuts, utilities",
    "author": "Daniel Ialcin Misser Westergaard",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/33/ca/7aa12141395e9454e1df1e04c36e23db6857bb93c9f0c9a43a4a2684036c/pycuts-1.0.0.tar.gz",
    "platform": null,
    "description": "# pycuts\n\n<div style=\"display: flex; gap: 7px;\">\n  <a href=\"https://pypi.org/project/pycuts/\" target=\"_blank\"><img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/pycuts\"></a>\n  <a href=\"https://huggingface.co/spaces/dwancin/\" target=\"_blank\"><img alt=\"Hugging Face\" src=\"https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace-%23097EFF?style=flat&logoColor=black\"></a>\n  <a href=\"https://github.com/dwancin/pycuts\" target=\"_blank\"><img alt=\"Static Badge\" src=\"https://img.shields.io/badge/Repository-white?logo=github&logoColor=black\"></a>\n</div>\n\n**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.\n\n## Installation\n\nYou can install pycuts directly from PyPI:\n\n```bash\npip install pycuts\n```\n\n## Shortcuts\n\n| **Function**          | **Return Type**       | **Description**                                                        |\n|-----------------------|-----------------------|------------------------------------------------------------------------|\n| `device()`            | `torch.device`        | Determines the best device to use (`cuda`, `mps`, or `cpu`).            |\n| `gpu()`               | `bool`                | Returns `True` if a GPU (\"cuda\" or \"mps\") is available, otherwise `False`. |\n| `torch_dtype()`       | `torch.dtype`         | Determines the appropriate tensor precision based on the device.        |\n| `synchronize()`       | `None`                | Waits for all kernels in all streams on the given device to complete.   |\n| `empty_cache()`       | `None`                | Clears the GPU memory to prevent out-of-memory errors.                  |\n| `device_count()`      | `int`                 | Returns the number of available devices (e.g., number of GPUs).         |\n| `manual_seed(seed)`   | `None`                | Sets the random seed for reproducible behavior across CPU/GPU.          |\n| `is_spaces()`         | `bool`                | Returns `True` if running in a Hugging Face Space, otherwise `False`.   |\n| `is_zero_gpu_space()` | `bool`                | Returns `True` if running in a zero-GPU Hugging Face Space.             |\n\n## Examples\n\n```python\nimport pycuts\nprint(f\"current device is: {pycuts.device()}\")\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A small collection of Python shortcut scripts for common tasks.",
    "version": "1.0.0",
    "project_urls": {
        "repository": "https://github.com/dwancin/pycuts"
    },
    "split_keywords": [
        "shortcuts",
        " pycuts",
        " utilities"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f1889e4a0eb22fb92eb161993a8d8288e38da4df7819943d19b8708797d11e16",
                "md5": "dd08151caec0fc51addcb88f8129d370",
                "sha256": "f50f94203cc0907a80957f17a43e177fbb5fd81618fda5880da2c0c59d928135"
            },
            "downloads": -1,
            "filename": "pycuts-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dd08151caec0fc51addcb88f8129d370",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4840,
            "upload_time": "2024-09-27T11:23:36",
            "upload_time_iso_8601": "2024-09-27T11:23:36.793428Z",
            "url": "https://files.pythonhosted.org/packages/f1/88/9e4a0eb22fb92eb161993a8d8288e38da4df7819943d19b8708797d11e16/pycuts-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33ca7aa12141395e9454e1df1e04c36e23db6857bb93c9f0c9a43a4a2684036c",
                "md5": "80003878e5ed47df5e696e360d2cd91a",
                "sha256": "d116ad085cbadb2f52cc16401d7e39642f3cfff31257e121f0447f71c7808f0c"
            },
            "downloads": -1,
            "filename": "pycuts-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "80003878e5ed47df5e696e360d2cd91a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3960,
            "upload_time": "2024-09-27T11:23:38",
            "upload_time_iso_8601": "2024-09-27T11:23:38.559729Z",
            "url": "https://files.pythonhosted.org/packages/33/ca/7aa12141395e9454e1df1e04c36e23db6857bb93c9f0c9a43a4a2684036c/pycuts-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-27 11:23:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dwancin",
    "github_project": "pycuts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pycuts"
}
        
Elapsed time: 0.34418s