Skip to main content

A library for key management in JAX.

Project description

randomix - Random Jax utilities

Miscellaneous things related to jax and random numbers.

For now, just the Keyer class.

(This package is an experiment with aider, uv, and what it takes to ship a pypi package)

Version

0.1.1

New Typed Keys

The new typed keys in JAX are represented as scalar arrays with a special RNG dtype that satisfies jnp.issubdtype(key.dtype, jax.dtypes.prng_key). This library ensures that the keys are of the new typed format and provides methods to split them into sub-keys based on a given shape.

For more information on the new typed keys, see the JAX documentation: https://docs.jax.dev/en/latest/jep/9263-typed-keys.html#notes-for-jax-library-authors

Keyer

The randomix.Keyer class handles jax.random.PRNGKey state storage within a single jit context.

Similar to e.g. treex.KeySeq but slightly more convenient API. (I've seen this basic concept in other places as well).

Usage:

    key = jax.random.key(42)  # Create a PRNG key through the new Jax API

    keyer = randomix.Keyer(key)

    other_key = keyer()  # Split a new key, update key held inside keyer

    more_keys = keyer((3, 2))  # Get keys with a shape

Note that you should not pass a keyer around jit borders or vmap lambdas or anything like that; just pass the split keys.

Open question: would it be convenient to just mirror all the jax.random methods that take key as an argument to this class?

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

randomix-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

randomix-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file randomix-0.1.1.tar.gz.

File metadata

  • Download URL: randomix-0.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for randomix-0.1.1.tar.gz
Algorithm Hash digest
SHA256 76efbad21e6a4961d66b2f686a8b5aa91741eeb2f8f102bb4a97d535d36e03c6
MD5 7fc113a90849be1dc530a65875dca74c
BLAKE2b-256 1cda05733265e9052f436ed09e816e5208ba4e051816dca0aeb70f5073c0c965

See more details on using hashes here.

Provenance

The following attestation bundles were made for randomix-0.1.1.tar.gz:

Publisher: publish-to-pypi.yml on tjltjl/randomix

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

File details

Details for the file randomix-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: randomix-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for randomix-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c49c40ffb33d8e237a29db4de2771ec4ea9e65e30668575eaa99157b650bdfa1
MD5 795a08342896b648d946c415d2e08d1c
BLAKE2b-256 fa1f8c9f4c94ac0e3ffb53a6ec40a690415b39b43a87af65513674e4979e8dfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for randomix-0.1.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on tjltjl/randomix

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