|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | + |
| 4 | +import json |
| 5 | +import os |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from tests.utils import RemoteOpenAIServer |
| 10 | +from vllm.platforms import current_platform |
| 11 | + |
| 12 | +if not current_platform.is_device_capability(100): |
| 13 | + pytest.skip("This test only runs on Blackwell GPUs (SM100).", |
| 14 | + allow_module_level=True) |
| 15 | + |
| 16 | +os.environ["FLASHINFER_NVCC_THREADS"] = "16" |
| 17 | + |
| 18 | +# dummy_hf_overrides = {"num_layers": 4, "num_hidden_layers": 4, |
| 19 | +# "text_config": {"num_layers": 4, "num_hidden_layers": 4}} |
| 20 | +dummy_hf_overrides = {"num_layers": 4, "num_hidden_layers": 4} |
| 21 | + |
| 22 | + |
| 23 | +def can_initialize(model: str, extra_args: list[str]): |
| 24 | + |
| 25 | + # Server arguments |
| 26 | + server_args = [ |
| 27 | + "--max-model-len", |
| 28 | + "2048", |
| 29 | + "--max-num-batched-tokens", |
| 30 | + "256", |
| 31 | + "--load-format", |
| 32 | + "dummy", |
| 33 | + "--trust-remote-code", |
| 34 | + "--limit-mm-per-prompt", |
| 35 | + json.dumps({"image": 0}), |
| 36 | + *extra_args, |
| 37 | + ] |
| 38 | + |
| 39 | + # Launch server and make a simple request |
| 40 | + with RemoteOpenAIServer( |
| 41 | + model, |
| 42 | + server_args, |
| 43 | + max_wait_seconds=1000, # Due to FlashInfer compile |
| 44 | + override_hf_configs=dummy_hf_overrides) as server: |
| 45 | + client = server.get_client() |
| 46 | + # Make a simple request to verify the server works |
| 47 | + completion = client.completions.create( |
| 48 | + model=model, |
| 49 | + prompt=["Hello, World!"], |
| 50 | + temperature=0, |
| 51 | + max_tokens=2, |
| 52 | + ) |
| 53 | + print(completion) |
| 54 | + assert completion.choices[0].text is not None |
| 55 | + |
| 56 | + |
| 57 | +## Llama4 ## |
| 58 | + |
| 59 | + |
| 60 | +@pytest.mark.skip(reason=( |
| 61 | + "RuntimeError: run_moe() Expected a value of type " |
| 62 | + "'Optional[List[Tensor]]' for argument '_9' but instead found type " |
| 63 | + "'list'.")) |
| 64 | +def test_llama4_fp8_tensor_moe_flashinfer_cutlass( |
| 65 | + monkeypatch: pytest.MonkeyPatch): |
| 66 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_FP8", "1") |
| 67 | + monkeypatch.setenv("VLLM_FLASHINFER_MOE_BACKEND", "throughput") |
| 68 | + can_initialize("nvidia/Llama-4-Scout-17B-16E-Instruct-FP8", []) |
| 69 | + |
| 70 | + |
| 71 | +@pytest.mark.skip(reason="Works, but takes too long to run") |
| 72 | +def test_llama4_fp8_tensor_moe_flashinfer_trtllm( |
| 73 | + monkeypatch: pytest.MonkeyPatch): |
| 74 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_FP8", "1") |
| 75 | + monkeypatch.setenv("VLLM_FLASHINFER_MOE_BACKEND", "latency") |
| 76 | + can_initialize("nvidia/Llama-4-Scout-17B-16E-Instruct-FP8", []) |
| 77 | + |
| 78 | + |
| 79 | +@pytest.mark.skip(reason="Works, but takes too long to run") |
| 80 | +def test_llama4_nvfp4_moe_flashinfer_cutlass(monkeypatch: pytest.MonkeyPatch): |
| 81 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_FP4", "1") |
| 82 | + monkeypatch.setenv("VLLM_FLASHINFER_MOE_BACKEND", "throughput") |
| 83 | + can_initialize("nvidia/Llama-4-Scout-17B-16E-Instruct-FP4", []) |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.skip(reason="RuntimeError: No kernel found for the given options") |
| 87 | +def test_llama4_nvfp4_moe_flashinfer_trtllm(monkeypatch: pytest.MonkeyPatch): |
| 88 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_FP4", "1") |
| 89 | + monkeypatch.setenv("VLLM_FLASHINFER_MOE_BACKEND", "latency") |
| 90 | + can_initialize("nvidia/Llama-4-Scout-17B-16E-Instruct-FP4", []) |
| 91 | + |
| 92 | + |
| 93 | +## DeepSeekV3 ## |
| 94 | + |
| 95 | + |
| 96 | +def test_deepseek_fp8_block_moe_deep_gemm(monkeypatch: pytest.MonkeyPatch): |
| 97 | + monkeypatch.setenv("VLLM_USE_DEEP_GEMM", "1") |
| 98 | + can_initialize("deepseek-ai/DeepSeek-V3.1", []) |
| 99 | + |
| 100 | + |
| 101 | +def test_deepseek_nvfp4_moe_flashinfer_cutlass( |
| 102 | + monkeypatch: pytest.MonkeyPatch): |
| 103 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_FP4", "1") |
| 104 | + monkeypatch.setenv("VLLM_FLASHINFER_MOE_BACKEND", "throughput") |
| 105 | + can_initialize("nvidia/DeepSeek-R1-0528-FP4-v2", []) |
| 106 | + |
| 107 | + |
| 108 | +@pytest.mark.skip(reason="RuntimeError: No kernel found for the given options") |
| 109 | +def test_deepseek_nvfp4_moe_flashinfer_trtllm(monkeypatch: pytest.MonkeyPatch): |
| 110 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_FP4", "1") |
| 111 | + monkeypatch.setenv("VLLM_FLASHINFER_MOE_BACKEND", "latency") |
| 112 | + can_initialize("nvidia/DeepSeek-R1-0528-FP4-v2", []) |
| 113 | + |
| 114 | + |
| 115 | +## GPT-OSS ## |
| 116 | + |
| 117 | + |
| 118 | +def test_gptoss_mxfp4bf16_moe_flashinfer(monkeypatch: pytest.MonkeyPatch): |
| 119 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_MXFP4_BF16", "1") |
| 120 | + can_initialize("openai/gpt-oss-20b", []) |
| 121 | + |
| 122 | + |
| 123 | +def test_gptoss_mxfp4mxfp8_moe_flashinfer_cutlass( |
| 124 | + monkeypatch: pytest.MonkeyPatch): |
| 125 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_MXFP4_MXFP8_CUTLASS", "1") |
| 126 | + can_initialize("openai/gpt-oss-20b", []) |
| 127 | + |
| 128 | + |
| 129 | +def test_gptoss_mxfp4mxfp8_moe_flashinfer_trtllm( |
| 130 | + monkeypatch: pytest.MonkeyPatch): |
| 131 | + monkeypatch.setenv("VLLM_USE_FLASHINFER_MOE_MXFP4_MXFP8", "1") |
| 132 | + can_initialize("openai/gpt-oss-20b", []) |
0 commit comments