دليل اللغة AI

Speculative Decoding and Draft Models

Speculative decoding speeds up large language models by letting a small, fast draft model guess several upcoming tokens, which the large target model then checks in a single pass.

استمع إلى هذا الدليلرواه الذكاء الاصطناعي · ~7 min

في هذه الصفحة8 دقائق قراءة
  1. نظرة عامة
  2. النقاط الرئيسية
  3. الغوص العميق
  4. Trace one round of speculative decoding
  5. التنفيذ في العالم الحقيقي
  6. The Future of Speculative Decoding and Draft Models
  7. وضعها موضع التنفيذ
  8. المصادر ومزيد من القراءة
  9. استمر في الاستكشاف
  10. الأسئلة المتداولة

نظرة عامة

With the standard acceptance rule the output follows exactly the same probability distribution as the large model alone, so it is faster text with no change in quality, typically two to three times faster in published tests.

النقاط الرئيسية

  1. Speculative decoding lets a small draft model guess several tokens that a large target model verifies in one forward pass.
  2. With the standard acceptance rule, the output distribution is mathematically identical to sampling from the large model alone.
  3. Google's 2022 paper reported 2 to 3 times faster T5-XXL decoding, and DeepMind sped up 70-billion-parameter Chinchilla 2 to 2.5 times.
  4. It works because language model inference is limited by memory bandwidth, leaving spare compute to check several tokens at once.
  5. Speedup depends on the acceptance rate, so predictable tasks like summarization and code gain more than high-temperature creative text.

الغوص العميق

Large language models write text one token at a time, where a token is a word or word fragment. Each new token needs a full forward pass through the model, a computation that reads all of its billions of weights from memory. Speculative decoding is a way to produce several tokens per expensive pass. A small, cheap model, called the draft model or drafter, quickly guesses the next few tokens. The large model, called the target model, then scores all of those guesses at once and keeps the ones it agrees with. When the guesses are good, the large model has effectively written several tokens for the price of one pass.

The method works step by step. First the drafter generates a short run of candidate tokens, say four or five, one after another; this is cheap because the drafter is small. Second, the target model runs one forward pass over the prompt plus all candidates together. Because Transformers process a whole sequence in parallel, this single pass yields the target's own probability for every candidate position. Third, each candidate is accepted or rejected in order using a rule that compares the target's probability with the drafter's. Fourth, at the first rejection the remaining guesses are thrown away and the target supplies a replacement token from a corrected distribution. If every guess is accepted, the target also contributes one bonus token. The loop then repeats from the new position.

The speedup comes from a hardware fact. Google researchers explained in a December 2024 retrospective that inference is usually limited by memory bandwidth, not arithmetic: chips can perform hundreds of operations per byte they read, while Transformer decoding performs only a few. Checking five tokens therefore costs about the same wall-clock time as generating one, because the weights are read from memory once either way. The second fact is that many tokens are easy. After "the United States of", almost any model predicts "America", so a tiny drafter is often right.

The idea was published twice in quick succession. Yaniv Leviathan, Matan Kalman and Yossi Matias of Google posted "Fast Inference from Transformers via Speculative Decoding" in November 2022 (ICML 2023), reporting 2 to 3 times faster decoding of the 11-billion-parameter T5-XXL with identical outputs; their retrospective cites about 3 times on translation using the 60-million-parameter T5-small as drafter. In February 2023 a DeepMind team led by Charlie Chen independently described speculative sampling and sped up the 70-billion-parameter Chinchilla 2 to 2.5 times. Hugging Face shipped the technique as "assisted generation" in Transformers in May 2023. Later work replaced the separate drafter: Medusa (January 2024) adds extra prediction heads to the target model and reports 2.2 to 3.6 times speedups, and EAGLE (January 2024) trains a light drafter on the target's internal features, reporting 2.7 to 3.5 times lower latency on LLaMA2-Chat 70B.

Compared with the alternatives, speculative decoding is unusual because it is lossless. Quantization (storing weights at lower precision), distillation (training a smaller model to imitate a large one) and pruning all make inference cheaper by changing the model, which can change its answers. Speculative decoding leaves the target model untouched, and the acceptance rule guarantees the same output distribution. vLLM's documentation adds a practical caveat: results are identical in theory but can differ slightly in practice because of floating-point precision and batching. Some variants trade this guarantee for speed; Medusa-2 fine-tunes the backbone, and vLLM labels its FLy verification mode as lossy.

The main limitation is that the gain depends entirely on the acceptance rate, the share of drafted tokens the target keeps. A drafter that disagrees often wastes work, so open-ended creative writing at high temperature gains less than code completion or summarization. Hugging Face found speedups of up to 2 times in ordinary GPU setups (3 times with 8-bit weights) and up to 10 times when the model was too large for GPU memory, but warned that the method is not a cure-all and should be benchmarked. Load matters too. At high request rates the GPU is already busy with large batches, spare compute shrinks, and vLLM's guide rates the benefit of draft models in that regime as only medium. Its first Transformers release supported only a batch size of one.

In practice a separate drafter must share the target's tokenizer, meaning the same mapping from text to token IDs, so that both models are guessing the same units; Hugging Face recommends a drafter at least ten times smaller. It also costs GPU memory to hold both models, plus engineering time to tune the number of drafted tokens. Model families that ship in several sizes, such as a 1-billion and a 70-billion version trained on the same data, make natural pairs. Feature-based drafters such as EAGLE need a short training run on the target model but no tokenizer search, and n-gram methods, which copy likely continuations from the prompt itself, need no extra model at all.

04عملت المثال

Trace one round of speculative decoding

  1. Start with the prompt "The capital of France is" and let the drafter propose four tokens: "Paris", ",", "a", "city".

  2. Run the target model once over the prompt plus all four candidates to get its probabilities at each of the four positions.

  3. Check "Paris": the drafter gave it 0.90 and the target 0.95, so p/q is above 1 and it is accepted.

  4. Check ",": the drafter gave 0.50 and the target 0.40, so accept with probability 0.8; suppose the random draw accepts it.

  5. Check "a": the drafter gave 0.30 and the target 0.06, so accept with probability 0.2; suppose it is rejected.

  6. Discard "city", sample a replacement from the residual max(0, p - q), for example "which", and start the next round from "Paris, which".

ما يظهر

One target pass produced three tokens instead of one. To check the logic, repeat the round many times with a random seed and confirm that the frequency of each final token matches the target model's probabilities, which is the losslessness guarantee in action.

التنفيذ في العالم الحقيقي

Google applies speculative decoding in several products, including AI Overviews in Google Search, which its researchers said in December 2024 now returns results faster with the same response quality.

In Hugging Face Transformers, passing a small model such as pythia-160m as assistant_model to generate() lets it draft tokens for pythia-1.4b, provided both share the exact same tokenizer.

The vLLM inference server supports draft models, EAGLE, multi-token prediction heads, n-gram and suffix decoding, configured through a speculative_config setting with num_speculative_tokens.

DeepMind's 2023 speculative sampling paper sped up the 70-billion-parameter Chinchilla model 2 to 2.5 times in a distributed setup without changing its outputs.

Speech recognition and summarization benefit strongly because their outputs closely follow the input, making the next tokens easy for a small drafter to guess, according to Hugging Face's assisted generation write-up.

The Future of Speculative Decoding and Draft Models

Research since 2024 has moved from separate draft models toward drafters built into or trained on the target model. EAGLE-3, posted in March 2025, reports up to 6.5 times speedup and a 1.38 times throughput gain at batch size 64 in the SGLang serving framework, addressing the older weakness that speculation helped little under heavy load. Serving engines are adding dynamic speculation that changes the drafted length per request based on measured acceptance; vLLM's documentation in 2026 lists dynamic speculative decoding, adaptive verification and per-request acceptance metrics. Open problems remain. Gains shrink for high-temperature sampling and for very large batches, keeping two models in memory competes with space for longer contexts, and lossy variants that relax verification for extra speed blur the original guarantee that outputs are unchanged. Google's 2024 retrospective notes that the same draft-and-verify idea has spread to image and speech generation. Whether future models will be trained from the start with built-in drafting heads, removing the need for a separate drafter, is an active direction rather than a settled outcome.

وضعها موضع التنفيذ

لماذا يهم

  • السرعة والحجم. يمكن أن تتحرك مسارات عمل اللغة بشكل أسرع دون التضحية بالاتساق.
  • الوصول والوصول. فهو يوسع الوصول عبر اللغات وأنماط الاتصال.
  • قرارات أوضح. يمكن للفرق قضاء المزيد من الوقت في الحكم بينما تتعامل الأتمتة مع التكرار.

احترس من

  • يمكن للحقائق المهلوسة إدخال التقارير أو تدفقات الدعم أو مخرجات البحث بهدوء.
  • يمكن أن تؤدي الحساسية السريعة إلى نتائج غير متناسقة عبر الطلبات المماثلة.
  • قد يتم كشف البيانات النصية الحساسة إذا كانت عناصر التحكم في الوصول ضعيفة.

الخطوات التالية

  1. حدد تنسيق الإخراج والنغمة ومعايير الجودة قبل بدء التشغيل.
  2. استجابات أرضية من مصادر موثوقة عندما تكون الدقة مهمة.
  3. احتفظ بنقطة تفتيش للمراجعة البشرية للمخرجات عالية المخاطر.
  4. تتبع أنماط الفشل وأعد تدريب المطالبات أو سير العمل بانتظام.

المصادر ومزيد من القراءة

  1. arXiv (ICML 2023)Fast Inference from Transformers via Speculative Decoding
  2. arXiv (DeepMind)Accelerating Large Language Model Decoding with Speculative Sampling
  3. Google ResearchLooking back at speculative decoding
  4. Hugging FaceAssisted Generation: a new direction toward low-latency text generation
  5. vLLM Documentationفك التشفير التخميني
  6. arXivMedusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads
  7. arXivEAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty
  8. arXivEAGLE-3: Scaling up Inference Acceleration of Large Language Models via Training-Time Test

استمر في الاستكشاف

رسالة إخبارية مجانية

احصل على الإحاطة اليومية لمنظمة العفو الدولية

ثلاث قصص تم التحقق منها بواسطة الذكاء الاصطناعي كل صباح من أيام الأسبوع، مكتوبة باللغة الإنجليزية البسيطة. مجاني للأبد، بدون إعلانات.

بريد إلكتروني واحد كل يوم من أيام الأسبوع. إلغاء الاشتراك بنقرة واحدة. نحن لا نبيع أو نشارك عنوانك أبدًا.

اختبر نفسك

Take the Speculative Decoding and Draft Models quiz

تعليقات فورية على كل إجابة، وشهادة قابلة للمشاركة مع معرف يمكن التحقق منه بمجرد اجتياز الدورة التدريبية.

ابدأ الاختبار

دعم تعليم الذكاء الاصطناعي المجاني. AI Understanding هي منظمة 501(c)(3) غير ربحية - لا إعلانات ولا نظام حظر الاشتراك غير المدفوع على الإطلاق. قم بالتبرع

الأسئلة المتداولة

What is Speculative Decoding and Draft Models?

Speculative decoding speeds up large language models by letting a small, fast draft model guess several upcoming tokens, which the large target model then checks in a single pass. With the standard acceptance rule the output follows exactly the same probability distribution as the large model alone, so it is faster text with no change in quality, typically two to three times faster in published tests.

ما هو الدور الأساسي لنموذج "المسودة" في فك التشفير التأملي؟

يخمن نموذج المسودة الصغيرة الرموز المميزة القادمة بتكلفة زهيدة، والتي يتحقق منها النموذج المستهدف الكبير بعد ذلك في تمريرة متوازية واحدة.

Why can verifying a drafted token block accelerate target-model generation in a suitable workload?

Parallel verification can reduce the cost per accepted token, but its cost and benefit depend on the model, hardware, block length, and acceptance rate.

ماذا يحدث للرموز المميزة التي تمت صياغتها بعد الرمز المميز الأول الذي يرفضه النموذج المستهدف؟

In the standard procedure, the first rejection ends acceptance of the drafted prefix. A correction is sampled and the later draft suffix is discarded; rejection is governed by the acceptance test rather than just an argmax disagreement.

What correctness property does the standard exact speculative-sampling rejection procedure preserve under its assumptions?

Exactness concerns the sampling law, not factual correctness or guaranteed bit-for-bit sequence identity.

Which mechanism distinguishes EAGLE's drafting approach from Medusa's additional decoding heads?

EAGLE uses feature-level autoregression, while Medusa introduces multiple additional token-prediction heads.

استمر في التعلم

أدلة ذات صلة

تم اختيار المزيد من الأدلة لهذا الموضوع

احصل على شهادة الذكاء الاصطناعي المجانيةدورة مجانية قصيرة واختبار. لا تكلفة ولا بطاقة. حوالي 2.5 ساعة.ابدأ مجانًا →