espnet2.torch_utils.check_look_ahead.check_look_ahead
espnet2.torch_utils.check_look_ahead.check_look_ahead
espnet2.torch_utils.check_look_ahead.check_look_ahead(forward: Callable[[Tensor], object], inputs: Tensor, last_input: Callable[[int], int], cut_points: Iterable[int], time_dim: int = 1, atol: float = 0.0, tight: bool = True, tight_window: int = 1, seed: int = 0) → LookAheadCheck
Check that output frame i of forward reads no input after last_input(i).
For each cut point c, the inputs at positions c, c + 1, … on time_dim are replaced with random values, ten times the inputs’ standard deviation. Every output frame i with last_input(i) < c must change by at most atol. With tight=True, one of the first tight_window output frames with last_input(i) >= c must change by more than atol, which shows that the bound is reached and not only respected (use tight_window > 1 when the first such frame reads input c with a tiny weight, e.g. at the edge of a window).
- Parameters:
- forward – Maps an input like
inputsto the output (tensor or array). - inputs – Input with time on time_dim.
- last_input – Output frame index -> last input position it may read.
- cut_points – Input positions from which the input is changed.
- time_dim – The time dimension of the input and the output.
- atol – Largest change allowed for the frames that must not change.
- tight – Also require a change of the frames that may read the cut.
- tight_window – Number of such frames to look at for that change.
- seed – Seed of the replacement values.
- forward – Maps an input like
- Returns: The largest changes seen over all cut points.
- Raises:AssertionError – An output frame changes although last_input(i) < c, or (tight) none of the frames that may read the cut changes.
