tfp.random.sanitize_seed  |  TensorFlow Probability (original) (raw)

tfp.random.sanitize_seed

Stay organized with collections Save and categorize content based on your preferences.

Map various PRNG seed flavors to a seed Tensor.

tfp.random.sanitize_seed(
    seed, salt=None, name=None
)

Used in the notebooks

Used in the tutorials
TFP Release Notes notebook (0.13.0)

This function implements TFP's standard PRNG seeding semantics. See https://github.com/tensorflow/probability/blob/main/PRNGS.mdfor details.

Operationally, sanitize_seed maps any seed flavor to a "stateless-compatible" seed. Under TensorFlow and NumPy this means:

Under JAX, this function only accepts outputs from jax.random.PRNGKey, being a no-op except for the salting behavior described below.

This, any function that accepts a seed argument can be written in stateless-seed style internally, and acquires TFP's seed-type-directed stateless/stateful switching behavior by just running the input seed through sanitize_seed on entry.

The sanitize_seed function also allows salting the seed: if a user accidentally passes the same stateful seed to two different calls tosanitize_seed with different salts, they will get independent randomness. We may micro-optimize by removing salting fromsanitize_seed of already-stateless seeds in the future, as using a stateless seed already requires seed uniqueness discipline.

Args
seed An int32[2] Tensor or a Python list or tuple of 2 ints, which will be treated as stateless seeds; or a Python int orNone, which will be treated as stateful seeds.
salt An optional Python string.
name An optional Python string, name to add to TF ops created by this function.
Returns
seed An int32[2] Tensor suitable for use as a stateless PRNG seed.