🏗️ Synecdoche
HyperNetworks and compressed weight representations for JAX / Flax NNX.
Synecdoche (si-NEK-duh-kee) is the figure of speech in which a part stands in for the whole — "all hands on deck." Fittingly, this library lets a small, easy-to- manipulate set of parameters stand in for all the weights of a much larger network: you train or evolve the part, and it generates the whole.
import synecdoche as syn
from flax import nnx
model = nnx.Linear(256, 256, rngs=nnx.Rngs(0)) # 65 792 parameters
target = nnx.state(model, nnx.Param) # the template
hyper = syn.DCT(target, embedding_dim=32, rngs=nnx.Rngs(1))
syn.apply_to(model, hyper) # model now runs on generated weights
print(syn.compression_ratio(hyper, model)) # a much smaller description
Why
A hypernetwork replaces a network's weights with a generator. That buys you three things:
- Compression — describe many weights with few numbers.
- Structure / inductive bias — the generator constrains what kinds of weight matrices are reachable (smooth, low-rank, tied, …).
- Tractable search — evolution strategies and other black-box optimisers have variance that grows with the number of parameters, so they don't scale to full networks. Move the search into the hypernetwork's small latent space and they become viable again. (This is why synecdoche pairs naturally with spiking / non-differentiable networks trained by evolution.)
Everything is a plain flax.nnx.Module, so generated weights drop into any NNX
model, and the generator's parameters train by gradient or evolve by ES.
Generators
Build any of these from a target's nnx.state(model, nnx.Param); call it to get a
matching weight pytree.
| Generator | Idea | Learnable params |
|---|---|---|
RandomProjection |
fixed random basis · learnable embeddings (random-feature indirect encoding) | num_layers × embedding_dim |
DCT |
inverse-DCT of a few low-frequency coefficients — compressed weight search (Koutník, Gomez & Schmidhuber, 2010) | num_layers × embedding_dim |
LowRank |
left @ right factorisation of the stacked weights |
rank × (num_layers + max_size) |
MLPHyper |
a shared MLP decodes per-layer embeddings (Ha, Dai & Le, HyperNetworks, 2016) | embeddings + MLP |
experimental.DynamicHypernetwork |
weights conditioned on the input batch (fast-weights / meta-learning) | embeddings + MLP |
RandomProjection and DCT are the strong compressors; LowRank / MLPHyper are
more expressive but compress only when the target's layers are large relative to
their number (the generators pad to the largest layer — see the docstrings).
Training the compressed representation
Inside nnx.jit / nnx.grad / an ES loop, don't mutate the target model in place —
rebuild it functionally from generated weights with syn.functional:
apply = syn.functional(model) # capture structure once
def loss_fn(hyper):
return mse(apply(hyper, X), Y) # forward on generated weights
opt = nnx.Optimizer(hyper, optax.adam(3e-3), wrt=nnx.Param)
loss, grads = nnx.value_and_grad(loss_fn)(hyper) # grads w.r.t. the hypernetwork
opt.update(hyper, grads)
See examples/compress_and_train.py for a runnable
end-to-end fit (16× compression, trains to convergence).
Lazy weights (optional, via quax)
pip install synecdoche[quax] adds synecdoche.lazy: weights that keep their
compressed form all the way into the computation and never materialise in full,
using quax's multiple dispatch. A low-rank weight computes x @ (a @ b) as
(x @ a) @ b — the full matrix is never formed.
import quax, synecdoche.lazy as sl
w = sl.LowRankWeight.init((1024, 1024), rank=8, rngs=nnx.Rngs(0)) # 8·2048 params, not 1M
y = quax.quaxify(lambda W, x: x @ W)(w, x) # never forms 1024×1024
Install
pip install synecdoche # core (jax + flax)
pip install synecdoche[quax] # + lazy never-materialised weights
Roadmap
- Generative weight generators — sampling weights from a learned distribution (diffusion / VAE over checkpoints, after Neural Network Diffusion and G.pt), the stochastic counterpart to the deterministic generators here.
- Per-layer output heads so
LowRank/MLPHypercompress heterogeneous architectures without the pad-to-max-size overhead. - First-class
spyxadapter for evolving spiking networks in the compressed space.
References
- Koutník, Gomez & Schmidhuber. Evolving neural networks in compressed weight space. GECCO 2010.
- Ha, Dai & Le. HyperNetworks. ICLR 2017.
- Kidger et al. quax — JAX + multiple dispatch for custom array types.
Metadata
Release files for synecdoche 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| synecdoche-0.2.0.tar.gz | 11.4 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| synecdoche-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.3 kB
Release files / synecdoche-0.2.0.tar.gz
| Download URL | synecdoche-0.2.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8602c7cab7899d0c8909ca3891fcebcd9481b26cfa44db8612adede9ff9a4b0
|
|
BLAKE2b-256 checksum How to use checksums |
37df40f4934028e7c75fa19e629545bb42ae4c5fd262134c6619088019d1273b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 6, 2026.
Transparency logRelease files / synecdoche-0.2.0-py3-none-any.whl
| Download URL | synecdoche-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c747a4cb6d23f2315cb81152673a72af82872e908bb4a2a2ed4be262088cb30
|
|
BLAKE2b-256 checksum How to use checksums |
15136fd68229398bd47af9637b4acb93e17becac8163d22a4938955b67d35fc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 6, 2026.
Transparency logSecurity for synecdoche 0.2.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for synecdoche-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 6, 2026.
Transparency logA 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.