---
title: "Faster Text Generation with Self-Speculative Decoding"
description: "Self-speculative decoding from the LayerSkip paper drafts tokens by exiting early from a model's own intermediate layers and verifies them with the remaining layers."
url: "https://swe.quest/articles/faster-text-generation-with-self-speculative-decoding-0171e077befc3347"
canonical: "https://huggingface.co/blog/layerskip"
source: "Hugging Face"
published: "2024-11-20"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 13
tags: ["inference","llms","performance"]
---

# Faster Text Generation with Self-Speculative Decoding

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-11-20, 13 min read, Deep dive. Original: [https://huggingface.co/blog/layerskip](https://huggingface.co/blog/layerskip)

## Summary

Self-speculative decoding from the LayerSkip paper drafts tokens by exiting early from a model's own intermediate layers and verifies them with the remaining layers. Because no separate draft model is needed, weights, KV cache and compute for the first layers can be shared. It only speeds things up on checkpoints trained with the LayerSkip recipe (layer dropout plus early-exit loss), and Hugging Face transformers exposes it through the \`assistant\_early\_exit\` argument to \`generate()\`. On A100 benchmarks it reaches up to about 1.8x over autoregressive decoding and beats two-model speculative decoding for most Llama sizes except Llama2 70B. The best exit layer is a per-model tradeoff between draft accuracy and drafting cost.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- transformer decoder architecture ([easy posts on System design](https://swe.quest/tags/system-design.md?difficulty=easy))
- speculative decoding
- KV cache ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))

## Keywords

LayerSkip, self-speculative decoding, Hugging Face Transformers, Llama 2, Llama 3, early exit

## Related posts

- [Achieve state-of-the-art inference latencies with speculative decoding](https://swe.quest/articles/achieve-state-of-the-art-inference-latencies-with-speculative-decoding-29855d3aec239f45.md): Modal · 2026-06-24 · Hard · 9 min read · Inference & serving, LLMs, Performance engineering, Model training
  Speculative decoding is the dominant lever for low-latency LLM serving because decode steps dominate latency and speculation yields multiplicative speedups roughly linear in acceptance length.
- [Speculation Is All You Need](https://swe.quest/articles/speculation-is-all-you-need-dffc126cb5233807.md): Modal · 2026-06-19 · Hard · 17 min read · Inference & serving, LLMs, Performance engineering, Model training
  Speculative decoding delivers integral-factor (2-3x+) LLM decode speedups, far beyond the few-percent gains from kernel or host-side optimization, and its benefit scales roughly linearly with acceptance length.
- [Faster Assisted Generation with Dynamic Speculation](https://swe.quest/articles/faster-assisted-generation-with-dynamic-speculation-d8a65fbd607c86ac.md): Hugging Face · 2024-10-08 · Medium · 7 min read · Inference & serving, LLMs, Performance engineering
  Dynamic speculative decoding stops the draft model's token generation as soon as its softmax confidence falls below a threshold (assistant\_confidence\_threshold), rather than always drafting a fixed or heuristically adjusted number of tokens before verification by the target model.
- [Accelerate RL rollouts by up to 50% with distribution-aware speculative decoding](https://swe.quest/articles/accelerate-rl-rollouts-by-up-to-50-with-distribution-aware-speculative-decoding-1fa2a300c01f2135.md): Together AI · 2026-04-24 · Hard · 5 min read · Inference & serving, Model training, LLMs, Performance engineering, Data structures
  Distribution-aware speculative decoding (DAS) speeds up the rollout phase of LLM RL post-training, which can consume ~70% of training time due to long-tail straggler generations, while keeping outputs identical to standard decoding.
- [Universal Assisted Generation: Faster Decoding with Any Assistant Model](https://swe.quest/articles/universal-assisted-generation-faster-decoding-with-any-assistant-model-9472b2a3456cf247.md): Hugging Face · 2024-10-29 · Hard · 6 min read · Inference & serving, LLMs, Performance engineering
  Universal Assisted Generation (UAG) extends speculative decoding so the assistant model no longer needs the target's tokenizer.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
