Speculative decoding
Speculative decoding with Red Hat AI Inference
Abstract
Chapter 1. About Speculators
Speculators is a unified library for building, training, and storing speculative decoding algorithms for large language model (LLM) inference, including frameworks such as vLLM.
Speculators is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
Speculative decoding is an optimization technique that improves inference performance for the LLM you are trying to serve. Red Hat AI Inference supports Eagle 3, a speculative decoding algorithm that uses a small, single-layer draft model and a full-sized 'verifier' model, which is the LLM you are serving. The Eagle 3 speculator model auto-regressively predicts several tokens, and then the verifier model processes these tokens in parallel. As the verifier model can accept multiple tokens per forward pass, effective throughput increases. When the verifier model rejects a token, it samples a corrected token from its own distribution, ensuring the output matches what it would produce alone.
Speculative decoding provides the following advantages:
- Latency decreases through parallel token validation.
- Eagle 3 speculator models require minimal processing due to their small size.
- Output quality matches what the verifier model would produce alone.
Chapter 2. Deploying speculator models
Deploy a trained EAGLE-3 speculator model to accelerate inference using speculative decoding with Red Hat AI Inference.
Prerequisites
- You have installed Podman or Docker.
- You are logged in as a user with sudo access.
-
You have access to
registry.redhat.ioand have logged in. - You have a Hugging Face account and have generated a Hugging Face access token.
- You have access to a Linux server with at least one NVIDIA AI accelerator installed.
- You have installed the relevant Content from docs.nvidia.com is not included.NVIDIA drivers.
- You have installed the Content from docs.nvidia.com is not included.NVIDIA Container Toolkit.
Procedure
Log in to the Red Hat container registry:
podman login registry.redhat.io
Pull the AI Inference container image:
podman pull registry.redhat.io/{rhaii-registry-namespace}/vllm-cuda-rhel9:{rhaiis-version}Set your Hugging Face token as an environment variable:
export HF_TOKEN=<your_huggingface_token>
This example uses the RedHatAI/Qwen3-8B-speculator.eagle3 pre-trained model. For other available speculator models, see the Content from huggingface.co is not included.Red Hat AI speculator models collection. If you encounter an access error, verify that you have accepted a license agreement on Hugging Face before downloading.
Start the inference server with a speculator model:
podman run --rm -it \ --device nvidia.com/gpu=all \ --shm-size=2g \ -p 8000:8000 \ --env "HUGGING_FACE_HUB_TOKEN=$HF_TOKEN" \ --env "HF_HUB_OFFLINE=0" \ registry.redhat.io/{rhaii-registry-namespace}/vllm-cuda-rhel9:{rhaiis-version} \ --model RedHatAI/Qwen3-8B-speculator.eagle3 \ --host 0.0.0.0 \ --port 8000vLLM reads the speculator configuration from the model and loads both the draft model and the verifier model.
Verification
In a separate terminal, send a request to the model:
curl http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "RedHatAI/Qwen3-8B-speculator.eagle3", "messages": [ {"role": "user", "content": "Hello, how are you?"} ], "max_tokens": 50 }'Example output
{ "id": "chatcmpl-8dc33cb67b69b432", "object": "chat.completion", "created": 1776107449, "model": "RedHatAI/Qwen3-8B-speculator.eagle3", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "<think>\nOkay, the user greeted me with \"Hello, how are you?\" I need to respond in a friendly and helpful manner..." }, "finish_reason": "length" } ], "usage": { "prompt_tokens": 14, "total_tokens": 64, "completion_tokens": 50 } }
Chapter 3. Converting models with Speculators
Convert an existing Eagle 3 speculator model to the Speculators format for use with Red Hat AI Inference. Use this procedure when you have an externally-trained Eagle 3 checkpoint that is not already in the Speculators format.
Prerequisites
- You have installed Podman or Docker.
- You are logged in as a user with sudo access.
-
You have access to the
registry.redhat.ioimage registry and have logged in. - You have a Hugging Face account and have generated a Hugging Face access token.
- You have access to a Linux server with at least one NVIDIA AI accelerator installed.
- You have installed the relevant Content from docs.nvidia.com is not included.NVIDIA drivers.
- You have installed the Content from docs.nvidia.com is not included.NVIDIA Container Toolkit.
This example uses the meta-llama/Meta-Llama-3.1-8B-Instruct model, which requires accepting a license agreement. Before running this procedure, request access at Content from huggingface.co is not included.meta-llama/Llama-3.1-8B-Instruct on Hugging Face.
Procedure
Pull the Red Hat AI Model Optimization Toolkit container image:
$ podman pull registry.redhat.io/rhaii-early-access/model-opt-cuda-rhel9:3.5.0-ea.1
Verify the Speculators version installed in the container:
$ podman run --rm -it \ registry.redhat.io/rhaii-early-access/model-opt-cuda-rhel9:3.5.0-ea.1 \ pip show speculators | grep Version
Example output
Version: 0.4.0a1
Create a working directory and clone the upstream Speculators repository:
$ mkdir model-opt && \ cd model-opt && \ git clone https://github.com/vllm-project/speculators.git
Check out the Speculators branch that matches the version installed in the container:
$ cd speculators && \ git checkout v0.4.0+rhaiis
Create or append your
HF_TOKENHugging Face token to theprivate.envfile and source it:$ echo "export HF_TOKEN=<YOUR_HF_TOKEN>" > private.env $ source private.env
If your system has SELinux enabled, configure SELinux to allow device access:
$ sudo setsebool -P container_use_devices 1
Run the Content from github.com is not included.apply_eagle3_eagle.sh convert example using the Red Hat AI Model Optimization Toolkit container:
$ podman run --rm \ -v "$(pwd):/opt/app-root/model-opt" \ --device nvidia.com/gpu=0 \ --ipc=host \ -e HF_TOKEN=$HF_TOKEN \ registry.redhat.io/rhaii-early-access/model-opt-cuda-rhel9:3.5.0-ea.1 \ bash /opt/app-root/model-opt/speculators/examples/convert/eagle3/apply_eagle3_eagle.sh
The script downloads the Eagle 3 checkpoint, converts it to the Speculators format, and validates the result.
Verification
-
Verify that the output includes
Validation succeeded. -
Confirm that the converted model directory exists in your working directory, for example
eagle3-llama-3.1-8b-instruct-converted.
Example output
2026-04-17 13:58:49.830 | INFO | speculators.convert.eagle.eagle3_converter:convert:41 - Converting Eagle-3 checkpoint: yuhuili/EAGLE3-LLaMA3.1-Instruct-8B Fetching 2 files: 100%|██████████| 2/2 [00:06<00:00, 3.04s/it] 2026-04-17 13:59:01.127 | SUCCESS | speculators.convert.eagle.eagle3_converter:convert:88 - Saved to: eagle3-llama-3.1-8b-instruct-converted 2026-04-17 13:59:03.888 | SUCCESS | speculators.convert.eagle.eagle3_converter:_validate_converted_checkpoint:220 - Validation succeeded