segment_causal_mask_from_is_init#
- class torchrl.modules.segment_causal_mask_from_is_init(is_init: Tensor)[source]#
Build a block-diagonal causal attention mask from
is_initflags.Entry
[..., i, j]isTrue(attend) iffj <= iand stepsiandjbelong to the same episode segment, so attention never crosses an episode boundary within a training window.- Parameters:
is_init (torch.Tensor) – a boolean tensor of shape
[*batch, T]marking the first step of each episode.- Returns:
A boolean tensor of shape
[*batch, T, T]whereTruemeans “may attend”.
Examples
>>> is_init = torch.tensor([[False, True]]) >>> segment_causal_mask_from_is_init(is_init) tensor([[[ True, False], [False, True]]])