Fine-grained, dynamic control of neural network topology in JAX.
Project description
Connex
Connex is a JAX library built on Equinox for trainable neural networks whose topology is defined by a directed acyclic graph.
With Connex, you can:
- compile a DAG into a trainable Equinox module;
- compose built-in or user-defined graph operations;
- add and remove connections or neurons while preserving compatible parameters;
- set scalar or per-node dropout with explicit JAX random keys;
- use padded, sparse, matmul, or hybrid affine backends;
- export trained parameters to a NetworkX weighted digraph.
Installation
pip install connex
Quickstart
import connex as cnx
import jax
import jax.numpy as jnp
import jax.random as jr
graph = {
0: [1, 2, 3],
1: [4],
2: [4, 5],
4: [6],
5: [7],
6: [8, 9],
7: [10],
8: [11],
9: [11],
10: [11],
}
spec = cnx.GraphSpec(graph, inputs=[0], outputs=[3, 11])
model = cnx.NeuralDAG(
spec,
ops=cnx.ops.default_ops(activation=jax.nn.relu),
key=jr.key(0),
)
y = model(jnp.array([1.0]))
GraphSpec validates the DAG and preserves input/output ordering. NeuralDAG
is an equinox.Module, so training uses standard Equinox and Optax patterns:
import equinox as eqx
import optax
optim = optax.adam(1e-3)
opt_state = optim.init(eqx.filter(model, eqx.is_array))
@eqx.filter_value_and_grad
def loss_fn(model, x, y):
pred = model.batched(x)
return jnp.mean((pred - y) ** 2)
Topology edits go through the editor API. Edits return a new model and leave the old one untouched:
model = (
cnx.edit(model)
.add_edges([(1, 6), (2, 11)])
.remove_nodes([9])
.set_dropout(0.1)
.build(key=jr.key(2))
)
The default affine backend is hybrid: each topological batch chooses padded
rows, sparse edge accumulation, or dense matmul based on graph structure. Long
one-input chain segments use an automatic jax.lax.scan execution plan when the
operation stack supports it.
Custom operations subclass connex.ops.Op and participate in the same pipeline:
class MyOp(cnx.ops.Op):
def apply(self, ctx, *, state=None, key=None):
...
Prebuilt graph constructors are available under connex.nn:
model = cnx.nn.MLP(2, 1, width=32, depth=3, key=jr.key(0))
Documentation
Full documentation lives at:
https://leonard-gleyzer.github.io/connex
Citation
@software{gleyzer2023connex,
author = {Leonard Gleyzer},
title = {{C}onnex: Fine-grained Control over Neural Network Topology in {JAX}},
url = {http://github.com/leonard-gleyzer/connex},
year = {2023},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file connex-0.4.0.tar.gz.
File metadata
- Download URL: connex-0.4.0.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97d8cad70f3b1fb861512868888b09a1f9a8857825b3c6510611dbeb0fc4bd49
|
|
| MD5 |
72562f3171e7cbbcb5d7c7321f4d9336
|
|
| BLAKE2b-256 |
a9f4ded4da27ad2e991d6aca58d13f8726e78612b3e3226763f560d7d048ef5b
|
File details
Details for the file connex-0.4.0-py3-none-any.whl.
File metadata
- Download URL: connex-0.4.0-py3-none-any.whl
- Upload date:
- Size: 36.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e23ab7c9a511c69eb39d68049229e2317720568f99fbc6ef4ba205321ee8ef73
|
|
| MD5 |
38ebbf58a553ccfc9002f4f5f367844f
|
|
| BLAKE2b-256 |
d654b738d3986ac751371be0ac0ce67ac3db1f7a89ebe9748dd4c3d7ddbb8592
|