test_integration_dist_tp4.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """Tests which cover integration of the speculative decoding framework with
  2. tensor parallelism.
  3. """
  4. import openai
  5. import pytest
  6. import torch
  7. from .conftest import run_equality_correctness_test_tp
  8. MAIN_MODEL = "JackFram/llama-68m"
  9. SPEC_MODEL = "JackFram/llama-68m"
  10. @pytest.mark.skipif(torch.cuda.device_count() < 4,
  11. reason="Need at least 4 GPUs to run the test.")
  12. @pytest.mark.parametrize(
  13. "common_llm_kwargs",
  14. [[
  15. # Skip cuda graph recording for fast test.
  16. "--enforce_eager",
  17. # Required for spec decode.
  18. "--use-v2-block-manager",
  19. "--tensor-parallel-size",
  20. "4",
  21. ]])
  22. @pytest.mark.parametrize("per_test_common_llm_kwargs", [
  23. [
  24. "--speculative-model",
  25. f"{SPEC_MODEL}",
  26. "--num-speculative-tokens",
  27. "5",
  28. ],
  29. ])
  30. @pytest.mark.parametrize("baseline_llm_kwargs", [[]])
  31. @pytest.mark.parametrize(
  32. "test_llm_kwargs",
  33. [
  34. #TODO(wooyeon): add spec_draft_dp=2 case
  35. [
  36. "--speculative-draft-tensor-parallel-size",
  37. "1",
  38. ],
  39. ])
  40. @pytest.mark.parametrize("batch_size", [2])
  41. @pytest.mark.parametrize("seed", [1])
  42. def test_draft_model_tp_lt_target_model_tp4(common_llm_kwargs,
  43. per_test_common_llm_kwargs,
  44. baseline_llm_kwargs,
  45. test_llm_kwargs, batch_size: int,
  46. seed: int):
  47. """Verify spec decode works well with smaller tp for draft models.
  48. """
  49. run_equality_correctness_test_tp(MAIN_MODEL,
  50. common_llm_kwargs,
  51. per_test_common_llm_kwargs,
  52. baseline_llm_kwargs,
  53. test_llm_kwargs,
  54. batch_size,
  55. max_output_len=32,
  56. seed=seed,
  57. temperature=0.0)
  58. @pytest.mark.skipif(torch.cuda.device_count() < 4,
  59. reason="Need at least 4 GPUs to run the test.")
  60. @pytest.mark.parametrize(
  61. "common_llm_kwargs",
  62. [[
  63. # Skip cuda graph recording for fast test.
  64. "--enforce-eager",
  65. # Required for spec decode.
  66. "--use-v2-block-manager",
  67. "--tensor-parallel-size",
  68. "4",
  69. ]])
  70. @pytest.mark.parametrize("per_test_common_llm_kwargs", [[]])
  71. @pytest.mark.parametrize("baseline_llm_kwargs", [[]])
  72. @pytest.mark.parametrize(
  73. "test_llm_kwargs",
  74. [
  75. [
  76. "--speculative-model",
  77. f"{SPEC_MODEL}",
  78. "--num-speculative-tokens",
  79. "5",
  80. # Artificially limit the draft model max model len; this forces vLLM
  81. # to skip speculation once the sequences grow beyond 32-k tokens.
  82. "--speculative-max-model-len",
  83. "32",
  84. ],
  85. ])
  86. @pytest.mark.parametrize("batch_size", [8])
  87. @pytest.mark.parametrize(
  88. "output_len",
  89. [
  90. # This must be a good bit larger than speculative_max_model_len so that
  91. # we can test the case where all seqs are skipped, but still small to
  92. # ensure fast test.
  93. 64,
  94. ])
  95. @pytest.mark.parametrize("seed", [1])
  96. def test_skip_speculation(common_llm_kwargs, per_test_common_llm_kwargs,
  97. baseline_llm_kwargs, test_llm_kwargs,
  98. batch_size: int, output_len: int, seed: int):
  99. """Verify job failure with RuntimeError when all sequences skip speculation.
  100. We do this by setting the max model len of the draft model to an
  101. artificially low value, such that when the sequences grow beyond it, they
  102. are skipped in speculative decoding.
  103. TODO: fix it to pass without raising Error. (#5814)
  104. """
  105. with pytest.raises(openai.APIConnectionError):
  106. run_equality_correctness_test_tp(MAIN_MODEL,
  107. common_llm_kwargs,
  108. per_test_common_llm_kwargs,
  109. baseline_llm_kwargs,
  110. test_llm_kwargs,
  111. batch_size,
  112. output_len,
  113. seed,
  114. temperature=0.0)