Skip to main content

Jaxpr-Viz

JAX Computation Graph Visualisation Tool

JAX has built-in functionality to visualise the HLO graph generated by JAX, but I've found this rather low-level for some use-cases.

The intention of this package is to visualise how sub-functions are connected in JAX programs. It does this by converting the JaxPr representation into a pydot graph. See here for examples.

NOTE: This project is still at an early stage and may not support all JAX functionality (or permutations thereof). If you spot some strange behaviour please create a Github issue.

Installation

Install with pip:

pip install jpviz

Dependent on your system you may also need to install Graphviz

Usage

Jaxpr-viz can be used to visualise jit compiled (and nested) functions. It wraps jit compiled functions, which when called with concrete values returns a pydot graph.

For example this simple computation graph

import jax
import jax.numpy as jnp

import jpviz

@jax.jit
def foo(x):
    return 2 * x

@jax.jit
def bar(x):
    x = foo(x)
    return x - 1

# Wrap function and call with concrete arguments
#  here dot_graph is a pydot object
dot_graph = jpviz.draw(bar)(jnp.arange(10))
# This renders the graph to a png file
dot_graph.write_png("computation_graph.png")

produces this image

bar computation graph

Pydot has a number of options for rendering graphs, see here.

NOTE: For sub-functions to show as nodes/sub-graphs they need to be marked with @jax.jit, otherwise they will just merged into thir parent graph.

Jupyter Notebook

To show the rendered graph in a jupyter notebook you can use the helper function view_pydot

...
dot_graph = jpviz.draw(bar)(jnp.arange(10))
jpviz.view_pydot(dot)

Visualisation Options

Collapse Nodes

By default, functions that are composed of only primitive functions are collapsed into a single node (like foo in the above example). The full computation graph can be rendered using the collapse_primitives flag, setting it to False in the above example

...
dot_graph = jpviz.draw(bar, collapse_primitives=False)(jnp.arange(10))
...

produces

bar computation graph

Show Types

By default, type information is included in the node labels, this can be hidden using the show_avals flag, setting it to False

...
dot_graph = jpviz.draw(bar, show_avals=False)(jnp.arange(10))
...

produces

bar computation graph

NOTE: The labels of the nodes don't currently correspond to argument/variable names in the original Python code. Since JAX unpacks arguments/outputs to tuples they do correspond to the positioning of arguments and outputs.

Examples

See here for more examples of rendered computation graphs.

Developers

Developer notes can be found here.

Metadata

Release files for jpviz 0.1.7

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

Source distribution (sdist)

Source distribution for jpviz 0.1.7
File Size Uploaded Provenance Actions
jpviz-0.1.7.tar.gz 11.4 kB Without provenance Details for jpviz-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jpviz 0.1.7
File Interpreter ABI Platform Actions
jpviz-0.1.7-py3-none-any.whl Python 3 none any Details for jpviz-0.1.7-py3-none-any.whl

Total release size: 23.7 kB

Release files / jpviz-0.1.7.tar.gz

Download URL jpviz-0.1.7.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b4eefc11217d14a3a7167726bd1186681b2d9c4cd27e9dc1f386c91195a71b4f
BLAKE2b-256 checksum
How to use checksums
c3e2892dd192945d2ba75b0a0437a0b637d5bed701e925f427303d0fb5ff5db1
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 / jpviz-0.1.7-py3-none-any.whl

Download URL jpviz-0.1.7-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bec5935cd9e41fdc60a9daf0b4f50bb479906aa2205d012ee1a2efb5e02ebae
BLAKE2b-256 checksum
How to use checksums
8ba58489c2b5971f96f05f1228dfc95f2cd2aac5b6603152b8218d5a11e5b47d
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

Security for jpviz 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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