Attention over the window

Window positions

×

For each query, the last 128 positions up to and including its own.

Jtw={max⁡(0, t−127),…,t}{\htmlData{light=window-allowed window-rows}{J^{w}_{t}}}=\{\max(0,\,t-127),\ldots,t\}
in
WW [B batch, T positions, 512 d_h]
out
JwJ^{w} [B batch, T positions, 128 window]

Causality is in this list: there is no mask tensor.

Sources

In codeget_window_topk_idxs(win, bsz, seqlen, start_pos) · 507

Open pinned code ↗

Direct evidence

The window lists, for each query, the positions from t − 127 to t (−1 where none); when decoding, the ring buffer’s slots.

model.py 254–265 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6

Excerpt
@lru_cache(1)
def get_window_topk_idxs(window_size: int, bsz: int, seqlen: int, start_pos: int):
    if start_pos >= window_size - 1:
        start_pos %= window_size
        matrix = torch.cat([torch.arange(start_pos + 1, window_size),  torch.arange(0, start_pos + 1)], dim=0)
    elif start_pos > 0:
        matrix = F.pad(torch.arange(start_pos + 1), (0, window_size - start_pos - 1), value=-1)
    else:
        base = torch.arange(seqlen).unsqueeze(1)
        matrix = (base - window_size + 1).clamp(0) + torch.arange(min(seqlen, window_size))
        matrix = torch.where(matrix > base, -1, matrix)
    return matrix.unsqueeze(0).expand(bsz, -1, -1)