Skip to content

← random package

DrawRandomSeed

Draw a random seed from the currently sequence of deterministic random seeds, if one is set.

This seed can be passed into a random operation to ensure that the operation will yield deterministic results (i.e., the same results for every run of the program). This node can only be used in a context where such a sequence has been set, which can be done by putting a WithRandomSeed node at the end of the computation/graph, which acts as a context manager. Version 0.5.0

Ports/Properties

key

Splittable random seed.

  • verbose name: Key
  • default value: None
  • port type: DataPort
  • value type: AnyArray (can be None)
  • data direction: OUT

num

Number of seeds to draw. If more than one is drawn, keys will be a correspondingly larger array.

  • verbose name: Number Of Seeds
  • default value: 1
  • port type: IntPort
  • value type: int (can be None)

from_context

Ambient context from which to draw the random seed. The auto mode will attempt to use first the deep learning context, then the Bayesian context, and finally the WithRandomSeed context. If set to WithRandomSeed, the next random seed provided by the nearest enclosing WithRandomSeed node is used. If set to deep learning, the seed provided by the nearest enclosing deep-learning context (usually DeepModel, but can also be NetTransform) is used. If set to bayes, the seed provided by the nearest enclosing Bayesian inference context is used (usually one of the Inference nodes).

  • verbose name: From Context
  • default value: auto
  • port type: EnumPort
  • value type: str (can be None)

backend

Optional compute backend for which to generate the seed. Keep is the current default, which is typically numpy, but which can be overridden in contexts that require it. Some backends (notably jax and tensorflow) require that the seed be generated using the same backend as the downstream random operation. For this reason, it is a good idea to use the same backend for both the seed management and the random operation to future-proof one's pipeline.

  • verbose name: Backend
  • default value: keep
  • port type: EnumPort
  • value type: str (can be None)

from_haiku_context

Legacy option, use from_context instead.

  • verbose name: From Haiku Context
  • default value: None
  • port type: AliasPort
  • value type: str (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)