jax.experimental.key_reuse module
Contents
jax.experimental.key_reuse module#
Experimental Key Reuse Checking#
This module containsexperimental functionality for detecting reuse of randomkeys within JAX programs. It is under active development and the APIs here arelikely to change. The usage below requires JAX version 0.4.26 or newer.
Key reuse checking can be enabled using thejax_debug_key_reuse configuration.This can be set globally using:
>>>jax.config.update('jax_debug_key_reuse',True)
Or it can be enabled locally with thejax.debug_key_reuse() context manager.When enabled, using the same key twice will result in aKeyReuseError:
>>>importjax>>>withjax.debug_key_reuse(True):...key=jax.random.key(0)...val1=jax.random.normal(key)...val2=jax.random.normal(key)Traceback (most recent call last):...KeyReuseError:Previously-consumed key passed to jit-compiled function at index 0
The key reuse checker is currently experimental, but in the future we will likelyenable it by default.
Contents
