|
| 1 | +"""Tests which cover integration of the speculative decoding framework with |
| 2 | +tensor parallelism. |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | +import torch |
| 7 | + |
| 8 | +from vllm.utils import is_hip |
| 9 | + |
| 10 | +from .conftest import run_greedy_equality_correctness_test |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.skipif(torch.cuda.device_count() < 2, |
| 14 | + reason="Need at least 2 GPUs to run the test.") |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "common_llm_kwargs", |
| 17 | + [{ |
| 18 | + "model": "JackFram/llama-68m", |
| 19 | +
|
| 20 | + # Skip cuda graph recording for fast test. |
| 21 | + "enforce_eager": True, |
| 22 | +
|
| 23 | + # Required for spec decode. |
| 24 | + "use_v2_block_manager": True, |
| 25 | + "tensor_parallel_size": 2, |
| 26 | +
|
| 27 | + # Use AsyncLLM engine, so that the engine runs in its own process. |
| 28 | + # Otherwise, since vLLM does not follow true SPMD, the test runner |
| 29 | + # process will have both the engine and the rank0 worker. NCCL is not |
| 30 | + # cleaned up properly, and its server host thread leaks, causing the |
| 31 | + # second run of the test to fail with internal NCCL error. |
| 32 | + "use_async": True, |
| 33 | + }]) |
| 34 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 35 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 36 | +@pytest.mark.parametrize("test_llm_kwargs", [ |
| 37 | + { |
| 38 | + "speculative_model": "JackFram/llama-68m", |
| 39 | + "num_speculative_tokens": 3, |
| 40 | + }, |
| 41 | + { |
| 42 | + "speculative_model": "[ngram]", |
| 43 | + "num_speculative_tokens": 5, |
| 44 | + "ngram_prompt_lookup_max": 3, |
| 45 | + }, |
| 46 | +]) |
| 47 | +@pytest.mark.parametrize("batch_size", [2]) |
| 48 | +@pytest.mark.parametrize( |
| 49 | + "output_len", |
| 50 | + [ |
| 51 | + # Use smaller output len for fast test. |
| 52 | + 32, |
| 53 | + ]) |
| 54 | +@pytest.mark.parametrize("seed", [1]) |
| 55 | +def test_target_model_tp_gt_1(baseline_llm_generator, test_llm_generator, |
| 56 | + batch_size: int, output_len: int): |
| 57 | + """Verify greedy equality when tensor parallelism is used. |
| 58 | + """ |
| 59 | + if is_hip(): |
| 60 | + pytest.skip("hip is not well-supported yet") |
| 61 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 62 | + test_llm_generator, |
| 63 | + batch_size, |
| 64 | + max_output_len=output_len, |
| 65 | + force_output_len=True) |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.skipif(torch.cuda.device_count() < 2, |
| 69 | + reason="Need at least 2 GPUs to run the test.") |
| 70 | +@pytest.mark.parametrize( |
| 71 | + "common_llm_kwargs", |
| 72 | + [{ |
| 73 | + # Use a small model for a fast test. |
| 74 | + # Note this is repeated in the test body; to initialize a tokenizer. |
| 75 | + "model": "JackFram/llama-68m", |
| 76 | +
|
| 77 | + # Skip cuda graph recording for fast test. |
| 78 | + "enforce_eager": True, |
| 79 | +
|
| 80 | + # Required for spec decode. |
| 81 | + "use_v2_block_manager": True, |
| 82 | + "tensor_parallel_size": 2, |
| 83 | +
|
| 84 | + # Use AsyncLLM engine, so that the engine runs in its own process. |
| 85 | + # Otherwise, since vLLM does not follow true SPMD, the test runner |
| 86 | + # process will have both the engine and the rank0 worker. NCCL is not |
| 87 | + # cleaned up properly, and its server host thread leaks, causing the |
| 88 | + # second run of the test to fail with internal NCCL error. |
| 89 | + "use_async": True, |
| 90 | + }]) |
| 91 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 92 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 93 | +@pytest.mark.parametrize("test_llm_kwargs", [ |
| 94 | + { |
| 95 | + "speculative_model": "JackFram/llama-68m", |
| 96 | + "num_speculative_tokens": 5, |
| 97 | + "speculative_draft_tensor_parallel_size": 1, |
| 98 | + }, |
| 99 | +]) |
| 100 | +@pytest.mark.parametrize("batch_size", [2]) |
| 101 | +@pytest.mark.parametrize("seed", [1]) |
| 102 | +def test_draft_model_tp_lt_target_model_tp2(test_llm_generator, |
| 103 | + baseline_llm_generator, |
| 104 | + batch_size: int): |
| 105 | + """Verify spec decode works well with smaller tp for draft models. |
| 106 | + """ |
| 107 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 108 | + test_llm_generator, |
| 109 | + batch_size, |
| 110 | + max_output_len=32, |
| 111 | + force_output_len=True) |
0 commit comments