|View source on GitHub|
Map various PRNG seed flavors to a seed
tfp.substrates.jax.random.sanitize_seed( seed, salt=None, name=None )
This function implements TFP's standard PRNG seeding semantics. See https://github.com/tensorflow/probability/blob/master/PRNGS.md for details.
sanitize_seed maps any seed flavor to a
"stateless-compatible" seed, namely a
int32 Tensor. To wit:
- If the
seedargument is an
None, we use
tf.random.stateless_uniformto statefully draw a pair of unbounded
int32s and wrap them into a Tensor.
- If the
seedargument is a stateless-compatible seed already, we just cast it to an
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.
sanitize_seed function also allows salting the seed: if a user
accidentally passes the same stateful seed to two different calls to
sanitize_seed with different salts, they will get independent
randomness. We may micro-optimize by removing salting from
sanitize_seed of already-stateless seeds in the future, as using a
stateless seed already requires seed uniqueness discipline.
||An optional Python string.|
||An optional Python string, name to add to TF ops created by this function.|