main
py 53 lines 1.43 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import pytest
5 import torch
6
7 from vllm.platforms import current_platform
8
9 if current_platform.is_rocm():
10 pytest.skip(
11 reason="FlashInfer GDN prefill is not supported on ROCm.",
12 allow_module_level=True,
13 )
14
15 import flashinfer.gdn_prefill # noqa: E402
16
17 from vllm.model_executor.layers.mamba.gdn.qwen_gdn_linear_attn import (
18 fi_chunk_gated_delta_rule,
19 ) # noqa: E402
20
21
22 def test_flashinfer_gdn_prefill_uses_int64_cu_seqlens(monkeypatch):
23 captured_cu_seqlens = None
24
25 def fake_chunk_gated_delta_rule(**kwargs):
26 nonlocal captured_cu_seqlens
27 captured_cu_seqlens = kwargs["cu_seqlens"]
28 return kwargs["q"]
29
30 monkeypatch.setattr(
31 flashinfer.gdn_prefill,
32 "chunk_gated_delta_rule",
33 fake_chunk_gated_delta_rule,
34 )
35 q = torch.zeros(1, 2, 1, 2)
36 cu_seqlens = torch.tensor([0, 2], dtype=torch.int32)
37
38 output, final_state = fi_chunk_gated_delta_rule(
39 q=q,
40 k=q,
41 v=q,
42 g=torch.zeros(1, 2, 1),
43 beta=torch.zeros(1, 2, 1),
44 initial_state=torch.zeros(1, 1, 2, 2),
45 output_final_state=False,
46 cu_seqlens=cu_seqlens,
47 use_qk_l2norm_in_kernel=False,
48 )
49
50 assert captured_cu_seqlens is not None
51 assert captured_cu_seqlens.dtype == torch.int64
52 assert output.shape == q.shape
53 assert final_state is None