returnn.tensor.utils
¶
Some helper utils.
- returnn.tensor.utils.tensor_dict_fill_random_numpy_(tensor_dict: TensorDict, *, rnd: int | RandomState = 42, dyn_dim_max_sizes: Dict[Dim, int] | None = None, dyn_dim_min_sizes: Dict[Dim, int] | None = None)[source]¶
Random fill with NumPy arrays.
- Parameters:
tensor_dict
rnd
dyn_dim_max_sizes – you can specify max sizes for dim tags with dynamic sizes. The fill random code makes sure that there is at least one entry where we reach the max size, so that the dim value will be the max size.
dyn_dim_min_sizes
- returnn.tensor.utils.tensor_fill_random_numpy_(x: Tensor, *, min_val: int = 0, max_val: int | None = None, rnd: RandomState, dyn_dim_max_sizes: Dict[Dim, int] | None = None, dyn_dim_min_sizes: Dict[Dim, int] | None = None) bool [source]¶
fill. return whether sth was filled
- returnn.tensor.utils.tensor_dict_dims_random_seq_len_min_max(tensor_dict: TensorDict, seq_lens: None | int | Tuple[int, int] | Dict[str | Dim | None, int | Tuple[int, int]] = None) Tuple[List[Dim], Dict[Dim, Tuple[int, int]]] [source]¶
This is specifically intended to prepare the list of all dynamic dims from the tensor dict and the seq_len_min_max for
get_random_seq_lens_for_dyn_dims()
.- Parameters:
tensor_dict
seq_lens – either fixed seq len, or take randint. per data key, or per dim, or same for all
- Returns:
dims, seq_len_min_max
- returnn.tensor.utils.get_random_seq_lens_for_dyn_dims(dims: Sequence[Dim], seq_len_min_max: Dict[Dim, Tuple[int, int]], *, batch_size: int = 1, rnd: int | RandomState = 1337) Dict[Dim, ndarray] [source]¶
Make random seq lens for dims.
Note that dim tags are not actually modified here, as we need to have this in a safe way, which might run in parallel to the main thread.
- Parameters:
dims – Note that the order matter, as we use complete_dyn_size() (or equivalent).
seq_len_min_max
batch_size
rnd