| 1 | # EAGLE Draft Models |
| 2 | |
| 3 | The following code configures vLLM to use speculative decoding where proposals are generated by an [EAGLE (Extrapolation Algorithm for Greater Language-model Efficiency)](https://arxiv.org/pdf/2401.15077) based draft model. A more detailed example for offline mode, including how to extract request level acceptance rate, can be found in [examples/features/speculative_decoding/spec_decode_offline.py](../../../examples/features/speculative_decoding/spec_decode_offline.py) |
| 4 | |
| 5 | ## Eagle Drafter Example |
| 6 | |
| 7 | ```python |
| 8 | from vllm import LLM, SamplingParams |
| 9 | |
| 10 | prompts = ["The future of AI is"] |
| 11 | sampling_params = SamplingParams(temperature=0.8, top_p=0.95) |
| 12 | |
| 13 | llm = LLM( |
| 14 | model="meta-llama/Meta-Llama-3-8B-Instruct", |
| 15 | tensor_parallel_size=4, |
| 16 | speculative_config={ |
| 17 | "model": "yuhuili/EAGLE-LLaMA3-Instruct-8B", |
| 18 | "draft_tensor_parallel_size": 1, |
| 19 | "num_speculative_tokens": 2, |
| 20 | "method": "eagle", |
| 21 | }, |
| 22 | ) |
| 23 | |
| 24 | outputs = llm.generate(prompts, sampling_params) |
| 25 | |
| 26 | for output in outputs: |
| 27 | prompt = output.prompt |
| 28 | generated_text = output.outputs[0].text |
| 29 | print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") |
| 30 | ``` |
| 31 | |
| 32 | ## Eagle3 Drafter Example |
| 33 | |
| 34 | ```python |
| 35 | from vllm import LLM, SamplingParams |
| 36 | |
| 37 | prompts = ["The future of AI is"] |
| 38 | sampling_params = SamplingParams(temperature=0.8, top_p=0.95) |
| 39 | |
| 40 | llm = LLM( |
| 41 | model="meta-llama/Meta-Llama-3-8B-Instruct", |
| 42 | tensor_parallel_size=2, |
| 43 | speculative_config={ |
| 44 | "model": "RedHatAI/Llama-3.1-8B-Instruct-speculator.eagle3", |
| 45 | "draft_tensor_parallel_size": 2, |
| 46 | "num_speculative_tokens": 2, |
| 47 | "method": "eagle3", |
| 48 | }, |
| 49 | ) |
| 50 | |
| 51 | outputs = llm.generate(prompts, sampling_params) |
| 52 | |
| 53 | for output in outputs: |
| 54 | prompt = output.prompt |
| 55 | generated_text = output.outputs[0].text |
| 56 | print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") |
| 57 | ``` |
| 58 | |
| 59 | ## Pre-Trained Eagle Draft Models |
| 60 | |
| 61 | A variety of EAGLE draft models are available on the Hugging Face hub: |
| 62 | |
| 63 | * [RedHatAI/speculator-models](https://huggingface.co/collections/RedHatAI/speculator-models) |
| 64 | * [yuhuili/models](https://huggingface.co/yuhuili/models?search=eagle) |
| 65 | |
| 66 | !!! warning |
| 67 | If you are using `vllm<0.7.0`, please use [this script](https://gist.github.com/abhigoyal1997/1e7a4109ccb7704fbc67f625e86b2d6d) to convert the speculative model and specify `"model": "path/to/modified/eagle/model"` in `speculative_config`. |