test_cascade_attention.py 1.34 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
5
import pytest

6
7
from vllm import LLM, SamplingParams

8
from ...utils import create_new_process_for_each_test
9

10

11
@create_new_process_for_each_test()
12
@pytest.mark.parametrize("attn_backend", ["FLASH_ATTN", "FLASHINFER"])
13
def test_cascade_attention(example_system_message, monkeypatch, attn_backend):
14
15
    prompt = "\n<User>: Implement fibonacci sequence in Python.\n<Claude>:"

16
17
18
19
    if attn_backend == "FLASHINFER":
        pytest.skip("This test is failing with FlashInfer backend and "
                    "needs investigation. See issue #25679.")

20
21
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_V1", "1")
22
        m.setenv("VLLM_ATTENTION_BACKEND", attn_backend)
23
24
25
26
27
28
29
30
31
32
33
34
35
36

        llm = LLM(model="Qwen/Qwen2-1.5B-Instruct")
        sampling_params = SamplingParams(temperature=0.0, max_tokens=100)

        # No cascade attention.
        single_prompt = [example_system_message + prompt]
        responses = llm.generate(single_prompt, sampling_params)
        ref_output = responses[0].outputs[0].text

        # (Probably) Use cascade attention.
        prompts = [example_system_message + prompt] * 64
        responses = llm.generate(prompts, sampling_params)
        for response in responses:
            assert response.outputs[0].text == ref_output