test_eagle_correctness.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. """This docstring details important information on the testing methodology.
  2. Most of the tests rely on "greedy equality", where we expect the output of
  3. speculative decoding on a sequence to exactly match the output of normal non-
  4. speculative decoding.
  5. Since speculative decoding with rejection sampling guarantees that the output
  6. distribution matches the target model's output distribution (up to hardware
  7. numerics, see https://arxiv.org/pdf/2302.01318.pdf), we can expect greedy
  8. equality.
  9. However, we still need to verify below scenario could be passed:
  10. * Batch size 1 greedy equality
  11. * Batch size >1 greedy equality
  12. * Test greedy equality under preemption
  13. * Test greedy equality under various number of speculative tokens.
  14. With those tests, we can say at least, EAGLE would not break the
  15. correctess for the target model outputs.
  16. """
  17. import pytest
  18. from .conftest import run_equality_correctness_test
  19. # main model
  20. MAIN_MODEL = "JackFram/llama-68m"
  21. # speculative model
  22. SPEC_MODEL = "abhigoyal/vllm-eagle-llama-68m-random"
  23. # max. number of speculative tokens: this corresponds to
  24. # num_heads in the config.json of the speculator model.
  25. MAX_SPEC_TOKENS = 4
  26. # precision
  27. PRECISION = "float32"
  28. @pytest.mark.parametrize(
  29. "common_llm_kwargs",
  30. [{
  31. # Skip cuda graph recording for fast test.
  32. "enforce_eager": True,
  33. # Required for spec decode.
  34. "use_v2_block_manager": True,
  35. # Print spec metrics.
  36. "disable_log_stats": False,
  37. # Precision
  38. "dtype": PRECISION,
  39. # Main model
  40. "model_name": MAIN_MODEL,
  41. }])
  42. @pytest.mark.parametrize("per_test_common_llm_kwargs", [{}])
  43. @pytest.mark.parametrize("baseline_llm_kwargs", [{}])
  44. @pytest.mark.parametrize("test_llm_kwargs", [
  45. {
  46. "speculative_model": SPEC_MODEL,
  47. "num_speculative_tokens": MAX_SPEC_TOKENS,
  48. },
  49. ])
  50. @pytest.mark.parametrize("output_len", [
  51. 128,
  52. ])
  53. @pytest.mark.parametrize("batch_size", [1, 32])
  54. @pytest.mark.parametrize("seed", [1])
  55. def test_eagle_e2e_greedy_correctness(aphrodite_runner, common_llm_kwargs,
  56. per_test_common_llm_kwargs,
  57. baseline_llm_kwargs, test_llm_kwargs,
  58. batch_size: int, output_len: int,
  59. seed: int):
  60. run_equality_correctness_test(aphrodite_runner, common_llm_kwargs,
  61. per_test_common_llm_kwargs,
  62. baseline_llm_kwargs, test_llm_kwargs,
  63. batch_size, output_len, seed)
  64. @pytest.mark.parametrize(
  65. "common_llm_kwargs",
  66. [{
  67. "enforce_eager": False,
  68. # Required for spec decode.
  69. "use_v2_block_manager": True,
  70. # Print spec metrics.
  71. "disable_log_stats": False,
  72. # Precision
  73. "dtype": PRECISION,
  74. # Main model
  75. "model_name": MAIN_MODEL,
  76. }])
  77. @pytest.mark.parametrize("per_test_common_llm_kwargs", [{}])
  78. @pytest.mark.parametrize("baseline_llm_kwargs", [{}])
  79. @pytest.mark.parametrize("test_llm_kwargs", [
  80. {
  81. "speculative_model": SPEC_MODEL,
  82. "num_speculative_tokens": MAX_SPEC_TOKENS,
  83. },
  84. ])
  85. @pytest.mark.parametrize("output_len", [
  86. 128,
  87. ])
  88. @pytest.mark.parametrize("batch_size", [1, 32])
  89. @pytest.mark.parametrize("seed", [1])
  90. def test_eagle_e2e_greedy_correctness_cuda_graph(
  91. aphrodite_runner, common_llm_kwargs, per_test_common_llm_kwargs,
  92. baseline_llm_kwargs, test_llm_kwargs, batch_size: int, output_len: int,
  93. seed: int):
  94. """Verify greedy equality with cuda graph enabled and different
  95. batch sizes."""
  96. run_equality_correctness_test(aphrodite_runner, common_llm_kwargs,
  97. per_test_common_llm_kwargs,
  98. baseline_llm_kwargs, test_llm_kwargs,
  99. batch_size, output_len, seed)
  100. @pytest.mark.parametrize(
  101. "common_llm_kwargs",
  102. [{
  103. "block_size": 8,
  104. # 2 for small prompt, 256//8 for generated.
  105. "num_gpu_blocks_override": 2 + 256 // 8,
  106. "max_model_len": (2 + 256 // 8) * 8,
  107. # Skip cuda graph recording for fast test.
  108. "enforce_eager": True,
  109. # Required for spec decode.
  110. "use_v2_block_manager": True,
  111. # Precision
  112. "dtype": PRECISION,
  113. # Main model
  114. "model_name": MAIN_MODEL,
  115. }])
  116. @pytest.mark.parametrize("per_test_common_llm_kwargs", [{}])
  117. @pytest.mark.parametrize("baseline_llm_kwargs", [{}])
  118. @pytest.mark.parametrize("test_llm_kwargs", [
  119. {
  120. "speculative_model": SPEC_MODEL,
  121. "num_speculative_tokens": MAX_SPEC_TOKENS,
  122. },
  123. ])
  124. @pytest.mark.parametrize(
  125. "output_len",
  126. [
  127. # Use small output len for fast test.
  128. 128,
  129. ])
  130. @pytest.mark.parametrize("batch_size", [4])
  131. @pytest.mark.parametrize("seed", [1])
  132. def test_eagle_e2e_greedy_correctness_with_preemption(
  133. aphrodite_runner, common_llm_kwargs, per_test_common_llm_kwargs,
  134. baseline_llm_kwargs, test_llm_kwargs, batch_size: int, output_len: int,
  135. seed: int):
  136. """Verify greedy equality, even when some sequences are preempted mid-
  137. generation.
  138. """
  139. run_equality_correctness_test(aphrodite_runner, common_llm_kwargs,
  140. per_test_common_llm_kwargs,
  141. baseline_llm_kwargs, test_llm_kwargs,
  142. batch_size, output_len, seed)
  143. @pytest.mark.parametrize(
  144. "common_llm_kwargs",
  145. [{
  146. # Skip cuda graph recording for fast test.
  147. "enforce_eager": True,
  148. # Required for spec decode.
  149. "use_v2_block_manager": True,
  150. # Precision
  151. "dtype": PRECISION,
  152. # Main model
  153. "model_name": MAIN_MODEL,
  154. }])
  155. @pytest.mark.parametrize("per_test_common_llm_kwargs", [{}])
  156. @pytest.mark.parametrize("baseline_llm_kwargs", [{}])
  157. @pytest.mark.parametrize(
  158. "test_llm_kwargs",
  159. [
  160. {
  161. "speculative_model": SPEC_MODEL,
  162. "num_speculative_tokens": k,
  163. }
  164. # Try a range of num. speculative tokens
  165. for k in range(1, 1 + MAX_SPEC_TOKENS)
  166. ])
  167. @pytest.mark.parametrize("batch_size", [2])
  168. @pytest.mark.parametrize(
  169. "output_len",
  170. [
  171. # Use smaller output len for fast test.
  172. 32,
  173. ])
  174. @pytest.mark.parametrize("seed", [1])
  175. def test_eagle_different_k(aphrodite_runner, common_llm_kwargs,
  176. per_test_common_llm_kwargs, baseline_llm_kwargs,
  177. test_llm_kwargs, batch_size: int, output_len: int,
  178. seed: int):
  179. """Verify that eagle speculative decoding produces exact equality
  180. to without spec decode with different values of num_speculative_tokens.
  181. """
  182. run_equality_correctness_test(aphrodite_runner, common_llm_kwargs,
  183. per_test_common_llm_kwargs,
  184. baseline_llm_kwargs, test_llm_kwargs,
  185. batch_size, output_len, seed)
  186. @pytest.mark.parametrize(
  187. "common_llm_kwargs",
  188. [{
  189. # Skip cuda graph recording for fast test.
  190. "enforce_eager": True,
  191. # Required for spec decode.
  192. "use_v2_block_manager": True,
  193. # Precision
  194. "dtype": PRECISION,
  195. # Main model
  196. "model_name": MAIN_MODEL,
  197. }])
  198. @pytest.mark.parametrize("per_test_common_llm_kwargs", [{}])
  199. @pytest.mark.parametrize("baseline_llm_kwargs", [{}])
  200. @pytest.mark.parametrize("test_llm_kwargs",
  201. [{
  202. "speculative_model": SPEC_MODEL,
  203. "num_speculative_tokens": MAX_SPEC_TOKENS,
  204. "speculative_disable_by_batch_size": 4
  205. }])
  206. @pytest.mark.parametrize("batch_size", [1, 5])
  207. @pytest.mark.parametrize(
  208. "output_len",
  209. [
  210. # Use smaller output len for fast test.
  211. 32,
  212. ])
  213. @pytest.mark.parametrize("seed", [1])
  214. def test_eagle_disable_queue(aphrodite_runner, common_llm_kwargs,
  215. per_test_common_llm_kwargs, baseline_llm_kwargs,
  216. test_llm_kwargs, batch_size: int, output_len: int,
  217. seed: int):
  218. """Verify that eagle speculative decoding produces exact equality
  219. to without spec decode when speculation is disabled for large
  220. batch sizes.
  221. """
  222. run_equality_correctness_test(aphrodite_runner, common_llm_kwargs,
  223. per_test_common_llm_kwargs,
  224. baseline_llm_kwargs, test_llm_kwargs,
  225. batch_size, output_len, seed)
  226. if __name__ == "__main__":
  227. import pytest
  228. pytest.main([__file__])