SpecExec: Massively Parallel Speculative Decoding For Interactive LLM Inference on Consumer Devices

Authors: ruslan  svirschevski
†♡  avner may
zhuoming  chen
‡  beidi
chen  ‡♢
zhihao  jia
max  ryabinin
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-14 21:07:19

Abstract: As large language models gain widespread adoption, running them efficiently becomes a crucial task. Recent works on LLM inference use speculative decoding to achieve extreme speedups. However, most of these works implicitly design their algorithms for high-end datacenter hardware. In this work, we ask the opposite question: how fast can we run LLMs on consumer machines? Consumer GPUs can no longer fit the largest available models and must offload them to RAM or SSD. With parameter offloading, hundreds or thousands of tokens can be processed in batches within the same time as just one token, making it a natural fit for speculative decoding. We propose SpecExec (Speculative Execution), a simple parallel decoding method that can generate up to 20 tokens per target model iteration for popular LLM families.  SpecExec takes the most probable continuations from the draft model to build a "cache" tree for the target model, which then gets validated in a single pass. Using SpecExec, we demonstrate inference of 50B+ parameter LLMs on consumer GPUs with RAM offloading at 4--6 tokens per second with 4-bit quantization or 2--3 tokens per second with 16-bit weights. Our code is available at https://github.com/yandex-research/specexec .

Main paper: 
 introduction: 
 Open-access large language models (LLMs), such as Llama [Touvron et al., 2023] and Mistral [Jiang et al., 2023] , have become increasingly capable in the past years, and their adoption has grown dramatically. Although these models are openly available, users who are interested in running these models on consumer-grade GPUs (for example, due to privacy or cost reasons) face significant challenges. Many open-access LLMs are too large to fit on consumer GPUs, which necessitates offloading them onto CPU RAM to perform inference. Given the limited memory bandwidth between the CPU and the GPU, as well as the fact that all model parameters must be transferred to the GPU for the LLM to generate each new token, offloading is extremely slow and bandwidth-bound. For example, generating a single token using Llama 2-70B in 16 bit with offloading on an RTX 3090 GPU takes at least 4.5 seconds 2 .A recent line of work that aims to speed up LLM inference is speculative decoding [Leviathan et al., 2023 , Chen et al., 2023a] , which uses a small draft model to predict the next tokens and a larger target model to verify which of those tokens to accept in parallel. Although speculative decoding is a promising direction, the speedups that existing methods can attain in the offloading setting are relatively modest. While studying existing approaches [Leviathan et al., 2023 , Miao et al., 2023 , Sun et al., 2023] , we discovered that these methods do not scale well with the draft model token budget. In particular, as shown in Figure 1 (left), the number of tokens accepted by the target model is Figure 1 : Acceptance counts vs draft size (left), forward pass GPU time vs input size (right). Llama 2-7B draft model, offloaded Llama 2-70B target model, MTBench dataset, t=0.6 and top-p=0.9. empirically upper-bounded (approximately by 10 for this model and dataset combination) regardless of the number of speculated tokens. In turn, methods that scale better with more draft tokens Chen et al. [2024a] rely on static tree structures that may not be optimal for every setting, as they require tree structure optimization for every change in the text domain, generation parameters, and the hardware setup.In this work, we aim to improve the effectiveness of speculative decoding for running large language models on consumer hardware with RAM offloading. We propose SpecExec, a speculative decoding method that addresses the performance, flexibility and scalability issues of prior methods. SpecExec3 adopts a powerful draft model to deterministically4 construct a large draft tree that covers the most likely continuations of the prefix with a parallel search algorithm. We then apply a simple verification algorithm that views this tree as a cache of potential continuations and validates it with the target model in a single pass.Our main contributions can be summarized as follows:1. We analyze the empirical behavior of speculative decoding algorithms with large language models and identify ways to improve their acceptance rate when scaling to thousands of draft tokens.2. We propose SpecExec -a speculative decoding algorithm that improves the structure of generated draft trees for very large token budgets. We demonstrate that this technique can produce draft trees resulting in 10-20 accepted tokens with sufficiently large budgets.3. Using our observations and SpecExec, we design a system that can run Llama 2-70B or comparable models interactively at 4-6 tokens/second using 4-bit quantization or 2-3 tokens/second with 16-bit weights on consumer GPUs with offloading, with 10-18x speedups compared to sequential inference on the same hardware.2 Background 
speculative decoding: 
 In this study, we extend a family of algorithms for speculative decoding of autoregressive LLMs Stern et al. [2018] , Leviathan et al. [2023] , Chen et al. [2023a] . These algorithms generate tokens in two phases: drafting and verification.During the drafting phase, the algorithm generates a candidate sequence of tokens by sampling from a small draft model P (x t+1 |x 0:t , θ draft ). In turn, the verification stage leverages the target model P (x t+1 |x 0:t , θ main ) to verify these draft sequences and accept all tokens that have passed the verification. The probability of accepting a token is chosen in a way that preserves the output distribution of sequential sampling from the original LLM Leviathan et al. [2023] , Chen et al. [2023a] , Sun et al. [2023] . A key advantage of speculative algorithms is that the main model can verify all draft tokens in parallel, which is more efficient than sequentially generating one token at a time.Subsequent works in speculative decoding extend this idea in several directions, including generating multiple draft sequences or draft trees, using multiple draft models, and finetuning the draft models to improve generation speed Miao et al. [2023] , Liu et al. [2023] , Xu et al. [2023] . Another line of follow-up studies explores alternative sources for the draft model: namely, self-speculative decoding uses a subset of main model layers to produce a draft Zhang et al. [2023] , REST retrieves draft sequences from a search index He et al. [2023] , and staged speculative decoding uses multiple levels of speculation Spector and Re [2023] . Leveraging these techniques, practitioners have built efficient implementations for fast LLM inference [Miao et al., 2023 , Cai et al., 2023] . We refer the readers to survey papers for a more detailed coverage of speculative decoding methods Zhang et al. [2024a] , Xia et al. [2024a] .In our analysis, we focus on speculative decoding algorithms that support sampling from the target model and guarantee identical sample probabilities vs standard generation. The rationale for our choice is that most popular LLM applications (such as chat assistants) require stochastic sampling to introduce variability into their responses. This focus rules out several algorithms that only support greedy inference Fu et al. [2023] , Liu et al. [2023] . Still, most works on speculative decoding fit within that criterion.Another recent line of work explores running and training large models with limited accelerator memory by "offloading" their parameters to more abundant storage, such as RAM or even SSD [Pudipeddi et al., 2020 , Ren et al., 2021 , Alizadeh et al., 2023] . This technique works by loading model parameters on the GPU when they are needed for computation. Since most deep learning models use layers in a fixed order, offloading can pre-dispatch the next layer's parameters in the background.This technique works particularly well when processing large batches of data, during training Pudipeddi et al. [2020] , Ren et al. [2021] or large-batch non-interactive inference Aminabadi et al.[2022], Sheng et al. [2023] , where each layer process multiple tokens each time it is loaded. In turn, when doing interactive inference, offloading works significantly slower than on-device inference. This is because interactive inference has to process one or few tokens at a time, and therefore spends most of the time waiting for the parameters to load.While our observations are not specific to any particular LLM, we focus on a practical case of running modern instruction-tuned models such as Llama-2-70B-chat Touvron et al. [2023] and Mixtral 8x7B Jiang et al. [2024] . To better estimate the target hardware setups, we study communities dedicated to running large models locally, such as LocalLlama [2023] . A popular5 hardware configuration for running those models locally is a desktop or a cloud instance with a single consumer-grade GPU6 with 12-24 GB VRAM, 4-8 CPU cores, 32-64 GB RAM, and a PCIe 3.0 or 4.0 x16 bus between CPU and GPU. Another popular setup is devices without a dedicated GPU, such as MacBooks with an ARM-based CPU, 16 GB RAM, and an SSD. While this survey may not be fully representative, it reveals popular setups that are not targeted by most speculative decoding research.Running the largest language models in this setup requires either extreme compression or offloading. While it is possible to fit 70B+ models into consumer GPUs by compressing them to 1.5-2 bits per parameter Chee et al. [2023] , Tseng et al. [2023] , doing so causes significant accuracy losses that defeat the purpose of running large models Dettmers and Zettlemoyer [2022] , Tseng et al. [2023] . Thus, practitioners with consumer-grade hardware may find it optimal to run 50B+ models with mild (e.g. 4-bit) quantization and offload parameters from GPU to RAM or SSD Alizadeh et al. [2023] . 
preliminary analysis: 
 Speculative decoding with offloading benefits from the fact that it is more efficient to process tokens in parallel than sequentially. In conventional inference, this is caused by the higher arithmetic intensity of GPU processing7 . With offloading, there is a different bottleneck -loading model parameters from storage. Since offloading engines can dispatch model parameters in parallel with computation, the total processing time is the maximum of the time to load all parameters and the total computation time. In preliminary experiments (see Figure 1 , right), we found that 70B models running on a consumer desktop can process thousands of tokens within nearly the same time as just a single token.This leads us to a question: how does speculative decoding perform when given hundreds to thousands of draft tokens? As shown in concurrent work Chen et al. [2024a] , speculative decoding algorithms with single or multiple sequences, like SpecInfer, are effectively upper-bounded in the number of accepted tokens as the speculation budget grows. This is confirmed by our observations (see Figure 1 , left), where the number of accepted tokens saturates even for the more powerful Llama-2 7B.In regular GPU inference, using 7B draft models would be impractical, as the drafting steps would take too long. However, in our setting, large draft models can be justified because each offloaded forward pass takes significantly more than a second (see Figure 1 , right). This runs contrary to a popular intuition in speculative decoding that favors smaller draft models Miao et al. [2023] , Liu et al. [2023] .We also observe that sampling from modern LLMs often results in a few high-probability tokens that add up nearly to a probability of 1 (see Figure 2 for an illustration). If we can find these tokens using the draft model, we can construct a draft that will be accepted with a similarly high probability. In preliminary experiments for 70B models, we found that running beam search with a capable draft model (e.g., Llama-2 7B) can recover many of these high-probability tokens. Unfortunately, this kind of deterministic search is incompatible with speculative decoding for stochastic sampling, which called for alternative validation method. 
speculative execution: 
 As we observed in Section 3, high-probability continuations of large models are concentrated in a few tokens, and offloading benefits from running target model on hundreds or thousands of tokens.To use these observations, we formulate an alternative, simpler speculative decoding strategy. Unlike speculative decoding, SpecExec (short for "Speculative Execution") does not propose a new sampling procedure: it runs standard (sequential) sampling while trying to "guess" which probabilities will be needed during future steps and precomputing these continuations in parallel. This is similar to speculative execution [Lampson, 2006] in modern CPUs that predicts which operations should be computed ahead of time to better utilize the compute cycles.More specifically, whenever SpecExec uses target model probabilities, it looks them up in a speculative "cache". If it encounters a token that is not in the cache, it queries the target model for that token and simultaneously computes probabilities for B potential future tokens chosen with the draft model, where B is the batch size. If the draft model can guess the likely next tokens accurately enough, the algorithm will be able to run multiple sampling iterations using these cached probabilities without querying the target model until it "exhausts the cache" and begins anew. A formal description of SpecExec is given in Algorithm 1.To choose which future tokens should be precomputed, we run a search algorithm with the draft model to find B most likely tokens according to their cumulative probability t P (x t+1 |x 0:t , θ draft ). for x i ∈ τ do 17:x prefix := π(x i , τ ) ▷ prefix in tree τ 18: cache[x prefix ⊕ {x i }] = next_probs[x i ] ▷ probabilities of possible next tokens 19:return cacheThe details of the search algorithm are given in Section 4.2; unlike drafting with regular speculative decoding, this procedure is deterministic and always selects tokens with the highest probability.Comparison to speculative decoding. The core advantage of SpecExec over regular speculative decoding is that the algorithm does not need the draft tree to follow a known probability distribution.In other words, SpecExec produces correct samples with any draft tree, even if it is deterministic. We use this property to construct the best possible speculative tree in ways that would break the assumptions of standard speculative decoding. For instance, our tree construction procedure, outlined in Section 4.2, considers only the most likely draft tokens and aims to capture a larger portion of the total probability mass.However, this advantage comes at the cost of lower acceptance rates for any individual token. Algorithm 1 accepts a token x t with probability P (x t+1 |x 0:t , θ target ), because accepting a token with SpecExec is equivalent to sampling that token from the target model distribution. Meanwhile, the original speculative decoding (for example, Miao et al. [2023] ) accepts tokens with a higher probability P (x t+1 |x 0:t , θ target )/P (x t+1 |x 0:t , θ draft ).For a small number of draft tokens (for instance, just one token), SpecExec is less effective than traditional speculative decoding. However, as we increase the number of draft tokens, speculative execution generates better-structured trees, which in practice leads to accepting more tokens for the same draft size; we verify this in Section 5.2.Correctness. Next, we need to verify that SpecExec is equivalent to sequential sampling from the target model. Notably, unlike Leviathan et al. [2023] , SpecExec does not change the probabilistic sampling procedure. The difference between SpecExec and sequential decoding is that SpecExec precomputes some probabilities, thus improving the GPU utilization in the case of offloading.From a formal perspective, we rely on the fact that a speculative generation algorithm is equivalent to sequential sampling if it is locally equivalent in every node Miao et al. [2023] ; in other words, it samples from the same probabilities for every prefix in the draft tree. Since SpecExec explicitly samples from the same probabilities as the main model, this is true by construction.The fact that SpecExec follows the same sampling procedure has another side effect. If we view SpecExec as a deterministic function that depends on a pseudo-random number generator as input, we can prove a stronger degree of equivalence. Namely, for every seed value of the random number generator, SpecExec produces exactly the same outputs as sequential sampling with the same seed. In contrast, speculative decoding does not have this properly, as it only guarantees correct probabilities for the overall generation procedure.As we discussed above, our algorithm uses the draft model to build a tree τ of likely future tokens for speculative caching. In this section, we describe how to find these tokens efficiently. From an optimization perspective, we seek to construct a tree that will lead to the highest expected number of generated (accepted) tokens. This problem can be solved by viewing the tree construction as the search for the set of nodes (i.e., tokens) that have the highest cumulative probability with respect to the target model. As we show in Appendix A, this search can be reduced to the single-source shortest path (SSSP) search problem that can be solved efficiently using a modified version of the Dijkstra's algorithm Dijkstra [1959] , described formally in Algorithm 2.In summary, SpecExec follows a loop:1. Run Algorithm 2 with the draft model to select K best tokens, 2. Process them with the target model using offloading, 3. Follow Algorithm 1 to determine which tokens are accepted.For a visual high-level representation of the SpecExec algorithm, see Appendix B.While Algorithm 2 is a rather special case of SSSP over a combinatorially large tree (the tree of all token sequences up to length K), the general SSSP problem is well studied in the computer science community (see Appendix C). Therefore, practitioners will be able to leverage existing algorithms to implement Speculative Execution for a broad range of setups, including GPUs, mobile CPUs, or distributed systems. if SIZE(τ ) ≥ K then 18:T := -KTHCUMULATIVELOGPROB(τ, K)▷ ignore tokens that fall outside the budget 19:probs := FORWARD(batch, θ draft ) ▷ run θ draft w/o offloading, attend to past tokens; note: probs is a matrix ∈ R B×vocab 20:topk := SELECTBEST(batch, probs, τ, K) ▷ select best tokens by cumulative probability 21:for(x i , p i ) ∈ topk do 22: log p prefix := CUMULATIVELOGPROB(x i , τ ) ▷ xt∈π(xi,τ ) log P (x t |π(x t , τ, θ draft ))23:nll := -log p prefix -log p i 24:H := INSERT(H, x i , nll)25:H := TRIM(H, K) ▷ remove all except K best 26:return TRIM(τ, K)Finally, we leverage several important technical improvements that speed up inference in real-world conditions. When running the forward pass with an offloaded target model, we accelerate inference by loading the next layer parameters in parallel with computing the previous layer activations using a dedicated CUDA stream, which is known to speed up offloading in other use cases Pudipeddi et al.[2020], Ren et al. [2021] , Aminabadi et al. [2022] . We also preload the first few layers of the target model on the GPU in the background while drafting for a further speedup. We describe additional implementation details in Appendix D.In our experiments, we also consider quantizing target models using recent post-training quantization algorithms Frantar et al. [2022] , Lin et al. [2023] , Dettmers et al. [2023] . While quantization is generally popular among LLM practitioners, it is particularly useful for our use case, as quantized models take less time to load from RAM to GPU and have RAM offloading requirements attainable by consumer hardware. 
probability coverage: 
 The core assumption behind Algorithm 1 is that a reasonably large draft can "cover" most of the high-probability sequences of the target model. This is only possible if the target model predictions have low entropy (i.e., there is a small number of tokens with high probability) and the draft model can guess these tokens most of the time.To test these assumptions in isolation, we measure the total probability mass "covered" by k most likely tokens, as well as the probability of top-k tokens guessed by draft models of varying size. If a certain draft model achieves a coverage probability p for k tokens, this means that taking the k most likely tokens predicted by the draft model and measuring their probabilities with the main model (Llama-2-Chat 70B) would result in an average cumulative probability equal to p. We evaluated multiple draft models of various size: JackFram-160M Miao et al. [2023] , TinyLlama-1.1B-Chat v1.0 Zhang et al. [2024b] , Llama-2-Chat 7B and 13B tou. We report these coverage probabilities on a sample of 512 OpenAssistant conversations Köpf et al. [2023] . For each conversation, we generate 64 additional tokens by sampling from the target 70B model probabilities. We sample these tokens using original probabilities (without temperature or top-p sampling) and use the same tokens for every draft model.The resulting coverage is reported in Figure 2 . This leads to several important observations. First, the target model (Llama-2 Chat 70B) tends to have sharp probability distributions, where the top 1-4 tokens cover 90-98% of the entire probability mass. This agrees with existing observations that language models (esp. the larger ones) are overconfident Miao et al. [2021] , Chen et al. [2023b] .Next, we compare how effective the draft models are at predicting these high-probability tokens. While all models eventually get over 90% coverage rate, Llama-2 Chat 7B makes much more accurate predictions with the first 1-4 tokens. This is important for our use case because, while the full draft tree contains thousands of tokens, individual tokens within that tree have much fewer children.Curiously, the 13B draft model demonstrates roughly the same accuracy as 7B despite its larger size.Though we evaluate coverage for "raw" probabilities from the 70B model, many practical inference scenarios use temperature or nucleus sampling Holtzman et al. [2020] . In fact, thedefault generation parameters for Llama-2 70B use both a temperature of 0.6 and top-0.9 nucleus sampling Face [2024] .Generating in this way makes the model even more confident, which further improves the efficiency of parallel decoding.Next, we study how Speculative Execution compares to existing speculative decoding variants for different token budgets. Since all algorithms guarantee that the tokens are sampled from P (x t+1 |x 0:t , θ main ), we compare them in their ability to generate longest sequences of accepted tokens given the same budget of draft tokens. Since we are interested in very large budgets, we choose baseline algorithms that better fit this task.The original speculative decoding algorithm Leviathan et al. [2023] generates a single sequence, which is truncated as soon as the algorithm rejects a single token. In other words, using a single long draft sequence results in most of the draft budget being wasted. Therefore, as our baseline, we choose the SpecInfer algorithm that shares the large token budget across multiple stems in a tree.Similarly to the previous section, we use 70B versions of Llama 2 and Llama 2-Chat as target models.The draft model choice was driven both by the speed and the acceptance rate factors: we found that using draft models with 7B parameters results in significantly more accepted tokens, and a longer forward pass time is still affordable in the offloading setting. We report the effects of these draft models in more detail in Appendix E.In each setup, we compared SpecExec and SpecInfer, using the 7B draft model, chosen based on our findings from Section 5.1. Figure 3 reports the average number of accepted tokens both for the default sampling configuration (temperature 0.6, top-p 0.9) and for greedy sampling for Llama 2-70B Chat model using the MTBench dataset. Similar tests were run for non-chat models on the C4 dataset; see Figure 4 for results. For smaller draft budgets, SpecExec performs on par with SpecInfer, but eventually outscales it as we increase the number of draft tokens. We attribute this not to the general verification algorithm, but to the fact that SpecExec constructs its draft out of most likely tokens, while SpecInfer must sample draft tokens to guarantee correctness. We also observe that Speculative Execution achieves a higher margin of improvement on MTBench samples than on C4. It also accepts more tokens with a lower temperature. We attribute this to sharper token probability distributions, leading to higher coverage rates for the same number of draft tokens.Finally, we evaluate the practical inference speed of SpecExec by running it with offloading in different hardware configurations. We run these evaluations for Llama 2-70B tou models, both in regular and chat (instruction-tuned) versions. For prompts, we used subsamples of size 100 from OpenAssistant conversations Köpf et al. [2023] , WikiText-2 Merity et al. [2016] , MTBench Zheng et al. [2023] , and C4 Raffel et al. [2020] , measuring the speed of generating 32+ tokens per prompt.For Llama 2, we tested two setups: running the main model in 16 bits or quantizing it to 4 bits using GPTQ Frantar et al. [2022] . We also tested Mixtral 8x7B Jiang et al. [2024] (also quantized with GPTQ) and Llama 3 AI [2024] target models in fewer setups. We measure the inference speed with multiple GPU types: A100 (data-center GPU), RTX 4090 (current generation high-end consumer GPU), RTX 3090 (previous generation consumer GPU), and RTX 2080Ti (older consumer GPU). The first three GPUs are connected to the host via PCIe Gen 4 x16, while 3090 and 2080Ti were tested with PCIe Gen 3 x16. Note that for A100, we report the forward pass time with offloading, even though the GPU can fit a quantized model in its memory. We run all experiments with a batch size of 1 to match the setup of running LLMs on a local machine.The average inference speed (measured in tokens per second) for A100 GPUs is reported in Tables 1 and 2 . While the exact inference speed differs from setup to setup, Speculative Execution consistently speeds up generation with offloading by several times. These results compare favorably with recently published speculative decoding methods using fixed trees like Sequoia Chen et al. [2024b] , which attains 2.2 tokens per second in the Llama 3-8B/70B setup, compared to 2.8 tokens per second in case of SpecExec.In Table 3 , we report the results of similar experiments for a range of real-world consumer GPUs. To reduce the memory requirements for the consumer setup, we replaced a 16-bit Llama-2 70B model with a 4-bit GPTQ compressed variant of Llama-2-70B as the target model. To lower the VRAM requirements for 2080 Ti, we used Sheared-Llama-1.3B Xia et al. [2024b] as a draft model, making the whole experiment consume just over 7 GB of VRAM. Note that while the fastest inference time is achieved on RTX 4090, slower consumer GPUs (for example, RTX 2080Ti) still generate tokens quickly enough for interactive use. We also explore the relationship between the inference speed and the draft tree size. A larger draft budget allows for a greater number of tokens to be generated per step (see Figure 5 (left)). However, beyond a certain size threshold (hundreds or thousands of tokens, depending on the model and GPU), the time required for generation increases at an accelerating rate (see Figure 1 (right)). Consequently, the optimal draft tree size is typically smaller than the size that maximizes the token acceptance rate. According to our findings, displayed in Figure 5 (right), the optimal draft tree size is 128-512 for SpecInfer and 1024-2048 for SpecExec for the A100 GPU. While this was not the primary focus area of our study, the SpecExec method can also deliver competitive speedups in inference without offloading; see Appendix G for sample results. Additional tests of SpecExec in generation with penalties show that the method is robust with such conditions: Appendix H provides the results of such an evaluation.Question: Does the paper provide open access to the data and code, with sufficient instructions to faithfully reproduce the main experimental results, as described in supplemental material?Answer • Providing as much information as possible in supplemental material (appended to the paper) is recommended, but including URLs to data and code is permitted. 
conclusion and future work: 
 In this work, we propose a method for fast inference of large models on consumer GPUs that unites the efficiency of offloading and speculative decoding in the large-budget setup. The resulting method, SpecExec, shows competitive performance in real-world experimental setups, demonstrating the possibility of running large models locally at the speed of interactive inference.Although we developed an offloading system to utilize SpecExec in practical settings, the goal of our study was not to create the fastest possible implementation of local LLM inference. Achieving that goal relies on combining our approach with orthogonal performance improvements proposed in prior work, which is beyond the scope of this paper. Importantly, given the recent trends in hardware accelerators for deep learning, inference of large models may become increasingly more constrained by the memory bandwidth even for the fastest devices. Therefore, optimizing generation time with bandwidth constraints in mind is likely to grow more important in the future, and our work demonstrates a novel approach to that problem.Question: Does the paper specify all the training and test details (e.g., data splits, hyperparameters, how they were chosen, type of optimizer, etc.) necessary to understand the results?Answer: [Yes]Justification: The paper, together with the "Additional Implementation Details" appendix and instructions in the code, contain information on all substantial details necessary to understand the results.Guidelines:• The answer NA means that the paper does not include experiments.• The experimental setting should be presented in the core of the paper to a level of detail that is necessary to appreciate the results and make sense of them. • The full details can be provided either with the code, in appendix, or as supplemental material. 
experiment statistical significance: 
 Question: Does the paper report error bars suitably and correctly defined or other appropriate information about the statistical significance of the experiments?Answer: [No] Justification: Following the setting of the past papers in the speculative decoding area, we focus on providing the attained generation speed and acceptance rates.Guidelines:• The answer NA means that the paper does not include experiments. Justification: In the paper and in the "Additional Implementation Details" appendix, we list the GPU types used and indicative memory requirements.Guidelines:• The answer NA means that the paper does not include experiments.• The paper should indicate the type of compute workers CPU or GPU, internal cluster, or cloud provider, including relevant memory and storage. • The paper should provide the amount of compute required for each of the individual experimental runs as well as estimate the total compute. • The paper should disclose whether the full research project required more compute than the experiments reported in the paper (e.g., preliminary or failed experiments that didn't make it into the paper). 
code of ethics: 
 Question: Does the research conducted in the paper conform, in every respect, with the NeurIPS Code of Ethics https://neurips.cc/public/EthicsGuidelines?Answer: [Yes] Justification: Yes, we confirm adherence to the NeurIPS Code of Ethics.Guidelines:• The answer NA means that the authors have not reviewed the NeurIPS Code of Ethics.• If the authors answer No, they should explain the special circumstances that require a deviation from the Code of Ethics. • The authors should make sure to preserve anonymity (e.g., if there is a special consideration due to laws or regulations in their jurisdiction). 
broader impacts: 
 Question: Does the paper discuss both potential positive societal impacts and negative societal impacts of the work performed? Answer: [NA] Justification: This paper studies the efficient inference of large language models on accelerators with limited memory. Importantly, using LLMs in these environments is already possible due to a considerable number of previously proposed algorithms, as the research area is well-known within the machine learning community. The method we propose does not affect the task performance of the language model it is applied to, as it only improves the speed of generation with that model. Therefore, we feel that no potential consequences of LLM use (aside from those already discussed in past work) need to be specifically highlighted in our paper. Guidelines:• The answer NA means that there is no societal impact of the work performed.• If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact. • Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations. • The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster. • The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology. • If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML). 
safeguards: 
 Question: Does the paper describe safeguards that have been put in place for responsible release of data or models that have a high risk for misuse (e.g., pretrained language models, image generators, or scraped datasets)? Answer: [NA] Justification: This paper does not alter the capabilities of the available models or datasets, but rather provides a more efficient approach to use them on hardware with limited capabilities. Thus, we believe that our paper has a neutral risk impact in this area. Guidelines:• The answer NA means that the paper poses no such risks.• Released models that have a high risk for misuse or dual-use should be released with necessary safeguards to allow for controlled use of the model, for example by requiring that users adhere to usage guidelines or restrictions to access the model or implementing safety filters. • Datasets that have been scraped from the Internet could pose safety risks. The authors should describe how they avoided releasing unsafe images. • We recognize that providing effective safeguards is challenging, and many papers do not require this, but we encourage authors to take this into account and make a best faith effort. 12. Licenses for existing assets • We recognize that the procedures for this may vary significantly between institutions and locations, and we expect authors to adhere to the NeurIPS Code of Ethics and the guidelines for their institution. • For initial submissions, do not include any information that would break anonymity (if applicable), such as the institution conducting the review. 
 
 Appendix: We can formulate this problem as follows:EQUATIONHere, x i ∈ τ refers to a token within the draft tree, T K is a set of all trees of K tokens and P reach (x i |τ ) is the probability that the Speculative Execution verification phase accepts the full prefix x 0 , . . . , x i-1 along the draft tree and considers sampling x i next. Finally, P accept (x i |τ ) is the probability that the token x i will be accepted if it is reached during verification. Both P reach and p accept depend on the target model probabilities P (x t+1 |x 0:t , θ target ), which cannot be accessed in the drafting phase. Instead, we use the draft model to approximate the target model probabilities as follows:EQUATIONwhere π(x i , τ ) is the path in τ from root to x i , excluding x i itself. From the LLM perspective, π(x i , τ ) is the prefix for a token x i within the draft tree. If we multiply the two expressions as per Equation 1, we get the cumulative probability of a sequence π(x i , τ ) ⊕ x i , where ⊕ is concatenation.EQUATIONSince token probabilities cannot be greater than 1, the cumulative probability of π(x i , τ ) ⊕ x i cannot exceed the cumulative probability of all tokens in π(x i , τ ). Therefore, if a token x i is among the K most likely tokens, every token in π(x i , τ ) is also a part of the solution. Using this property, we can simplify Equation 3 as finding top-K most likely prefixes, since they are guaranteed to form a tree. Formally speaking, the optimal tree consists of K tokens with the highest cumulative probability:arg top K xi xt∈π(xi,τ )⊕xi P (x t |π(x t , τ ), θ draft ) (4)This is similar (but not equivalent) to the standard beam search algorithm for neural sequence models Graves [2012] , Boulanger-Lewandowski et al. [2013] , Sutskever et al. [2014] . The main difference is that beam search looks for complete sequences, while we need a tree of partial drafts. However, using beam search instead of solving Equation 3 directly leads to suboptimal drafts (see Appendix F for details).Instead, we solve Equation 4 by reformulating it as a special case of the shortest path search problem. More specifically, arg maxxi xt∈π(xi,τ )⊕xi P (x t |π(x t , τ ), θ draft ) = = arg max xi xt∈π(xi,τ )⊕xi log P (x t |π(x t , τ ), θ draft ) = = arg min xi xt∈π(xi,τ )⊕xi -log P (x t |π(x t , τ ), θ draft ).(5)Note that every term in that sum is non-negative, (since -log P (x t |π(x t , τ ), θ draft ) ≥ 0), which makes this equivalent to a single-source shortest path (SSSP) problem for finding paths to K nearest nodes in a graph with non-negative edge weights. Normally, this problem can be solved by running the Dijkstra algorithm for K steps. However, in practice, running the algorithm for K sequential steps is inefficient on modern highly parallel hardware, especially in our setting with very large drafts.To alleviate this problem, we use a modified parallel Dijkstra algorithm, which expands B > 1 nodes on every iteration and keeps track of K nearest nodes in a priority queue. We describe this formally in Algorithm 2.In the worst case, this algorithm still makes up to K steps if the solution to Equation 3 is a single "stem" B tokens long. However, the actual number of steps is significantly lower, often slightly above the lower bound ⌈B/K⌉. In the practical GPU implementation, we also limit the maximum depth with a parameter D. The purpose of D is to limit the edge case where the draft model is very confident about the next token, and thus the solution to Equation 3 is a single sequence of length K. For this edge case, Algorithm 2 will take long to generate a sequential draft, most of which will later be discarded if the draft model makes even one mistake. There are dozens of works that study practical implementations of parallel shortest path search and SSSP in particular. One line of work proposes inexact search algorithms that use an approximate priority queue to improve the performance of SSSP: Nguyen et al. [2013] proposes a queue with an integer metric, and Zhang et al. [2020] adds bucket fusion to reduce the synchronization overhead..A significant effort was dedicated to efficient shortest-path search on GPUs, among others. Harish and Narayanan [2007] proposes a GPU-efficient SSSP that outperforms sequential CPU computations. Davidson et al. [2014] , Wang et al. [2016] compare several SSSP variants for GPUs. Iacono et al. [2019] adapts priority queues to run efficiently on GPU and uses the resulting data structure to accelerate SSSP.Many works on parallel graph search focus on the distributed setting Malewicz et al. [2010] , Zhu et al. [2016] , Besta et al. [2017] , addressing communication and synchronization overheads. Finally, a large body of work studies the theoretical properties of parallel SSSP, including Ullman and Yannakakis [1990] , Klein and Subramanian [1997] , Cohen [1993] , Shi and Spencer [1999] , Cohen [2000] , Spencer [1997] , Meyer [2001 ], Blelloch et al. [2016] .Our system design follows the following loop:1. Load the draft model onto GPU memory and generate a draft tree;2. Load the main model (several layers at a time, if using offloading) to compute probabilities for the draft tree tokens;3. Choose the accepted tokens following the verification procedure.When running the main model, we process all draft tokens in parallel by constructing a merged attention mask, similar to Miao et al. [2023] . We prefetch the first few layers of the main model during speculation to speed up the procedure. We also load subsequent LLM layers in parallel, while the previous layers compute their activations, as described in Pudipeddi et al. [2020] , Aminabadi et al.[2022].Finally, we keep the past key/value caches of both draft and main models in GPU memory at all times. We chose this because most modern language models use grouped-query attention Ainslie et al. [2023] , making caches relatively small for short prompts. When dealing with longer prompts or smaller GPU memory, one can reduce memory usage by offloading these KV caches into RAM. The draft model caches are only needed on GPU during the first stage when generating the draft tokens.In turn, the main model caches can be loaded alongside their transformer layers.The optimal implementation of this algorithm is slightly different depending on the hardware configuration. Running SpecExec on a system with GPU with RAM offloading works best with relatively fewer draft tokens, while longer offloading (to SSD or when using float16 precision weights) works best with larger token budgets.As for the quantization scheme, while there are better quantization algorithms Lin et al. [2023] , Dettmers et al. [2023] , Chee et al. [2023] , we chose GPTQ since it is popular among practitioners. Still, we believe that our experimental results will generalize to other quantization algorithms. In addition to the main model, we also quantize the draft (7B) model using the same GPTQ algorithm.The optimal choices of the quantization methods will vary as new methods or faster implementations appear.The experiments were mainly performed using A100 GPUs (unless specified otherwise), but may be easily reproduced using other GPUs. Note that while A100 has 80GB VRAM, we did not keep any layers in VRAM in order to keep the VRAM use to minimum and emulate performance of GPUs like RTX4090 or L40. A s a result, the observed VRAM use requirements with offloading was in 12-22 GB range for experiments with draft trees up to 2048 tokens when using Llama-2-70B RAM offloading. Naturally, keeping some of the layers constantly in VRAM would increase both baseline and the model performance.The offloading experiments require sufficient RAM to hold whole model. In case of Llama-2-70B in 16 bit, this is at least 140 GB, but in practice 192 GB would be recommended to fit the draft model, caches and memory of other processes. Our code is based on industry standard PyTorch Paszke et al.[2019] and Transformers Wolf et al. [2019] libraries.In Section 5.2, we evaluate SpecExec and SpecInfer with 7B draft models based on the observations about their coverage probabilities. Here, we further compare these models in terms of the number of accepted tokens for different SpecExec batch sizes. We report the results of this comparison in Figure 7 using the same OpenAssistant dataset as in the main experiments using the recommended temperature (0.6) and nucleus size (0.9). Similarly to Figure 2 , the 7B model significantly outperforms both JackFram/llama-160m and TinyLlama 1.1B Chat. This is true both for the original 7B model and the one quantized to 4 bits with GPTQ. Curiously, the full unquantized 13B model still obtains slightly more accepted tokens, though at the cost of 26GB memory footprint that is inaccessible to modern consumer GPUs. In our preliminary experiments, we tried to construct the optimal draft tree using top-k beam search decoding Graves [2012] . However, we observed that the algorithm performed significantly worse than expected and often plateaued as we increased the maximum beam search length. Here, we describe the analysis of this problem that eventually led us to Algorithm 2. Figure 8 (left) reports a grid where each cell is the number of accepted tokens for a version of SpecExec that uses beam search instead of parallel SSSP. The horizontal grid axis corresponds to beam size (also known as the number of beams), and the vertical axis depicts maximum length within a beam. The left grid shows standard beam search decoding that returns beam size most likely sequences. In turn, the right grid uses a modified search algorithm that starts the same way as beam search but does not prune any partial hypotheses that did not make it into the final beam.As we can see, standard beam search decoding is suboptimal for SpecExec in the sense that it can be outperformed with trivial modifications. In turn, Algorithm 2 is a generalization of the version on the right that does not need to be manually tuned for length and width, but instead expands the graph optimally to maximize the coverage probability.While this was not the primary focus area of our research, the SpecExec method can also deliver measurable speedups in inference without offloading. While these speedups are less impressive than those for offload settings, they are still competitive when compared to recent works such as Chen et al. [2024a] . To verify the method's robustness, we ran a series of experiments with penalties excluding the use of specific tokens. The same penalty scheme was applied to both draft and target models, and the expectation is that the models should be able to run SpecExec effectively. To verify this claim, we ran a series of experiments with penalties excluding use of fewer or more tokens. For these experiments, we penalized all tokens that start from the letter "r" (left) or all tokens that contain the letter "r" (right). Here we used the Llama 2-7B Chat target model with TinyLlama-1.1B Chat draft model, t=0.6, p=0.9, MT-Bench dataset.The results of these experiments can be found in Figure 9 . We found that our method's performance (measured in terms of accepted tokens per iteration) stays stable only with lightweight penalties, yet heavier penalties reduce the absolute speedups. Looking at the generated samples, we observed that while with lighter penalties, the model is able to work around the restrictions and generate reasonable text, with heavier penalties the quality deteriorated as the model skipped or replaced tokens seemingly at random. Stronger penalties affect the quality of the generated text and naturally make the task harder for the draft model. Thus, we attribute the lower performance with a heavy penalty to this perplexity increase rather than to the penalty directly. Figure 9 : Acceptance rate in generation with token penalty: "don't start words with "R"" (left) and "don't use the letter "R"" (right); Llama 2 7B Chat (+ TinyLlama-1.1B Chat draft) model (t=0.6, p=0.9), MT-Bench dataset. The rest of the experimental configuration is the same as in Figure 1 . (d) We recognize that reproducibility may be tricky in some cases, in which case authors are welcome to describe the particular way they provide for reproducibility.In the case of closed-source models, it may be that access to the model is limited in some way (e.g., to registered users), but it should be possible for other researchers to have some path to reproducing or verifying the results.We chose this name because our method directly applies speculative execution to LLM inference. The draft model "guesses" which token prefixes the target model will need to continue, and then the target model computes distributions of continuations with a single forward pass on the speculated prefix tree.In contrast, speculative sampling requires stochastic generation of the draft tree using draft probabilities.Based on popular hardware guides such asDettmers [2023] as well as setups examples (see A, B, C, D)For example, RTX 4060 or 4090 desktops, T4 or A2 VMs.Parallel matrix multiplications do more useful computations per memory access for multiple tokens. 


Decision: The paper has an Average Rating: 5.75 (Min: 5, Max: 7) and is slightly above the acceptance threshold. While there are various issues, all reviewers have given positive evaluations. Considering the following strengths, I recommend acceptance(poster).

1: SpecExec offers a method that enables large LLMs to operate efficiently on consumer-grade GPUs. Even on consumer hardware, it achieves more than a tenfold speed improvement when combined with offloading, making LLMs more accessible and practical by enhancing their accessibility and usability.

2: The proposed method consistently shows higher speed improvements compared to existing SpecInfer methods, especially when processing large numbers of tokens in parallel. Significant improvements in actual computation time have also been confirmed.

3: SpecExec extends existing inference methods by utilizing Dijkstra’s algorithm to construct more efficient token trees, allowing multiple tokens to be verified simultaneously. This significantly improves speed while maintaining the same output as sequential sampling.

4: The SpecExec algorithm leverages techniques adapted from CPU architecture, making it robust and applicable to a broader range of computing environments and models in the future. It is particularly well-regarded for its applicability to scenarios where inference speed is critical.

Reviews: review: paper_summary: paper_summary: This work introduces SpecExec, an improved speculative decoding method.

By constructing a better draft token tree and refining the process of verifying tokens, SpecExec significantly increases the number of tokens accepted in a single verification while producing exactly the same outputs as sequential sampling from the target model.

Additionally, SpecExec leverages the capability of modern offloading engines to dispatch model parameters in parallel with computation, successfully achieving effective acceleration under offloading configurations.

Experiments demonstrate that SpecExec can run a 70B model on consumer-grade GPUs and achieve up to 10.6 times acceleration.
strength_weakness: strength_weakness: 1. While SpecExec achieves significant performance acceleration in systems with offloading, it is unclear how this method performs in terms of acceleration in speculative inference systems that do not have offloading.
questions: questions: 1. In Line 14 of Algorithm 1, "next_probs := FORWARD(τ, θ_target)", how is forward inference performed on the draft tree? Is it the same method used in SpecInfer?

2. The paper lacks clear illustrations of the working process of SpecExec. Could additional diagrams be added to provide a more vivid explanation?

3. The paper mentions several articles related to speculative decoding but lacks an introduction to these works and does not explain the differences between them. Adding this background could help readers better understand this paper and it's contribution.
limitations: limitations: The authors have not adequately discussed the limitations of this paper.
paper_summary: paper_summary: The authors present a method to improve the efficiency of speculative decoding on consumer-grade hardware. The technique addresses the inefficiencies of existing speculative decoding approaches when applied to devices with limited GPU memory, necessitating parameter offloading to RAM or SSD. SpecExec leverages a powerful draft model to create a speculative tree of potential token continuations, which the target model then verifies. This approach enables the processing of multiple tokens in parallel, significantly improving the inference speed on consumer GPUs.
strength_weakness: strength_weakness: 1. Some experiment results are a bit confusing. For instance, the captions in Figure 3/4 say Generation rate vs draft size for Llama 2-7B/70B models, but it's not clear where the 7B model numbers are. The main text states the plots are for 70B models. 

2. The authors claim they have results on both base and chat models. But it's not clear from the tables and figures, which are chat models and which are base models. And further, whether this would lead to different results/conclusions.
questions: questions: My questions are mainly regarding the experiment details discussed above in the weakness section.
limitations: limitations: Yes, the authors adequately addressed the limitations and, if applicable, potential negative societal impact of their work.
paper_summary: paper_summary: In this paper, the authors propose a speculative decoding technique, SPECEXEC (Speculative Execution), that can generate up to 20 tokens per iteration for the LLaMA-2 70B model. SPECEXEC enables the LLaMA-2 70B model to run on a consumer GPU by a parallel decoding strategy. The offloading scheme can process thousands of tokens using the same latency as that of one token. Therefore, the offloading scheme can be naturally used in supporting speculative decoding. However, prior speculative decoding techniques do not scale with a large batch of draft tokens. SPECEXEC uses a smaller draft model to built a tree of best tokens by single-source shortest path (SSSP) searches, and then processes best tokens with the target model by offloading. SPECEXEC also includes a new algorithm to determine which tokens are accepted.
strength_weakness: strength_weakness: 1. The paper is not well-written. SPECEXEC is built on a important observation that the offloading of the target model can process thousands of tokens using the same latency as that of one token. SPECEXEC suffers from a lower acceptance rate for individual tokens. For a small number of draft tokens, SpecExec is less efficient than speculative decoding. However, for a large enough number of draft tokens, SpecExec obtains a better tree and increases the accept rate. SPECEXEC adopts the offloading technique to mitigate the processing of the  large enough number of draft tokens. Unfortunately, the authors did not justify the applications or user cases that must use the offloading schemes.
questions: questions: 1. What type of applications are more suitable for SpecExec? The applications have not enough server-level GPUs?
limitations: limitations: no limitation.
paper_summary: paper_summary: This paper presents a novel speculation decoding method called SpecExec, designed to improve the performance of large language model (LLM) inference on consumer-level GPUs with offloading scenario. The main contribution is the application of speculative execution, a technique from CPU architecture, to the speculation decoding of LLMs. SpecExec leverages a draft model to construct a large draft tree of potential continuations, which are then verified in parallel by the target model. This approach aims to mitigate the inefficiencies of existing speculative decoding methods, particularly when dealing with a large number of draft tokens. The experiments result demonstrate that SpecExec achieves up to 18.7x speedup.
strength_weakness: strength_weakness: - Although the paper targets consumer-level GPUs, the experiment results show that SpecExec achieves the highest speedup with the A100 GPU, one of the most popular datacenter-level GPUs.
- Token throughput is still slow because of the offloading. For A100 GPU, using 4-bit quantized 70B model (AWQ, GPTQ, ...) and without speculative decoding will be more practical.
- SpecExec seems plausible only for single request with single user.
questions: questions: - How much speedup does SpecExec gain without RAM offloading? For example, Llama2-70b chat GPTQ model on an A100 GPU. I am just curious
- So, if I understood correctly, sampling parameters such as t = 0.6, p = 0.9 do not affect the draft tree, right? (deterministic tree)
- In Figure 3 and 4, random sampling results are comparable with greedy sampling on the MTBench dataset while the C4 dataset shows lower hit ratio on random sampling. Does this difference come solely from the difference between datasets?
- Can SpecExec achieve high performance gain on token penalty scenarios? For example, repetition penalty, presence penalty, and frequency penalty.
limitations: limitations: No additional limitations regarding societal impact.
For technical limitations, I stated in the weakness section.