Skip to main content

Additional pytree utilities for JAX

Project description

Jaxtree Extensions

jaxtree-extensions extends JAX's native jax.tree_util with extra tree utilities for JAX, Equinox, and other pytree frameworks.

Core Utilities

Function Description Comparison
tree_map_prune Map and filter leaves by predicate, collapsing containers. Similar to jax.tree_util.tree_map but drops/collapses leaves.
tree_select_by_path / tree_at_path Mask or edit nodes matching wildcard path strings (e.g. **/bias). Similar to equinox.tree_at but using glob/wildcard patterns.
tree_zip_mismatched Zip mismatched trees via intersection/padding and broadcast scalars. Extends jax.tree_util.tree_map to handle structure/shape mismatches.
tree_map_enumerate Map over a tree passing a sequential flat index to each leaf. Similar to jax.tree_util.tree_map but provides automatic indices 0, 1, 2...
tree_compare Compare two trees and generate a detailed mismatch diagnostic report. Similar to chex.assert_trees_all_close but returns a diagnostic TreeDiff.
tree_reduce_with_path Reduce a tree passing key-path tuples of each leaf. Extends jax.tree_util.tree_reduce with path-aware context.

Installation

Install the package via PyPI:

pip install jaxtree-extensions

Or install locally for development:

uv pip install -e .

Quick Start

import jaxtree_extensions as jte
import jax.numpy as jnp

# Pruning elements
pruned, _ = jte.tree_map_prune(lambda x: x, {"a": [1, 2], "b": 3}, keep_fn=lambda x: x > 1)
# pruned = {"a": [2], "b": 3}

# Path-based editing
model = {"layer1": {"bias": jnp.ones(2)}, "layer2": {"bias": jnp.ones(2)}}
zero_bias = jte.tree_at_path(model, "**/bias", replace=0.0)

Running Tests

To run the test suite:

uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jaxtree_extensions-0.2.0.tar.gz (117.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jaxtree_extensions-0.2.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file jaxtree_extensions-0.2.0.tar.gz.

File metadata

  • Download URL: jaxtree_extensions-0.2.0.tar.gz
  • Upload date:
  • Size: 117.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jaxtree_extensions-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a3281851594e635846f0d6ccbc859c18b944c43a142d72204cae94e50b6756d3
MD5 a9032eccf8e2cf9ac192de93faa3c513
BLAKE2b-256 08208e3ec3479ef3e4a90ccf8a678801fd2e80fa931835ae633353668b34fd2c

See more details on using hashes here.

File details

Details for the file jaxtree_extensions-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jaxtree_extensions-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jaxtree_extensions-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e5406e48f442135cbe1346aa742368a195fab13fb4f067010a81067b2d8a682
MD5 11ac3c121bc623c304dad75130686ed6
BLAKE2b-256 a88d3a484e500c1f0618cbf8d3ef999232fde2d8a248715e7c38f65e1ea949f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page