Skip to main content

copy-and-mutate for Equinox modules: a context manager for ergonomic, in-place-feeling edits of frozen Equinox modules.

Project description

eqx-cam

Copy-and-mutate for Equinox modules.

An Equinox port of copy_and_mutate from jax_dataclasses by Brent Yi. See Attribution.

Equinox modules are frozen dataclasses. Editing a deeply nested field normally means threading replacement values back out through eqx.tree_at (or nested dataclasses.replace) calls. copy_and_mutate can often be more convenient. It just yields a temporarily mutable copy so you can just change whatever you need and get back your eqx.Module.

import jax
import equinox as eqx
from eqx_cam import copy_and_mutate

model = eqx.nn.MLP(2, 2, 8, 2, key=jax.random.key(0))

with copy_and_mutate(model) as m:
    m.layers[0].weight = m.layers[0].weight.at[0, 0].set(1.0)

# `model` is unchanged; `m` is a normal frozen Equinox module.

Attribution

This package is an independent reimplementation of the copy_and_mutate context manager from jax_dataclasses by Brent Yi, adapted to target equinox.Module rather than jax_dataclasses pytree dataclasses. The idea of temporarily unfreezing a pytree came directly from that project.

Development

uv sync           # install with dev dependencies
uv run pytest     # run the test suite
uv run ruff check # lint

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

eqx_cam-0.1.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

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

eqx_cam-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file eqx_cam-0.1.0.tar.gz.

File metadata

  • Download URL: eqx_cam-0.1.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for eqx_cam-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ddae36113bafc3caa1a2b7227d9e9d09d643adbfa380b35bc118c66646afe93e
MD5 e166b4f1f17936843ae70fdec1975cb8
BLAKE2b-256 c27856c54866fab60e1468d500ceee4db10da668a9c3dcf686822fbad482815b

See more details on using hashes here.

Provenance

The following attestation bundles were made for eqx_cam-0.1.0.tar.gz:

Publisher: publish.yml on mishmish66/eqx-cam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file eqx_cam-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: eqx_cam-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for eqx_cam-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 440604dd00b85219f5597df63009a3118cbd6d13ff9694e97170ec0b7eb2671d
MD5 8cc8207dcee4a746cf76638cdf72ca15
BLAKE2b-256 a3c46f2580a8d771b095b8e4850b6f53785114fa7ffc465ffb63ffe1397c5430

See more details on using hashes here.

Provenance

The following attestation bundles were made for eqx_cam-0.1.0-py3-none-any.whl:

Publisher: publish.yml on mishmish66/eqx-cam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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