jax-tqdm


Namejax-tqdm JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/jeremiecoullon/jax-tqdm
SummaryTqdm progress bar for JAX scans and loops
upload_time2024-04-26 10:40:17
maintainerNone
docs_urlNone
authorJeremie Coullon
requires_python<4.0,>=3.9
licenseMIT
keywords jax tqdm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JAX-tqdm

Add a [tqdm](https://github.com/tqdm/tqdm) progress bar to your JAX scans and loops.

## Installation

Install with pip:

```bash
pip install jax-tqdm
```

## Example usage

### in `jax.lax.scan`

```python
from jax_tqdm import scan_tqdm
from jax import lax
import jax.numpy as jnp

n = 10_000

@scan_tqdm(n)
def step(carry, x):
    return carry + 1, carry + 1

last_number, all_numbers = lax.scan(step, 0, jnp.arange(n))
```

### in `jax.lax.fori_loop`

```python
from jax_tqdm import loop_tqdm
from jax import lax

n = 10_000

@loop_tqdm(n)
def step(i, val):
    return val + 1

last_number = lax.fori_loop(0, n, step, 0)
```

### Print Rate

By default, the progress bar is updated 20 times over the course of the scan/loop
(for performance purposes, see [below](#why-jax-tqdm)). This
update rate can be manually controlled with the `print_rate` keyword argument. For
example:

```python
from jax_tqdm import scan_tqdm
from jax import lax
import jax.numpy as jnp

n = 10_000

@scan_tqdm(n, print_rate=2)
def step(carry, x):
    return carry + 1, carry + 1

last_number, all_numbers = lax.scan(step, 0, jnp.arange(n))
```

will update every other step.

### Progress bar options

Any additional keyword arguments are passed to the [tqdm](https://github.com/tqdm/tqdm)
progress bar constructor. For example:

```python
from jax_tqdm import scan_tqdm
from jax import lax
import jax.numpy as jnp

n = 10_000

@scan_tqdm(n, print_rate=1, desc='progress bar', position=0, leave=False)
def step(carry, x):
    return carry + 1, carry + 1

last_number, all_numbers = lax.scan(step, 0, jnp.arange(n))
```

## Why JAX-tqdm?

JAX functions are [pure](https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#pure-functions),
so side effects such as printing progress when running scans and loops are not allowed.
However, the
[debug module](https://jax.readthedocs.io/en/latest/notebooks/external_callbacks.html#exploring-debug-callback)
has primitives for calling Python functions on the host from JAX code. This can be used
to update a Python tqdm progress bar regularly during the computation. JAX-tqdm
implements this for JAX scans and loops and is used by simply adding a decorator to the
body of your update function.

Note that as the tqdm progress bar is only updated 20 times during the scan or loop,
there is no performance penalty.

The code is explained in more detail in this [blog post](https://www.jeremiecoullon.com/2021/01/29/jax_progress_bar/).

## Developers

Dependencies can be installed with [poetry](https://python-poetry.org/) by running

```bash
poetry install
```

### Pre-Commit Hooks

Pre commit hooks can be installed by running

```bash
pre-commit install
```

Pre-commit checks can then be run using

```bash
task lint
```

### Tests

Tests can be run with

```bash
task test
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jeremiecoullon/jax-tqdm",
    "name": "jax-tqdm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "jax, tqdm",
    "author": "Jeremie Coullon",
    "author_email": "jeremie.coullon@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/7a/4700283b547ccdf8ea4e9d0aa3fc8d0fc436fdb2816dc9135dd40966d39e/jax_tqdm-0.2.0.tar.gz",
    "platform": null,
    "description": "# JAX-tqdm\n\nAdd a [tqdm](https://github.com/tqdm/tqdm) progress bar to your JAX scans and loops.\n\n## Installation\n\nInstall with pip:\n\n```bash\npip install jax-tqdm\n```\n\n## Example usage\n\n### in `jax.lax.scan`\n\n```python\nfrom jax_tqdm import scan_tqdm\nfrom jax import lax\nimport jax.numpy as jnp\n\nn = 10_000\n\n@scan_tqdm(n)\ndef step(carry, x):\n    return carry + 1, carry + 1\n\nlast_number, all_numbers = lax.scan(step, 0, jnp.arange(n))\n```\n\n### in `jax.lax.fori_loop`\n\n```python\nfrom jax_tqdm import loop_tqdm\nfrom jax import lax\n\nn = 10_000\n\n@loop_tqdm(n)\ndef step(i, val):\n    return val + 1\n\nlast_number = lax.fori_loop(0, n, step, 0)\n```\n\n### Print Rate\n\nBy default, the progress bar is updated 20 times over the course of the scan/loop\n(for performance purposes, see [below](#why-jax-tqdm)). This\nupdate rate can be manually controlled with the `print_rate` keyword argument. For\nexample:\n\n```python\nfrom jax_tqdm import scan_tqdm\nfrom jax import lax\nimport jax.numpy as jnp\n\nn = 10_000\n\n@scan_tqdm(n, print_rate=2)\ndef step(carry, x):\n    return carry + 1, carry + 1\n\nlast_number, all_numbers = lax.scan(step, 0, jnp.arange(n))\n```\n\nwill update every other step.\n\n### Progress bar options\n\nAny additional keyword arguments are passed to the [tqdm](https://github.com/tqdm/tqdm)\nprogress bar constructor. For example:\n\n```python\nfrom jax_tqdm import scan_tqdm\nfrom jax import lax\nimport jax.numpy as jnp\n\nn = 10_000\n\n@scan_tqdm(n, print_rate=1, desc='progress bar', position=0, leave=False)\ndef step(carry, x):\n    return carry + 1, carry + 1\n\nlast_number, all_numbers = lax.scan(step, 0, jnp.arange(n))\n```\n\n## Why JAX-tqdm?\n\nJAX functions are [pure](https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#pure-functions),\nso side effects such as printing progress when running scans and loops are not allowed.\nHowever, the\n[debug module](https://jax.readthedocs.io/en/latest/notebooks/external_callbacks.html#exploring-debug-callback)\nhas primitives for calling Python functions on the host from JAX code. This can be used\nto update a Python tqdm progress bar regularly during the computation. JAX-tqdm\nimplements this for JAX scans and loops and is used by simply adding a decorator to the\nbody of your update function.\n\nNote that as the tqdm progress bar is only updated 20 times during the scan or loop,\nthere is no performance penalty.\n\nThe code is explained in more detail in this [blog post](https://www.jeremiecoullon.com/2021/01/29/jax_progress_bar/).\n\n## Developers\n\nDependencies can be installed with [poetry](https://python-poetry.org/) by running\n\n```bash\npoetry install\n```\n\n### Pre-Commit Hooks\n\nPre commit hooks can be installed by running\n\n```bash\npre-commit install\n```\n\nPre-commit checks can then be run using\n\n```bash\ntask lint\n```\n\n### Tests\n\nTests can be run with\n\n```bash\ntask test\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tqdm progress bar for JAX scans and loops",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/jeremiecoullon/jax-tqdm",
        "Repository": "https://github.com/jeremiecoullon/jax-tqdm"
    },
    "split_keywords": [
        "jax",
        " tqdm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f08a08fd33d2b2a41642036d7ea38c52613be26f9b07f223184cc570d3a506eb",
                "md5": "d29b042166371f25660c6d67f85834d1",
                "sha256": "09c2afabe0804d4f489a49f6b036d5cc0603f2f2e1dcc424506ece8977154af9"
            },
            "downloads": -1,
            "filename": "jax_tqdm-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d29b042166371f25660c6d67f85834d1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 4473,
            "upload_time": "2024-04-26T10:40:16",
            "upload_time_iso_8601": "2024-04-26T10:40:16.030123Z",
            "url": "https://files.pythonhosted.org/packages/f0/8a/08fd33d2b2a41642036d7ea38c52613be26f9b07f223184cc570d3a506eb/jax_tqdm-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b17a4700283b547ccdf8ea4e9d0aa3fc8d0fc436fdb2816dc9135dd40966d39e",
                "md5": "3fa3219ea69b07485cea9f29aa3beaa2",
                "sha256": "466db74e4326af2745d9789c8719309af7a48aacb3e0543a49f42ea169d41c87"
            },
            "downloads": -1,
            "filename": "jax_tqdm-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3fa3219ea69b07485cea9f29aa3beaa2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 3999,
            "upload_time": "2024-04-26T10:40:17",
            "upload_time_iso_8601": "2024-04-26T10:40:17.767210Z",
            "url": "https://files.pythonhosted.org/packages/b1/7a/4700283b547ccdf8ea4e9d0aa3fc8d0fc436fdb2816dc9135dd40966d39e/jax_tqdm-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-26 10:40:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jeremiecoullon",
    "github_project": "jax-tqdm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jax-tqdm"
}
        
Elapsed time: 0.26181s