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)

Keyer

The randomix.Keyer class handles jax.random.PRNGKey state storage within a single jit context and makes it easy to split off either single new keys or arrays of keys from the contained key.

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?

Note: 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

Version

0.1.1

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.2.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.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: randomix-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 d3bf8b0de87c086a2b728e45166b7b21111b87e2e65af63730ca36b961b290fb
MD5 6a05b58fc5998db3fd35ac69d86384c3
BLAKE2b-256 22e2bac555a90e415dab6099fec90f5d96b69ee097d7148cc95bab7ab73c23d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for randomix-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: randomix-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc2aed0f123a42a03e2863a7edb6423a17187d9e88f9d48dc1f3be967cf5563
MD5 3980207af6cab8d65337810e19a9abb8
BLAKE2b-256 082a624ec8367a4a7668ad43d02fe9572f1ceb12f96962e73f6f740b734a478c

See more details on using hashes here.

Provenance

The following attestation bundles were made for randomix-0.1.2-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