Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions python/sglang/srt/layers/attention/flashinfer_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1931,11 +1931,18 @@ def update_sliding_window(
fixed_split_size=fixed_split_size,
multi_item_params=multi_item_params,
cross_attention_custom_mask=swa_paged_custom_mask,
# paged-only SWA path only; ragged keeps its custom prefix
# mask, spec-verify keeps its tree mask
# Paged-only SWA path. DFlash verify is a linear block without a
# tree mask, so its layer still needs the kernel's moving window.
window_left=(
sliding_window_size
if (wrapper_id == 0 and not use_ragged and spec_info is None)
if (
wrapper_id == 0
and not use_ragged
and (
spec_info is None
or spec_info.spec_input_type == SpecInputType.DFLASH_VERIFY
)
)
else -1
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def _make_flashinfer_dflash_swa_builtin_masks(
*,
device: str,
) -> list[torch.Tensor]:
"""Mirror FlashInfer DFLASH verify's production no-custom-mask path."""
"""Each query sees the sliding window ending at its own position, so the
window is per query and not per request."""
draft_token_num = _check_target_verify_case(case)
window = int(case.sliding_window_size)
masks_by_req = []
Expand All @@ -276,9 +277,10 @@ def _make_flashinfer_dflash_swa_builtin_masks(
).unsqueeze(1)
for prefix_len in case.prefix_lens:
seq_len = prefix_len + draft_token_num
prefix_start = max(0, int(prefix_len) - window)
k_idx = torch.arange(seq_len, dtype=torch.int32, device=device).unsqueeze(0)
masks_by_req.append((k_idx >= prefix_start) & (k_idx <= prefix_len + q_idx))
q_pos = int(prefix_len) + q_idx
lower = torch.clamp(q_pos - window, min=0)
masks_by_req.append((k_idx >= lower) & (k_idx <= q_pos))

return masks_by_req

Expand Down
Loading