Skip to main content

JAX-tqdm

Add a tqdm progress bar to your JAX scans and loops.

Installation

Install with pip:

pip install jax-tqdm

Example usage

in jax.lax.scan

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

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). This update rate can be manually controlled with the print_rate keyword argument. For example:

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 type

You can select the tqdm submodule manually with the tqdm_type option. The options are 'std', 'notebook', or 'auto'.

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

n = 10_000

@scan_tqdm(n, print_rate=1, tqdm_type='std') # tqdm_type='std' or 'notebook' or 'auto'
def step(carry, x):
    return carry + 1, carry + 1

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

Progress bar options

Any additional keyword arguments are passed to the tqdm progress bar constructor. For example:

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, so side effects such as printing progress when running scans and loops are not allowed. However, the debug module 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.

Developers

Dependencies can be installed with poetry by running

poetry install

Pre-Commit Hooks

Pre commit hooks can be installed by running

pre-commit install

Pre-commit checks can then be run using

task lint

Tests

Tests can be run with

task test

Metadata

Release files for jax-tqdm 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jax-tqdm 0.2.2
File Size Uploaded
jax_tqdm-0.2.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jax-tqdm 0.2.2
File Interpreter ABI Platform
jax_tqdm-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / jax_tqdm-0.2.2.tar.gz

Download URL jax_tqdm-0.2.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
178cf14f77c11f1318bd305d14771185aff72fb1a03332e06c78e51cc230f888
BLAKE2b-256 checksum
How to use checksums
3868d6694219c733c63c9caec4b64492f252456ba5ef5edeed6ba37247754fc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.10.6 Linux/6.9.3-76060903-generic

Release files / jax_tqdm-0.2.2-py3-none-any.whl

Download URL jax_tqdm-0.2.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4007ce510e7bc81efc8dd75330f842d4698b8ec5cbd61453f8fe0b237b16af26
BLAKE2b-256 checksum
How to use checksums
38c5e6dda36c05032cc7b36799e39b19f29677b0d2098d3d30490f3912bda5ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.10.6 Linux/6.9.3-76060903-generic

Release history Release notifications | RSS feed

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page