returnn.frontend._random_journal

Utilities to record and playback calls to random. This is useful to be able to compare different backends even when they use random numbers.

It assumes that the order of random calls is deterministic and consistent between backends.

The logic becomes more complex when control flow is involved like conditionals or loops. We are also storing the control flow context in the journal.

class returnn.frontend._random_journal.RandomJournal[source]

random journal. see module docstring

append(*, distribution: str, mean: int | float | Tensor | None = None, stddev: int | float | Tensor | None = None, bound: int | float | Tensor | None = None, minval: int | float | Tensor | None = None, maxval: int | float | Tensor | None = None, seed: int | Sequence[int] | ndarray | None = None, static: bool | None = None, out: Tensor[ndarray] | None)[source]
get_next(*, new_out_template: Tensor | None = None) RandomJournalEntry[source]

read next

reached_end() bool[source]

reached end

add_graph_reader_node(out)[source]

In graph mode, if reading (get_next), at cgraph construction time, register that we are reading from the journal now in the current context. This is used in get_recent_graph_reader_node_in_accessible_ctx().

get_graph_reader_idx() int[source]

current index

get_recent_graph_reader_node_in_accessible_ctx() Tensor | None[source]

From the graph reader nodes, return the most recent one which is in an accessible context. Accessible context means either the same, or a parent context.

class returnn.frontend._random_journal.RandomJournalEntry(out: Tensor[ndarray] | None, control_flow_ctx: ControlFlowContext | None, run_ctx: RunCtx, distribution: str, mean: int | float | Tensor | None = None, stddev: int | float | Tensor | None = None, bound: int | float | Tensor | None = None, minval: int | float | Tensor | None = None, maxval: int | float | Tensor | None = None, seed: int | Sequence[int] | ndarray | None = None, static: bool | None = None)[source]

entry

out: Tensor[ndarray] | None[source]
control_flow_ctx: ControlFlowContext | None[source]
run_ctx: RunCtx[source]
distribution: str[source]
mean: int | float | Tensor | None = None[source]
stddev: int | float | Tensor | None = None[source]
bound: int | float | Tensor | None = None[source]
minval: int | float | Tensor | None = None[source]
maxval: int | float | Tensor | None = None[source]
seed: int | Sequence[int] | ndarray | None = None[source]
static: bool | None = None[source]