| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from vllm import LLM, SamplingParams |
| 7 | from vllm.platforms import current_platform |
| 8 | |
| 9 | from ....utils import create_new_process_for_each_test |
| 10 | |
| 11 | if current_platform.is_rocm(): |
| 12 | pytest.skip( |
| 13 | "Cascade attention backends FLASH_ATTN and FLASHINFER are notsupported on ROCm", |
| 14 | allow_module_level=True, |
| 15 | ) |
| 16 | |
| 17 | |
| 18 | @create_new_process_for_each_test() |
| 19 | @pytest.mark.parametrize("attn_backend", ["FLASH_ATTN", "FLASHINFER"]) |
| 20 | def test_cascade_attention(example_system_message, attn_backend): |
| 21 | prompt = "\n<User>: Implement fibonacci sequence in Python.\n<Claude>:" |
| 22 | |
| 23 | if attn_backend == "FLASHINFER": |
| 24 | pytest.skip( |
| 25 | "This test is failing with FlashInfer backend and " |
| 26 | "needs investigation. See issue #25679." |
| 27 | ) |
| 28 | |
| 29 | llm = LLM( |
| 30 | model="Qwen/Qwen2-1.5B-Instruct", attention_config={"backend": attn_backend} |
| 31 | ) |
| 32 | sampling_params = SamplingParams(temperature=0.0, max_tokens=100) |
| 33 | |
| 34 | # No cascade attention. |
| 35 | single_prompt = [example_system_message + prompt] |
| 36 | responses = llm.generate(single_prompt, sampling_params) |
| 37 | ref_output = responses[0].outputs[0].text |
| 38 | |
| 39 | # (Probably) Use cascade attention. |
| 40 | prompts = [example_system_message + prompt] * 64 |
| 41 | responses = llm.generate(prompts, sampling_params) |
| 42 | for response in responses: |
| 43 | assert response.outputs[0].text == ref_output |