Efficient Inference for Large Language Model-based Generative Recommendation

## Abstract

Abstract Large Language Model (LLM)-based generative recommendation has achieved notable success, yet its practical deployment is costly particularly due to excessive inference latency caused by autoregressive decoding.
For lossless LLM decoding acceleration, Speculative Decoding (SD) has emerged as a promising solution.
However, applying SD to generative recommendation presents unique challenges due to the requirement of generating top- K 𝐾 K italic_K items ( i.e., K 𝐾 K italic_K distinct token sequences) as a recommendation list by beam search. This leads to more stringent verification in SD, where all the top- K 𝐾 K italic_K sequences from the target LLM must be successfully drafted by the draft model at each decoding step.
To alleviate this, we consider 1) boosting top- K 𝐾 K italic_K sequence alignment between the draft model and the target LLM, and 2) relaxing the verification strategy to reduce trivial LLM calls.
To this end, we propose an alignment framework named AtSpeed , which presents the AtSpeed-S optimization objective for top- K 𝐾 K italic_K alignment under the strict top- K 𝐾 K italic_K verification. Moreover, we introduce a relaxed sampling verification strategy that allows high-probability non-top- K 𝐾 K italic_K drafted sequences to be accepted, significantly reducing LLM calls.
Correspondingly, we propose AtSpeed-R for top- K 𝐾 K italic_K alignment under this relaxed sampling verification.
Empirical results on two real-world datasets demonstrate that AtSpeed significantly accelerates LLM-based generative recommendation, e.g., near 2 × \times × speedup under strict top- K 𝐾 K italic_K verification and up to 2.5 × \times × speedup under relaxed sampling verification.
The codes and datasets will be released in the near future.

## 1 Introduction

Large Language Model (LLM)-based generative recommendation has achieved remarkable performance, emerging as a promising avenue and attracting widespread attention (Bao et al., ; Rajput et al., ).
Technically speaking, LLMs encode the user’s historical interactions, and then perform multiple LLM calls (*i.e., *forward processes of LLMs) autoregressively to decode top-$K$ ranked items as recommendations (Zheng et al., ).
Despite the effectiveness, the inference of LLM-based recommender models is unaffordably time-consuming, hindering real-world deployments (Cui et al., ).
Such intolerable time consumption primarily arises from the decoding process as shown in Figure 1(a), where multiple serial LLM calls are required for step-by-step autoregressive generation (Leviathan et al., ; Cai et al., ).
In light of this, it is essential to achieve lossless LLM decoding acceleration for LLM-based generative recommendation.

To accelerate the LLM decoding losslessly, Speculative Decoding (SD) (Leviathan et al., ; Xia et al., ) has been proposed as a promising approach in Natural Language Processing (NLP). SD utilizes a draft model (*e.g., *a compatible small-sized language model) to reduce the number of target LLM calls in the decoding process (Miao et al., ).
Technically, SD follows a draft-then-verify paradigm (Xia et al., ), which first efficiently drafts multiple subsequent tokens by a draft model, and then verifies the drafted tokens in parallel by the target LLM in a single call.
As depicted in Figure 1(b), tokens are either accepted or rejected, with the accepted tokens up to the first rejection step being utilized for subsequent decoding.
As such, the number of LLM calls can be reduced by leveraging the accepted tokens from the draft model, thereby improving the decoding efficiency.

However, it is non-trivial to apply SD for LLM-based generative recommendation due to the challenge of more stringent $N$-to-$K$ verification.
Specifically, traditional SD for NLP tasks typically follows an $N$-to-1 verification to generate only one response, which requires accepting a single token out of $N$ drafted tokens at each step (Figure 1(b)).
In contrast, recommendation tasks necessitate generating top-$K$ items (*i.e., *$K$ distinct token sequences) through beam search,
resulting in an $N$-to-$K$ verification problem (Figure 1(c)).
For each verification step, one LLM call can be skipped if and only if all the top-$K$ sequences are successfully drafted from the $N$ candidates.
To elaborate, SD fails to reduce target LLM calls in Figure 1(c) since $a_{3}$ is not drafted in the first step.
As such, the $N$-to-$K$ verification poses greater challenges than $N$-to-1 verification as each step requires drafting all the top-$K$ sequences.

To achieve effective SD for LLM-based generative recommendation, we formulate the SD task under the $N$-to-$K$ verification.
To reduce the target LLM calls under $N$-to-$K$ verification, we consider two objectives in the drafting and verification steps of SD: 1) top-$\bm{K}$ alignment, which aims to align the drafted sequences with the top-$K$ sequences generated by the target LLM, thereby maximizing the recall of all top-$K$ sequences;
and 2) verification relaxation, which seeks to ease the strict matching with the top-$K$ sequences from the target LLM, enhancing the acceptance rate of drafted sequences while maintaining the accuracy of top-$K$ recommendations.

Figure: Figure 1: (a) The inference time costs of LC-Rec (Zheng et al., ) with LLaMA-7B on a single A5000 GPU. (b) The illustration of the $N$-to-1 verification of SD with greedy decoding in NLP tasks. (c) $N$-to-$K$ verification of SD with beam search in recommendation tasks, where the drafting length, candidate number $N$, and beam size $K$ are set at 3 for illustration.
Refer to caption: x1.png

To this end, we propose an Alignment framework for Speculative decoding (AtSpeed) tailored for LLM-based generative recommendation.
First, under the strict top-$K$ verification, we propose an optimization objective named AtSpeed-S to train the draft model. AtSpeed-S improves the top-$K$ alignment theoretically by minimizing the Reverse Kullback-Leibler Divergence (RKLD) (Huszár, ) and a probability density regularization term (see Section 3.1).
Moreover, for verification relaxation, we introduce a relaxed sampling verification strategy that allows the non-top-$K$ drafted sequences with high generation probabilities to be accepted. To maintain recommendation accuracy, this verification strategy ensures that the generation distribution of SD is approximately equivalent to that of the target LLM with sampling-based beam search (see Section 3.2).
Under the relaxed sampling verification, we design AtSpeed-R for top-$K$ alignment, which minimizes the Total Variance Distance (TVD) on the generation probabilities of top-$K$ sequences (see Section 3.2).

We conduct extensive experiments using both verification strategies on two real-world recommendation datasets, demonstrating that AtSpeed significantly accelerates the decoding for LLM-based recommendation (around 2$\times$ speedup). Besides, the results confirm that the relaxed sampling verification strategy substantially improves decoding efficiency without sacrificing much recommendation accuracy.
The contributions of this work are summarized as follows:

- •
We are the first to propose the speculative decoding task for LLM-based recommender acceleration, highlighting the significant challenge of shifting from $N$-to-$1$ verification to $N$-to-$K$ verification.
- •
We propose a novel alignment framework named AtSpeed for speculative decoding under $N$-to-$K$ verification, with a relaxed sampling verification strategy for verification relaxation and two alignment objectives for superior top-$K$ alignment of draft models.
- •
We conduct extensive experiments on two datasets, which 1) demonstrate the verification efficiency and accuracy of the relaxed sampling verification strategy; and 2) validate that AtSpeed achieves almost 2$\times$ speedup for LLM-based recommender decoding.

## 2 Task Formulation

LLM-based Generative Recommendation.
In LLM-based generative recommendation, each item is represented by an item identifier, *i.e., *a token sequence such as item title (Bao et al., ) or learnable token sequence (Zheng et al., ), linking the recommendation items to the language space for LLMs to understand user behaviors and recommend items (Lin et al., ).
Formally, given the user’s historical interactions $\bm{x}$, the well-trained target LLM-based recommender model $\mathcal{M}_{p}$ generates top-$K$ ranked items via beam search, *i.e., *$\{\bm{y}_{L,i}\}_{i=1}^{K}\leftarrow\mathcal{M}_{p}(\bm{x})$, where $\bm{y}_{L,i}=(y_{1},y_{2},\dots,y_{L})_{i}$ is the item identifier of the $i$-th recommended item of length $L$(^1^11We follow the widely used codebook-based item identifier, due to its promising results and generalization ability on cold-start items (Wang et al., ; Rajput et al., ). The codebook-based identifier will ensure each item has an identifier of the same length.).
However, the LLM inference is time-consuming due to the need to perform multiple LLM calls (*i.e., *forward process) during autoregressive generation.
To accelerate the LLM inference, we are motivated to leverage SD for LLM-based generative recommendation for its decoding acceleration without losing accuracy.

Figure: Algorithm 1 SD step with Top-K Strict Verification

SD for LLM-based Recommendation.
The challenge of applying SD to LLM-based generative recommendation with beam search lies in the shift from $N$-to-$1$ to the harder $N$-to-$K$ verification.
In the following, we detail the draft-then-verify paradigm under the strict top-K verification and formulate the task of SD for LLM-based generative recommendation under $N$-to-$K$ verification.

- •
Drafting. Given the user’s historical interactions $\bm{x}$ and the generated sequences in the previous SD step $\mathcal{Y}_{t}=\{\bm{y}_{t,i}\}_{i=1}^{K}$, a
compatible small-sized draft model $\mathcal{M}_{q}$ is used to generate the drafted beam sequences for $\gamma$ steps via beam search with the beam size of $N$:
$\displaystyle{q}_{t+1},{q}_{t+2},\dots,$
$\displaystyle q_{t+\gamma}\leftarrow\text{BeamSearch}(\bm{x},\mathcal{Y}_{t},
\mathcal{M}_{q}),$
(1)
$\displaystyle{\mathcal{Y}}^{q}_{t+1},{\mathcal{Y}}^{q}_{t+2},\dots,{\mathcal{Y
}}^{q}_{t+\gamma}$
$\displaystyle\leftarrow\text{Top}N(q_{t+1}),\text{Top}N(q_{t+2}),\cdots,\text{
Top}N(q_{t+\gamma}),$
where ${q}_{t+j}$ with $j\in\{1,\dots,\gamma\}$ is the sequence probability distribution at step $j$ obtained by the beam search of draft model; and $\mathcal{Y}^{q}_{t+j}$ collects the top-$N$ drafted sequences with highest probabilities.
The drafted sequences are then fed into the target LLM $\mathcal{M}_{p}$ to obtain the target sequence probability ${p}_{t+1},{p}_{t+2},\dots,{p}_{t+\gamma+1}$,
where ${p}_{t+j}=\mathcal{M}_{p}(\mathcal{Y}_{t+j}^{q})$ with $j\in\{0,\dots,\gamma\}$.
Target LLM $\mathcal{M}_{p}$ then select the sequences with top-K probabilities as ideal sequences, *i.e., *$\mathcal{Y}_{t+j}^{p}\leftarrow\text{Top}K({p}_{t+j})$.
For simplicity, we omit the subscript $t$
and use ${q}_{j}$, ${p}_{j}$, ${\mathcal{Y}}^{q}_{j}$, and ${\mathcal{Y}}^{p}_{j}$ as shorthand for ${q}_{t+j}$, ${p_{t+j}}$, ${\mathcal{Y}}^{q}_{t+j}$, and ${\mathcal{Y}}^{p}_{t+j}$, respectively, in contexts where the exact value of $t$ is not essential.
- •
Strict Top-K Verification.
For every beam search step $j$, we have $N$ drafted sequences $\mathcal{Y}_{q}$(^2^22We denote $\mathcal{Y}_{j}^{p}$ and $\mathcal{Y}_{j}^{q}$ with $\mathcal{Y}_{p}$ and $\mathcal{Y}_{q}$, respectively, whenever step $j$ is clear.) and $K$ ideal sequences $\mathcal{Y}_{p}$.
We define the step acceptance as successfully drafting all the top-K ideal sequences for that step.
Formally, the beam search step is accepted if $\mathcal{Y}_{p}\in\mathcal{Y}_{q}$.
Otherwise, we reject the step, and discard the whole drafted sequences $\mathcal{Y}_{q}$ and correct it with $\mathcal{Y}_{p}$.
From beam search step $j=1$ to $j=\gamma$, we sequentially verify $\mathcal{Y}_{q}$ until the first rejection step occurs.
The corrected sequences $\mathcal{Y}_{p}$ at the first rejection step will be the output of the current SD step.
If every step is successfully accepted, we select top-K sequences from ${p}_{\gamma+1}$ as the output of the current SD step.
The target LLM calls for all previously accepted steps could be reduced as they are successfully skipped through a single LLM call via parallel verification.
The process of strict top-K verification is presented in Algorithm 1.

It is highlighted that SD for beam search under $N$-to-$K$ verification is more difficult than $N$-to-$1$ verification because an LLM call can be skipped if and only if the
top-$K$ sequences are entirely drafted.
To improve the acceptance rate of the drafted sequences to reduce the LLM calls, we have two key considerations:
1) top-$K$ alignment, which encourages the draft model to generate strongly aligned top-$K$ sequences; and
2) verification relaxation, which seeks to relax the strict matching for greater acceleration without much accuracy sacrifice.

## 3 AtSpeed

To pursue the two objectives, we propose AtSpeed, an alignment framework for SD under $N$-to-$K$ verification.
AtSpeed designs two effective alignment objectives for the draft model to get a higher acceptance rate under the strict top-K verification (Section 3.1) and the proposed novel relaxed verification (Section 3.2).
The overview of AtSpeed is presented in Figure 2.

Figure: Figure 2: Overview of AtSpeed. (a) shows the alignment training of the draft model with an additional alignment loss tailored for different verification strategies, *e.g., *$\mathcal{L}_{\text{Align-R}}$. (b) depicts the AtSpeed inference, where the well-trained draft model produces beam search sequences from each step, *i.e., *${\mathcal{Y}_{j}^{q}}$, for the target LLM to verify. The beam sequences from the last accepted step before encountering the first rejection are utilized in the following SD step, *i.e., *$\mathcal{Y}_{2}^{q}$. (c) demonstrates the tree-based attention for the drafted beam sequences ($N$=2 and $\gamma$=3).
Refer to caption: x2.png

### 3.1 Alignment for Strict Top-K Verification (AtSpeed-S)

Under strict top-$K$ verification,
the draft model is expected to generate top-K sequences that strictly align with the top-ranked sequences from the target LLM.
To achieve this, we design an optimization objective named AtSpeed-S that directly optimizes the acceptance rate for the strict top-$K$ verification.

Acceptance Rate.
We define the acceptance rate $\beta$ as the probability of the step acceptance, *i.e., *accepting
all the top-$K$ ideal sequences from
the draft sequences $\mathcal{Y}_{q}$.
With strict top-K verification strategy, for each step, we have $\beta=1$ if ${p}({\bm{y}})\geq{p}(\bm{y}_{K})$ for $\forall\bm{y}\in\mathcal{Y}_{q}$, where $\bm{y}_{K}$ is the sequence that has the K-th highest probability in ${p}$.

Alignment Objective.
Since the acceptance rate directly affects the acceleration performance,
we aim to optimize the acceptance rate of the draft model to achieve superior top-$K$ alignment with the target LLM.
To elaborate, we consider the following alignment objective for the draft model $\mathcal{M}_{q}$:

$$ $\displaystyle\theta^{*}$ $\displaystyle:=\mathop{\arg\max}_{\theta\in\Theta}\quad\mathbb{E}_{\bm{y}\sim \mathcal{Y}_{q_{\theta}}}\frac{p(\bm{y})}{p(\bm{y}_{K})}=\mathop{\arg\max}_{ \theta\in\Theta}-\sum_{\bm{y}\in\mathcal{Y}_{q_{\theta}}}q_{\theta}(\bm{y})log \frac{q_{\theta}(\bm{y})}{p(\bm{y})}+\sum_{\bm{y}\in\mathcal{Y}_{q_{\theta}}}q _{\theta}(\bm{y})\log\frac{q_{\theta}(\bm{y})}{p(\bm{y}_{K})},$ (2) $$

where $\mathcal{Y}_{q_{\theta}}=\mathcal{Y}_{1}^{q}\cup\mathcal{Y}_{2}^{q}\dots\cup
\mathcal{Y}_{L}^{q}$ aims at maximizing acceptance rate for every beam search step (see detailed derivatives in Appendix A.2).
This alignment objective can be further expanded as:

$$ $\displaystyle\theta^{*}:=\mathop{\arg\min}_{\theta\in\Theta}\mathbb{E}_{(\bm{x },\mathcal{Y})\sim\mathcal{D}^{\prime}}\sum_{\bm{y}\in\mathcal{Y}}\big{[}\frac {1}{|\bm{y}|}\sum_{t=1}^{|\bm{y}|}\big{[}{\sum_{y_{t}\in\mathcal{V}}q_{\theta} ({y_{t}}|c_{<t})\log\frac{q_{\theta}(y_{t}|c_{<t})}{p(y_{t}|c_{<t})}}-{\sum_{y _{t}\in\mathcal{V}}q_{\theta}(y_{t}|c_{<t})\log\frac{q_{\theta}(y_{t}|c_{<t})} {p(y_{K})}}\big{]}\big{]},$ (3) $$

where $c_{t}=(\bm{x},\bm{y}_{<t})$ is the context, $p(y_{K})=p(\bm{y}_{K,t}|\bm{y}_{K,<t})$,
and $\mathcal{D}^{\prime}=\{(\bm{x},\mathcal{Y}=\text{Top}K((1-\lambda)\mathcal{M}_
{q}(\bm{x})+\lambda\mathcal{M}_{p}))|\bm{x}\sim\mathcal{D}\}$(^3^33We follow (Gu et al., ) to adopt the target LLM-mixed sampling for data construction.), and $\mathcal{V}$ is the LLM vocabulary.

However, aligning every token over the entire vocabulary with ${y_{t}\in\mathcal{V}}$ might lead to suboptimal results due to the noises introduced by invalid tokens with high probabilities.
LLM-based recommender models usually employ constrained generation (Hua et al., ) to generate valid item identifiers only.
Blindly aligning across all tokens in $\mathcal{V}$ may cause unnecessary alignment to these high-probability but invalid tokens that will never be generated by the target LLM.
To mitigate this issue, we define $\mathcal{V}_{c}=\text{ConstrainedTop}K(q)$
to block out the potential alignment noises from invalid tokens.
We then define the alignment loss as:

$$ $\mathcal{L}_{\text{Align-S}}=\frac{1}{|\mathcal{D}^{\prime}|}\sum_{(\bm{x}, \mathcal{Y})\sim\mathcal{D}^{\prime}}\sum_{\bm{y}\in\mathcal{Y}}\big{[}\frac{1 }{|\bm{y}|}\sum_{t=1}^{|\bm{y}|}\big{[}\underbrace{\sum_{y_{t}\in\mathcal{V}_{ c}}q_{\theta}({y_{t}}|c_{<t})\log\frac{q_{\theta}(y_{t}|c_{<t})}{p(y_{t}|c_{<t })}}_{\begin{subarray}{c}(\textbf{RKLD})\end{subarray}}-\underbrace{\sum_{y_{t }\in\mathcal{V}_{c}}q_{\theta}(y_{t}|c_{<t})\log\frac{q_{\theta}(y_{t}|c_{<t}) }{p(y_{K})}}_{\begin{subarray}{c}(\textbf{Density Regularization})\end{ subarray}}\big{]}\big{]},$ (4) $$

which is essentially minimizing the RKLD over the top-K sequence probabilities and a density regularization term.
Intuitively, minimizing RKLD emphasizes aligning the draft model $\mathcal{M}_{q}$ to the target LLM $\mathcal{M}_{p}$ within the draft model’s generation capability (Gu et al., ), particularly for the top-K sequence probability distribution.
Moreover, the density regularization term encourages the top-K sequence probabilities of the draft model to dominate the whole probability distribution.

Overall Loss.
Based on Eq.(4), AtSpeed-S defines the overall training loss for the draft model as:

$$ $\mathcal{L}_{\text{AtSpeed-S}}=\alpha\mathcal{L}_{\text{Align-S}}+(1-\alpha) \mathcal{L}_{\text{Rec}},$ (5) $$

where $\mathcal{L}_{\text{Rec}}$ is the original loss to train the model for the recommendation tasks and $\alpha$ is the hyper-parameter to control the alignment strength.

### 3.2 Alignment for Relaxed Sampling Verification (AtSpeed-R)

In addition to the strengthened alignment for the strict top-$K$ verification, we further consider verification relaxation to reduce the trivial LLM calls.
From the angle of verification, we introduce a relaxed sampling verification strategy based on the sequence generation probability to improve the acceptance rate of draft sequences.
This verification strategy ensures that sequences falling outside the target’s top-$K$ predictions can still be accepted with a certain probability, while preserving the output distribution closely aligned with that of the target LLM to maintain the recommendation accuracy to some extent. Under this relaxed sampling verification strategy, we propose AtSpeed-R for top-$K$ alignment accordingly.

Relaxed Sampling Verification.
We design the verification strategy for each beam search step $j\in\{1,\dots,\gamma\}$ as follows.
Given the drafted results $\mathcal{Y}_{q}\sim q$(^4^44The drafted sequences are sampled from the sequence distribution $q_{j}$, and superscript $j$ is omitted for clarity.),
for each $\bm{y}\in\mathcal{Y}_{q}$, we accept $\bm{y}$ if ${p}(\bm{y})\geq{q}(\bm{y})$.
Otherwise, we reject $\bm{y}$ with probability of $1-\frac{p(\bm{y})}{q(\bm{y})}$ and resample $\bm{y}\sim p^{\prime}=\text{norm}(\max(0,p(\bm{y})-q(\bm{y})))$.
Notably, for the non-top-$K$ drafted sequence $\bm{y}$ with a high draft probability (*i.e., *$q(\bm{y})\geq p(\bm{y})$), this verification strategy ensures they have a certain probability of $\frac{p(\bm{y})}{q(\bm{y})}$ to be accepted.
We present more details on the relaxed sampling verification strategy in Algorithm 2 in Appendix.
Drawing upon the with-replacement sampling approximation(^5^55When the sample size (*i.e., *the number of recommended items $K$) is much smaller than the total population size (*i.e., *the vocabulary size), the sampling without replacement can be effectively approximated to the sampling with replacement. See Appendix A.2 for proof.),
the joint distribution of K output sequences under such verification is approximately equivalent to that of the target LLM as proven in Appendix A.2. Such equivalence ensures that the relaxed sampling verification does not sacrifice much recommendation accuracy (see Section 4.3 for empirical evidence).

Acceptance Rate.
For the relaxed sampling verification strategy, we obtain the probability of step acceptance
$\beta=\prod_{K}b$ under the with-replacement sampling approximation, where

$$ $b=\mathbb{E}_{\bm{y}\sim q(\bm{y})}\begin{cases}1,&q(\bm{y})\leq p(\bm{y})\\ \frac{p(\bm{y})}{q(\bm{y})},&q(\bm{y})>p(\bm{y})\end{cases}=\mathbb{E}_{y\sim q (\bm{y})}\min(1,\frac{p(\bm{y})}{q(\bm{y})})=1-\text{TVD}(p(\bm{y}),q(\bm{y})).$ (6) $$

The derivation of Eq.(6) can be easily extended from (Leviathan et al., ) as in Appendix A.2.

Alignment Objective.
Under the relaxed sampling verification, we consider maximizing $\log\beta=-\sum_{K}\log\text{TVD}(q,p)$, which is equivalent to minimizing $\sum_{K}\text{TVD}(q,p)$ to improve the acceptance rate. Thereafter, we present the alignment objective for the draft model:

$$ $\displaystyle\theta^{*}:$ $\displaystyle=\mathop{\arg\min}_{\theta\in\Theta}\mathbb{E}_{(\bm{x},\bm{y}) \sim\mathcal{D}^{\prime}}\sum_{K}\big{[}\frac{1}{|\bm{y}|}\sum_{t=1}^{|\bm{y}| }\text{TVD}(p^{\prime}(\cdot|\bm{x},\bm{y}_{<t}),q^{\prime}(\cdot|\bm{x},\bm{y }_{<t}))\big{]}.$ (7) $$

Similar to AtSpeed-S, we perform constrained alignment over the top-$K$ valid tokens,
and therefore $p^{\prime}(\cdot|\bm{x},\bm{y}_{<t})$ and $p^{\prime}(\cdot|\bm{x},\bm{y}_{<t})$ is the normalized truncated sequence probability over top-$K$ valid tokens.
Based on the with-replacement sampling approximation, Eq.(7) minimizes TVD with the strength of K for the same sequence.
Nevertheless, considering the beam search with sampling would obtain K different sequences, we alternatively leverage the top-K sequences from the target LLM, *i.e., *$\mathcal{D}^{\prime}=\{(\bm{x},\bm{y}\sim\text{Top}\textit{K}(\mathcal{M}_{p}(
\bm{x})))|\bm{x}\sim\mathcal{D}\}$ to minimize the TVD.
Finally, we define the alignment loss of AtSpeed-R as,

$$ $\mathcal{L}_{\text{Align-R}}=\frac{1}{|\mathcal{D}^{\prime}|}\sum_{(\bm{x},\bm {y})\sim\mathcal{D}^{\prime}}[\frac{1}{|\bm{y}|}\sum_{t=1}^{|\bm{y}|}TVD(p^{ \prime}(\cdot|\bm{x},\bm{y}_{<t}),q^{\prime}(\cdot|\bm{x},\bm{y}_{<t}))].$ (8) $$

Overall Loss.
The overall loss of AtSpeed-R is defined as:

$$ $\mathcal{L}_{\text{AtSpeed-R}}=\alpha\mathcal{L}_{\text{Align-R}}+(1-\alpha) \mathcal{L}_{\text{Rec}},$ (9) $$

where $\alpha$ controls the strength of the alignment loss.

### 3.3 Inference of AtSpeed

The inference of AtSpeed follows the draft-then-verify paradigm.
To efficiently recommend items during inference, AtSpeed
first leverages a well-aligned draft model for drafting and then chooses a specific strategy for verification.
Specifically, 1) to obtain identical recommendation results,
AtSpeed can utilize the draft model trained by AtSpeed-S and adopt the strict top-$K$ verification strategy for SD.
Alternatively, 2) to further improve the inference speedup, AtSpeed can use the draft model trained by AtSpeed-R along with the corresponding relaxed sampling verification strategy.
Note that any draft model can be interchangeably applied to the strict top-$K$ and relaxed sampling verification strategies, although they may not be optimized for enhancing the acceptance rate under the corresponding verification strategy.

Tree-based Attention. A challenge of AtSpeed inference is the verification inefficiency issue.
Using beam search results from every step would largely increase the number of drafted sequences ($\gamma N$ sequences),
where some prefix is shared by different beam sequences.
As such, self-attention is repeatedly calculated for the same prefix through a single LLM call, thus leading to verification inefficiency, especially with a larger $N$ (*e.g., *$N=20$).
In this work, we leverage the tree-based attention (Miao et al., ) to
eliminate the repeated calculations
via a single flattened sequence,
thereby boosting the efficiency of verification.
The tree-based attention for the drafted sequences from all steps is illustrated in Figure 2(c).

## 4 Experiments

In this section, we conduct extensive experiments to answer the following research questions:

- •
RQ1: How does our proposed AtSpeed perform in improving inference efficiency for LLM-based recommendation under both strict top-K and relaxed sampling verification strategies?
- •
RQ2: How do different components of AtSpeed affect the decoding acceleration?
- •
RQ3:
How is the recommendation accuracy of AtSpeed-R under the relaxed sampling verification?
- •
RQ4:
How do different hyper-parameters affect the performance?

### 4.1 Experimental Settings

Datasets and Baselines.
To evaluate our proposed framework, we instantiate AtSpeed on a SOTA LLM-based generative recommender model LC-Rec (Zheng et al., ) and test on two real-world recommendation datasets from the popular benchmark Amazon review datasets(^6^66[https://cseweb.ucsd.edu/~jmcauley/datasets/amazon_v2/.](https://cseweb.ucsd.edu/~jmcauley/datasets/amazon_v2/.)).
1) Beauty contains user interactions with the beauty products and
2) Games collects the user interactions with the video games.
For both datasets, each item has rich textual information such as title and description.
Based on the item textual information, we follow LC-Rec to assign each item with an item identifier generated by RQ-VAE (Lee et al., ).
More details of the datasets can be found in Appendix A.3.

We compare our proposed alignment methods with Supervised Fine-tuning (SFT) and
several representative Knowledge Distillation (KD) methods as follows:
1) SFT fine-tunes the draft model with the recommendation loss $\mathcal{L}_{Rec}$ on the recommendation dataset;
2) WordKD (Sanh, ; Hinton, ) fine-tunes the draft model to align with the token probability of the target LLM by KLD on the recommendation dataset;
3) SeqKD (Kim & Rush, ) additionally utilizes the top-K target LLM-generated data to fine-tune the draft model with the recommendation loss $\mathcal{L}_{Rec}$;
4) TVDKD (Wen et al., ) aligns the draft model and the target LLM with the symmetric divergence TVD.

Evaluation Metrics.
To measure the decoding efficiency, we use walltime speedup@$K$ (WS@$K$) for evaluation.
In addition, we report accept step@$K$ (AS@$K$), which is defined as the average number of accepted steps during the SD for each user.
As for the recommendation performance, we adopt the widely used metrics Recall@$K$ for evaluation.

Implementation Details.
We instantiate AtSpeed on LC-Rec, where the backend LLM is LLaMA-7B (Touvron et al., ).
For each dataset, we fine-tune the target LLM using the recommendation loss $\mathcal{L}_{\text{Rec}}$ with the parameter-efficient fine-tuning technique LoRA (Hu et al., ).
As for the draft model, we fully fine-tune a compatible small-sized model LLaMA-68M (Miao et al., ) for alignment training, and then utilize the fine-tuned model for SD inference.
We set draft length $\gamma=4$, number of recommended items $K=\{1,3,5,10,20\}$, and draft beam size $N=40$.
More implementation details are provided in Appendix A.

### 4.2 Overall Performance (RQ1)

We evaluate our method under both standard beam search (beam size=$K$) with strict top-$K$ verification and sampling-based beam search (temperature=$1$) with relaxed sampling verification.
The acceleration results of the baselines and AtSpeed on two datasets are presented in Table 1.
We can observe that:

- •
The walltime speedup under the relaxed sampling verification is generally better than the strict top-$K$ verification, validating the effectiveness of our proposed relaxed strategy.
It boosts the speedup by allowing non-top-$K$ sequences to be accepted with a certain probability.
- •
Compared to SFT, the logit-level KD methods (WordKD and TVDKD) often yield comparable or even inferior performance.
However, this is not surprising because the alignment task for the logit-level KD is more difficult due to two possible reasons.
1) While SFT solely focuses on fitting the top-1 probability token, logit-level KD requires alignment across the entire vocabulary, making it more difficult to achieve due to the limited expressiveness of the smaller model (Agarwal et al., ).
2) The alignment on the top-$K$ ranked items might be negatively affected by the invalid tokens with high probabilities.
During item generation, certain tokens with high probabilities will never be generated as they are deemed invalid tokens, and thereby will never be accepted by the target LLM (*cf. *Section 3.1).
- •
Among the baselines, SeqKD yields competitive results in most cases.
This is reasonable since SeqKD
1) aligns the draft model with the target LLM at the sequence level,
which fosters the generation of sequences more aligned with the target LLM’s distribution
(superior performance than WordKD); and
2) fine-tunes the draft model with target LLM-generated data, which implicitly incorporates the information of valid tokens in item identifiers, thereby alleviating the negative effect from the noisy invalid tokens (superior performance than TVDKD).
The competitiveness of SeqKD is also consistent with the observations in NLP tasks (Agarwal et al., ).
- •
AtSpeed significantly accelerates the LLM-based recommender inference under both strict top-$K$ and relaxed sampling verifications, showing the superiority of our proposed method for strong top-$K$ alignment.
In particular, AtSpeed-S under strict top-$K$ verification achieves an average speedup of 1.97$\times$ on Beauty and 1.83$\times$ on Games while obtaining the identical results of the top-$K$ recommended items.
Moreover, AtSpeed-R further enhances the efficiency with an average speedup of 2.11$\times$ and 2.05$\times$ on Beauty and Games, respectively.
Furthermore, as $K$ increases, the number of accept steps gradually decreases due to the increased difficulty of the $N$-to-$K$ verification.
Nevertheless, it is highlighted that the speedup for $K=20$ is still comparable to that for $K=5$ and outperforms the speedup for $K=10$.
This is attributed to tree-based attention, which efficiently verifies the drafted sequences (more detailed analysis in Appendix A.3).

**Table 1: Overall comparison of walltime speedup (WS@$K$) and accept steps (AS@$K$) between the baselines and AtSpeed instantiated on LC-Rec (LLaMA-7B) across two datasets. For each verification strategy, the best results are highlighted in bold and the second-best results are underlined.**
| Beauty |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Verification | Method | WS@1 | WS@3 | WS@5 | WS@10 | WS@20 | AS@1 | AS@3 | AS@5 | AS@10 | AS@20 |
|  | SFT | 1.88 | 1.55 | 1.43 | 1.37 | 1.55 | 2.19 | 1.66 | 1.32 | 0.66 | 0.09 |
|  | WordKD | 2.02 | 1.70 | 1.58 | 1.52 | 1.58 | 2.33 | 1.89 | 1.60 | 1.03 | 0.16 |
|  | TVDKD | 1.84 | 1.55 | 1.44 | 1.37 | 1.57 | 2.15 | 1.67 | 1.31 | 0.65 | 0.09 |
|  | SeqKD | \ul2.18 | \ul1.88 | \ul1.75 | 1.67 | 1.68 | \ul2.46 | \ul2.10 | \ul1.85 | 1.27 | 0.30 |
|  | AtSpeed-S | 2.33 | 1.97 | 1.84 | 1.87 | 1.82 | 2.58 | 2.20 | 2.00 | 1.64 | 0.57 |
| Strict Top$\bm{K}$ | AtSpeed-R | 1.95 | 1.71 | 1.70 | \ul1.71 | \ul1.74 | 2.26 | 1.96 | 1.82 | \ul1.33 | \ul0.43 |
|  | SFT | 1.77 | 1.76 | 1.80 | 2.06 | 2.36 | 2.15 | 2.06 | 2.03 | 1.99 | 1.48 |
|  | WordKD | 1.74 | 1.75 | 1.81 | 1.99 | 2.05 | 2.11 | 2.04 | 2.01 | 1.87 | 1.07 |
|  | TVDKD | 1.80 | 1.77 | 1.81 | 2.06 | 2.35 | 2.17 | 2.07 | 2.03 | 1.99 | 1.45 |
|  | SeqKD | 1.85 | 1.86 | \ul1.90 | 2.11 | 2.31 | 2.21 | 2.13 | \ul2.10 | 2.01 | 1.40 |
|  | AtSpeed-S | \ul1.94 | \ul1.87 | 1.89 | \ul2.12 | 2.51 | \ul2.26 | \ul2.14 | 2.09 | \ul2.03 | \ul1.71 |
| Relaxed Sampling | AtSpeed-R | 2.05 | 1.94 | 1.94 | 2.16 | \ul2.47 | 2.37 | 2.19 | 2.13 | 2.10 | 1.77 |
| Games |  |  |  |  |  |  |  |  |  |  |  |
| Verification | Method | WS@1 | WS@3 | WS@5 | WS@10 | WS@20 | AS@1 | AS@3 | AS@5 | AS@10 | AS@20 |
|  | SFT | 1.82 | 1.45 | 1.43 | 1.40 | 1.58 | 2.13 | 1.49 | 1.32 | 0.91 | 0.15 |
|  | WordKD | 1.82 | 1.45 | 1.31 | 1.35 | 1.47 | 2.13 | 1.49 | 1.10 | 0.80 | 0.14 |
|  | TVDKD | 1.70 | 1.33 | 1.24 | 1.32 | 1.50 | 1.99 | 1.26 | 0.95 | 0.66 | 0.09 |
|  | SeqKD | \ul2.01 | 1.72 | 1.60 | 1.46 | 1.77 | 2.31 | 1.95 | 1.67 | 1.05 | 0.76 |
|  | AtSpeed-S | 2.01 | 1.77 | 1.78 | 1.85 | \ul1.76 | \ul2.27 | 2.02 | 1.96 | 1.69 | \ul0.68 |
| Strict Top$\bm{K}$ | AtSpeed-R | 1.85 | 1.71 | 1.76 | 1.76 | 1.60 | 2.15 | \ul1.98 | \ul1.95 | \ul1.53 | 0.32 |
|  | SFT | 1.96 | 1.85 | 1.84 | 1.97 | 1.69 | 2.28 | 2.12 | 2.05 | 1.89 | 0.58 |
|  | WordKD | 1.84 | 1.77 | 1.78 | 1.84 | 1.56 | 2.17 | 2.05 | 1.99 | 1.68 | 0.25 |
|  | TVDKD | 1.96 | 1.81 | 1.81 | 1.90 | 1.55 | 2.26 | 2.08 | 2.02 | 1.80 | 0.29 |
|  | SeqKD | 1.91 | 1.87 | 1.90 | 2.03 | 2.05 | 2.22 | 2.13 | 2.10 | 1.98 | 1.22 |
|  | AtSpeed-S | 2.16 | 1.94 | 1.91 | \ul2.04 | 2.13 | 2.44 | 2.19 | \ul2.10 | \ul1.98 | \ul1.28 |
| Relaxed Sampling | AtSpeed-R | \ul2.10 | \ul1.92 | 2.00 | 2.05 | 2.20 | \ul2.40 | \ul2.18 | 2.17 | 1.98 | 1.35 |

### 4.3 In-depth Analysis

Ablation Study (RQ2).
To analyze the effect of AtSpeed-S,
we remove the density regularization term (“w/o DR”), constrained alignment (“w/o CA”), and tree-based attention (“w/o TA”) for AtSpeed-S.
These variants of AtSpeed-S are evaluated under the strict top-$K$ verification.
For AtSpeed-R,
we replace the top-$K$ sequences with the top-1 sequence from target LLM (denoted as “w/o top-$K$”), and separately remove the constrained alignment (“w/o CA”) and the tree-based attention (“w/o TA”). These variants are evaluated under the relaxed sampling verification.

From the results as shown in Figure 3, we have the following observations.
1) the performance decline of “w/o DR” indicates that aggregating probability around the top-$K$ tokens can effectively strengthen the alignment.
2) The use of top-1 sequence from the target LLM to execute AtSpeed-R results in a lower acceptance rate.
This makes sense since the top-1 sequence lacks diversity, which might overemphasize the alignment on the top-1 sequence and hurt the speedup.
3) By discarding either the constrained alignment or tree attention would lead to performance decline for both AtSpeed-S and AtSpeed-R.
This is expected since removing constrained alignment would introduce potential noisy tokens, which have high probability yet will be rejected to ensure in-corpus item recommendation.
Furthermore,
4) the removal of tree-based attention would hurt the speedup although it does not affect the acceptance rate, which validates the efficiency of utilizing tree-based attention to execute parallel verification.

Figure: Figure 3: Ablation study of AtSpeed-S and AtSpeed-R on Beauty dataset. Figure(a) presents the performance of removing each component of AtSpeed-S separately under strict top-$K$ verification; while figure(b) shows the results of discarding each component of AtSpeed-R separately under relaxed sampling verification.
Refer to caption: x3.png

Recommendation Accuracy of AtSpeed-R (RQ3).
To examine how our relaxed verification strategy affects the recommendation accuracy,
we run AtSpeed-R and the target LLM (*i.e., *LC-Rec (Zheng et al., ) based on LLaMA-7B) via sampling-based beam search.
The results are presented in Table 2, from which we can observe that
1) AtSpeed-R consistently yields comparable performance compared to the target LLM when the sampling is enabled for beam search.
This empirically validates the approximately equivalent output distribution of the LLM inference with and without SD.
In addition,
2) while AtSpeed-R boosts the LLM inference efficiency with an over 2$\times$ speedup,
it can achieve comparable or even better accuracy compared to the original top-$K$ recommendation of LC-Rec without sampling (temperature=0).

**Table 2: Recommendation performance of AtSpeed-R under relaxed sampling verification on Beauty. “WS@K” denotes “walltime speedup@K”.**
|  | Temperature=0 | Temperature=0.5 | Temperature=1 |  |  |
| --- | --- | --- | --- | --- | --- |
| Metrics | Target LLM | Target LLM | AtSpeed-R | Target LLM | AtSpeed-R |
| Recall@5 | 0.0056 | 0.0057 ^↑0.0001 | 0.0051 ^↓0.0006 | 0.0053 ^↓0.0003 | 0.0058 ^↑0.0002 |
| Recall@10 | 0.0098 | 0.0095 ^↓0.0003 | 0.0091 ^↓0.0007 | 0.0088 ^↓0.0010 | 0.0092 ^↓0.0006 |
| WS@5 | 1$\times$ | 1$\times$ | 1.83$\times$ ^↑0.83 | 1$\times$ | 2.13$\times$ ^↑1.13 |
| WS@10 | 1$\times$ | 1$\times$ | 2.04$\times$ ^↑1.04 | 1$\times$ | 2.10$\times$ ^↑1.10 |

Figure: Figure 4: Effect of draft beam size $N$ and the alignment strength $\alpha$ on Beauty.
Refer to caption: x5.png

Effect of Draft Beam Size $\bm{N}$ (RQ4).
To study how the draft beam size $N$ affects the acceleration of AtSpeed, we vary $N$ from 20 to 60 and test AtSpeed-S under strict top-$K$ verification (Figure 4) and AtSpeed-R under relaxed sampling verification, respectively.
From the figures, we can observe that
1) from $N=20$ to $N=60$, the acceptance rate constantly increases for both AtSpeed-S and AtSpeed-R.
This is reasonable as a larger beam size can produce more drafted sequences for verification, thus enhancing the acceptance rate.
Moreover,
2) the walltime speedup continues to improve steadily as $N$ gets larger.
We attribute this phenomenon to the utilization of tree-based attention, which efficiently verifies drafted sequences with a single flattened sequence (refer to Appendix A.3 for detailed speedup analysis of tree-based attention).
Nevertheless,
3) the improvement of acceptance rate and speedup gradually slows down (*i.e., *decreasing slope), indicating continuously increasing $N$ is approaching a balance between the enhanced acceptance rate and the increased overhead.

Effect of Alignment Strength $\bm{\alpha}$ (RQ4).
We train the draft model with different alignment strength $\alpha$ and present the results of AtSpeed-S in Figure 4(c)(^7^77More analysis of AtSpeed is presented in Appendix A.3 to save space.).
From the figure, it is observed that
the integration of alignment loss (incrementally increased from 0) improves performance, which validates the necessity of alignment to improve acceptance rate.
However,
2) blindly emphasizing the alignment loss may be ineffective, as the model struggles to capture the output of the target LLM due to the limited expressiveness of the small-sized model without the knowledge of recommendation task.
Therefore, it is essential to strike a balance between the task-specific objective and the alignment objective.
Empirically, we recommend setting $\alpha=0.5$ for alignment training.

## 5 Related Work

Speculative Decoding.
As an efficient LLM decoding technique, SD (Leviathan et al., ; Fu et al., ; Du et al., ; Liu et al., ; Chen et al., ; Sun et al., ) has been proposed to reduce the LLM calls by efficiently drafting multiple future tokens and then verifying them in parallel.
Early studies focus on SD in greedy decoding, where the draft model generates one token at each generation step for LLM to verify if they match the LLM’s top-$1$ token.
Later on, some studies extend SD to nucleus sampling to accelerate LLM decoding without changing its output distribution (Leviathan et al., ).
However, the early attempts simply draft one token at each step for verification, which significantly limits the acceptance rate (Xia et al., ).
To improve the acceptance rate, subsequent work designs various relaxed verification strategies for greedy decoding such as enlarging LLM candidates with a tolerable score away from the top-$1$ token (Xia et al., ) and measuring the distance of the probability between the draft model and the target LLM (Kim et al., ).
Concurrently, some studies propose different methods to draft multiple candidates for different sampling, as seen in
Medusa (Cai et al., ), EAGLE (Li et al., ) and so on.
While previous work primarily applies SD for NLP tasks and follows the $N$-to-$1$ verification,
our work extends SD to LLM-based generative recommendation tasks, addressing the unique challenge of $N$-to-$K$ verification, *i.e., *perfect matching over the top-$K$ sequences.
Closely related to our work, DistillSpec (Zhou et al., ) investigates the use of various KD techniques to enhance the alignment between the draft model and the target LLM, to achieve high acceptance rate.
However, they mainly focus on how KD helps for the $N$-to-$1$ verification. In contrast, this work studies the SD under $N$-to-$K$ verification for recommendation tasks, and proposes a framework to align the draft model with the target LLM on the top-$K$ sequences specifically for recommendation tasks.

Inference Acceleration for LLM-based Recommendation.
While LLM-based generative recommendations have shown remarkable performance (Li et al., ), their practical implementation is impeded due to the high time latency of LLM decoding (Li et al., ).
Consequently, accelerating LLM decoding is imperative to facilitate real-world deployment of the powerful LLM-based recommender models.
To tackle this issue, several approaches leverage KD to transfer knowledge from a teacher LLM to either a smaller language model (Xu et al., ; Wang et al., ) or a traditional recommender model (Cui et al., ).
Additionally, some methods focus on designing more lightweight model architectures, such as narrow and deep transformer structures (Mei & Zhang, ). However, the application of SD is underexplored in LLM-based recommendation.
DARE (Xi et al., ) is a relevant study that applies SD in user feature augmentation for LLM-based recommendation.
However, they focus on the LLM decoding for user feature generation that requires only one response from the target LLM, which is essentially SD under the $N$-to-$1$ verification.
In contrast, our work explores decoding acceleration for top-$K$ ranked item recommendation, tackling the more difficult $N$-to-$K$ verification problem.
In addition to these approaches, various other techniques, such as model quantization (Xiao et al., ), model pruning (Hassibi & Stork, ), and Key-Value (KV) cache optimization (Zhang et al., ), can also enhance inference acceleration.
Nonetheless, these methods are orthogonal to SD and can be effectively integrated with SD to further improve decoding efficiency.

## 6 Conclusion and Future Work

In this work, we formulated the speculative decoding task for LLM-based generative recommendation, highlighting the significant challenge of shifting from $N$-to-$1$ to $N$-to-$K$.
To effectively accelerate decoding under $N$-to-$K$ verification, the key lies in drafting all top-$K$ sequences from the target LLM, which drives two objectives for SD: top-$K$ alignment and verification relaxation.
To achieve this, we proposed an alignment framework called AtSpeed, along with a relaxed sampling verification strategy. AtSpeed designs two alignment objectives for the strict top-$K$ verification and relaxed sampling verification strategies.
Extensive experiments show that AtSpeed achieves around 2$\times$ speedup on two real-world recommendation datasets.
As an initial attempt work, it points out many promising directions for further explorations, such as
1) more efficient drafting methods to reduce the overhead of drafting, such as non-LLM recommender models for efficient high-quality drafting that might lead to better recommendation accuracy under the relaxed sampling verification strategy,
and 2) integration with other acceleration techniques such as memory access optimization.

## Ethics Statement

Our research focuses on effectively boosting the inference efficiency of LLM-based generative recommendation with the AtSpeed framework, unlocking the significant practical potential of LLM-based recommender models.
This work is technical and practical, with applications to LLM-based generative recommendation.
We have fully considered the potential societal impacts and do not foresee any direct, immediate, or negative consequences.
We are committed to the ethical dissemination of our findings and encourage their responsible use.

## Reproducibility Statement

All the results in this work are reproducible. We provide all the necessary code to replicate our results in an anonymous GitHub repository. The repository includes environment configurations, run scripts, and other relevant materials.
We discuss the experimental settings in Section 4.1, including implementation details such as the utilization of parameter-efficient training. Additionally, detailed experimental settings are provided in Appendix A.3.

## Appendix A Appendix

### A.1 Algorithm of Relaxed Sampling Verification

Figure: Algorithm 2 SD step with Relaxed Sampling Verification

### A.2 Proof and detailed derivatives

With-replacement Sampling Approximation.
During each step of the beam search,
given the sequence probability distribution $p$ and the beam size $n$, we can effectively approximate the sampling without replacement to the sampling with replacement when the population size $N$ *i.e., *vocabulary size, is much larger than the sample size $n$, *i.e., *beam size.

First, we model the sampling with replacement with multinomial distribution, where $p_{i}$ is the probability of sampling sequence $i$.
We have the mass function as

$$ $\displaystyle f(X_{1}=x_{1},X_{2}=x_{2},\dots,X_{n}=x_{n};n,p_{1},p_{2},\dots, p_{n})$ (10) $\displaystyle=P(X_{1}=x_{1},\dots,X_{n}=x_{n})$ $\displaystyle=\binom{n}{n_{1}n_{2}\dots}\prod_{i}p_{i}^{n_{i}}.$ $$

We then model the sampling without replacement with the multivariate hypergeometric distribution.
Let the population size be $N$, the subpopulation size be $N_{i}$,
the sample size be $n$, and the subpopulation sampled number be $n_{i}$.
Now we assume that $N\to\infty$ such that
$\sum_{i}N_{i}=N$, $\sum_{i}n_{i}=n$,
$\frac{N_{i}}{N}\rightarrow p_{i},\sum_{i}p_{i}=1$ as $N\to\infty$.
We can write the mass function of multivariate hypergeometric distribution as

$$ $\frac{\prod_{i}\binom{N_{i}}{n_{i}}}{\binom{N}{n}}.$ (11) $$

Based on the Stirling’s approximation (Marsaglia & Marsaglia, ), *i.e., *$n!\sim\sqrt{2\pi n}\binom{n}{e}^{n}$, we can rearrange Eq.(11) into

$$ $\displaystyle\frac{\prod_{i}\frac{N_{i}!}{n_{i}!(N_{i}-n_{i})!}}{\frac{N!}{n!( N-n)!}}=\binom{n}{n_{1}n_{2}\dots}\prod_{i}\frac{\sqrt{N_{i}}N_{i}^{N_{i}}}{ \sqrt{N}}N^{N}\prod_{i}\frac{\sqrt{N-n}(N-n)^{N-n}}{\sqrt{N_{i}-n_{i}}(N_{i}-n _{i})^{N_{i}-n_{i}}}.$ (12) $$

By taking the limits, $\frac{N_{i}}{N_{i}-n_{i}}\to 1$ and $\frac{N}{N-n}\to 1$, Eq.(12) is further rearranged to get the mass function for the multinomial distribution

$$ $\displaystyle\binom{n}{n_{1}n_{2}\dots}\prod_{i}(\frac{N_{i}}{N})^{N_{i}}\prod _{i}(\frac{N-n}{N_{i}-n_{i}})^{(N_{i}-n_{i})}$ (13) $\displaystyle=\binom{n}{n_{1}n_{2}\dots}\prod_{i}p_{i}^{n_{i}}.$ $$

Therefore, the sampling during beam search, *i.e., *the sampling without replacement, can be approximated to the sampling with replacement, when the population size $N$ becomes much larger than the beam size $n$.

Derivatives of Alignment objectives of AtSpeed-S.
To maximize the acceptance rate under the strict top-$K$ verification, we consider:

$$ $\displaystyle\mathop{\arg\max}_{\theta\in\Theta}$ $\displaystyle\mathbb{E}_{\bm{y}\sim\mathcal{Y}_{q_{\theta}}}\frac{p(\bm{y})}{p (\bm{y}_{K})}$ (14) $\displaystyle\mathop{\arg\max}_{\theta\in\Theta}$ $\displaystyle\mathbb{E}_{\bm{y}\sim\mathcal{Y}_{q_{\theta}}}\log\frac{p(\bm{y} )}{p(\bm{y}_{K})}$ $\displaystyle=\sum_{\bm{y}}q(\bm{y})\log p(\bm{y})-\sum_{\bm{y}}q(\bm{y})\log p (\bm{y}_{K})$ $\displaystyle=-\sum_{\bm{y}}q(\bm{y})\log\frac{1}{p(\bm{y})}-\sum_{\bm{y}}q( \bm{y})\log p(\bm{y}_{K})$ $\displaystyle=-\sum_{\bm{y}}q(\bm{y})\log\frac{q(\bm{y})}{p(\bm{y})}+\sum_{\bm {y}}q(\bm{y})\log q(\bm{y})-\sum_{\bm{y}}q(\bm{y})\log p(\bm{y}_{K})$ $\displaystyle=-\sum_{\bm{y}}q(\bm{y})\log\frac{q(\bm{y})}{p(\bm{y})}+\sum_{\bm {y}}q(\bm{y})\log\frac{q(\bm{y})}{p(\bm{y}_{K})},$ $$

According to the derivatives in Eq.(14), we obtain the alignment objective as shown in Eq.(2).
Since we have $q(\bm{y})=\prod_{t}q(y_{t}|\bm{x},\bm{y}_{<t})=\prod_{t}q(y_{t}|c_{<t})$, we can further expand with some rearrangement into:

$$ $\displaystyle-\sum_{\bm{y}}\prod_{t}q(y_{t}|c_{<t})\log\frac{\prod_{t}q(y_{t}| c_{<t})}{\prod_{i}p(y_{t}|c_{<t})}+\sum_{\bm{y}}\prod_{i}q(y_{t}|c_{<t})\log \frac{\prod_{i}q(y_{t}|c_{<t})}{\prod_{i}p(\bm{y}_{K,t}|\bm{y}_{K})}$ (15) $\displaystyle=$ $\displaystyle-\sum_{\bm{y}\in\mathcal{Y}}\big{[}\frac{1}{|\bm{y}|}\sum_{t=1}^{ |\bm{y}|}\big{[}{\sum_{y_{t}\in\mathcal{V}}q_{\theta}({y_{t}}|c_{<t})\log\frac {q_{\theta}(y_{t}|c_{<t})}{p(y_{t}|c_{<t})}}+{\sum_{y_{t}\in\mathcal{V}}q_{ \theta}(y_{t}|c_{<t})\log\frac{q_{\theta}(y_{t}|c_{<t})}{p(y_{K})}}\big{]}\big {]},$ $$

where $c_{t}=(\bm{x},\bm{y}_{<t})$ is the context, $p(y_{K})=p(\bm{y}_{K,t}|\bm{y}_{K,<t})$. Based on Eq.(15), we can easily obtain the alignment objective as in Eq.(3).

Derivatives of Acceptance Rate for Relaxed Sampling Verification.
Based on the with-replacement sampling approximation, for every independent sampling, we have acceptance rate of a sequence

$$ $b=\mathbb{E}_{\bm{y}\sim q(\bm{y})}\begin{cases}1,&q(\bm{y})\leq p(\bm{y})\\ \frac{p(\bm{y})}{q(\bm{y})},&q(\bm{y})>p(\bm{y})\end{cases}=\mathbb{E}_{y\sim q (\bm{y})}\min(1,\frac{p(\bm{y})}{q(\bm{y})})=1-\text{TVD}(p(\bm{y}),q(\bm{y})),$ (16) $$

which can be easily extended from (Leviathan et al., ) as follows.

###### Definition 1 .

$TVD(p,q)=\sum_{\bm{y}}|p(\bm{y})-M(\bm{y})|=\sum_{\bm{y}}|q(\bm{y})-M(\bm{y})|$, where $M(q)=\frac{p(\bm{y})+q(\bm{y})}{2}$.

###### Lemma 1 .

$TVD=1-\sum_{\bm{y}}\text{min}(p(\bm{y}),q(\bm{y}))$.

###### Proof.

$TVD(p,q)=\sum_{y}|p(\bm{y})-M(\bm{y})|=\sum_{\bm{y}}\frac{|p-q|}{2}=1-\sum_{
\bm{y}}=1-\sum_{\bm{y}}\text{min}(p(\bm{y})-q(\bm{y})$
∎

###### Theorem 1 .

$b=1-TVD(p,q)$.

Based on the with-replacement sampling approximation, we can obtain the acceptance rate of a step with $K$ accepted sequences as $\beta=\prod_{K}b$.
Similarly, we could also extend the distribution equivalence for sampling a sequence between the draft model and the target LLM from Appendix A.1 in  (Leviathan et al., ).
As such, when the sampling-based beam search is performed with a beam size $K$, the joint distribution of the output $K$ sequences from the SD under the relaxed sampling verification is approximately equivalent to the counterparts from the target LLM, according to the approximation of with-replacement sampling, *i.e., *independent sampling.

###### Definition 1 .

###### Lemma 1 .

###### Proof.

###### Theorem 1 .

### A.3 Experimental Details and Analysis

**Table 3: Statistics of the two datasets.**
| Datasets | # Users | # Items | # Interactions | Density |
| --- | --- | --- | --- | --- |
| Beauty | 19,383 | 12,035 | 138,870 | 0.06% |
| Games | 49,156 | 17,332 | 342,329 | 0.04% |

Datasets Details.
For both Beauty and Games, all interactions are sorted according to the global timestamps, and then split into training, validation, and testing sets with the ratio of 8:1:1. The dataset statistics is presented in Table 3.
For the item identifier, we follow LC-Rec (Zheng et al., ) to set the length $L=4$, *i.e., *the token sequence length of a generated item would be 4.

Implementation details.
For draft model training, we use AdamW optimizer with batch size$=64$, learning rate=$0.001$, and a cosine scheduler with warmup step of $200$ to adjust
the learning rate.
We train the draft model for 20 epochs on 4 NVIDIA RTX A5000 GPUs. Meanwhile, we search the alignment strength $\alpha$ in $\{0.1,0.3,0.5,0.7\}$ and weight decay in $\{0.01,0.1\}$.
For efficient training, we utilize top-$K$ sequences from the last step of beam search to construct the alignment data $\mathcal{D}^{\prime}$.
Despite the utilization of beam sequences from different steps of beam search
could potentially enhance the acceleration effects further,
it exacerbates the training burden regarding time cost and storage cost (see Table 4).

Figure: Figure 5: (a) Speedup effect of tree-based attention on Beauty. (b) Performance of AtSpeed on varying hyper-parameters (alignment strength $\alpha$) on Beauty.
Refer to caption: x8.png

Speedup of tree-based attention.
To analyze the speedup effect of tree-based attention, we instantiate it on the standard LLM decoding with beam search, where each decoding step will utilize the tree-based attention in the LLM forward process.
We compare the beam search with and without tree-based attention and report the results in Figure 5 (a).
As shown in the figure, we can find that the utilization of tree-based attention indeed exhibits an acceleration effect,
corroborating the efficacy of our method.
Furthermore, as the draft beam size $N$ grows larger, the speedup of tree-based attention becomes higher. This enhancement is attributed to the substantial reduction in repeated calculations of the same prefix shared across different beam sequences.

**Table 4: Comparison between AtSpeed with and without additional training data regarding decoding efficiency, training time efficiency, and storage efficiency. “w/ AD” denotes AtSpeed trains the draft model with additional data generated from different steps.**
| Verification | Method | WS@10$\uparrow$ | WS@20$\uparrow$ | AS@10$\uparrow$ | AS@20$\uparrow$ | Time Cost (h)$\downarrow$ | Storage Cost (GB)$\downarrow$ |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Strict Top-$\bm{K}$ | AtSpeed-S | 1.87 | 1.84 | 1.64 | 0.57 | 2.56 | 14.68 |
| AtSpeed-S w/ MD | 6661.87^↑0.00 | 6661.66^↓0.18 | 6661.60^↓0.04 | 6660.65^↑0.08 | 6664.10^↑1.54 | 666628.09^↑13.41 |  |
| Relaxed Sampling | AtSpeed-R | 2.09 | 2.44 | 2.01 | 1.61 | 2.63 | 14.68 |
| AtSpeed-R w/ MD | 6662.16^↑0.07 | 6662.42^↓0.02 | 6662.08^↑0.07 | 6661.65^↑0.04 | 6663.00^↑0.37 | 666628.09^↑13.41 |  |

Utilization of Beam Sequences from Diverse Steps.
Table 4 shows
inference and training efficiency comparison between AtSpeed training with and without additional data
generated from beam search results on diverse steps.
From the table, it is observed that incorporating data from diverse generating steps usually enhances the speedup and accept steps, which is attributed to the additional alignment of top-$K$ sequences across different steps.
Nevertheless, using additional data could incur increased training time and storage cost. Specifically, utilizing a larger dataset necessitates greater storage capacity and extends the training duration.
Despite these additional costs, the marginal improvement in performance is not substantial, leading to a low cost-effectiveness ratio.
Therefore, we should carefully consider the balance between the benefits of enhanced alignment against the increased training resource burden.

Hyper-parameter Analysis.
1) Effect of alignment strength $\alpha$.
Figure 5 (b) and (c) presents the results indicating the impact of alignment strength on AtSpeed-R.
As the value of $\alpha$ increases, the overall trend of accept steps exhibits an upward trajectory, which validates the necessity of alignment to improve the performance.
2) Effect of draft length $\gamma$.
Figure 6 presents the impact of varying $\gamma$ on the performance of AtSpeed. Despite acceptance generally increases with $\gamma$, speedup does not consistently improve with $\gamma$. The trend of speedup in relation to $\gamma$ is influenced by draft beam size parameter $N$. Specifically, when $N$ is small, speedup tends to increase with $\gamma$; conversely, when $N$ is large, speedup tends to decrease with $\gamma$. This variation is primarily attributed to the computational overhead during the draft phase, which escalates with larger beam size, thereby diminishing the acceleration benefits. The key determinant of the draft phase’s computational cost is the constraint search process.

Figure: Figure 6: Performance of AtSpeed with different draft length $\gamma$ on Beauty.
Refer to caption: x11.png

Case Study.
As shown in Figure 7, our proposed methodology achieves a significant reduction in decoding time.
Since the prefilling time is the same between target LLM with and without SD, AtSpeed boosts the LLM decoding by
reducing the percentage of decoding by 58% ($N$=1), 37% ($N$=10), and 23% ($N$=20).

Figure: Figure 7: Comparison of the time cost ratio between the prefilling and decoding. The time cost of prefilling is the same across different methods.
Refer to caption: x19.png

## Peer Reviews

confidence: 4
contribution: 3
initial_rating: 6
presentation: 4
questions: Please refer to "Weaknesses" for more details.

Lastly, I want to share a related paper, "Inductive Generative Recommendation via Retrieval-based Speculation". This paper was released after the ICLR submission deadline and is currently available only as a preprint. While this is not a critique or question, it’s relevant as it discusses speculative decoding in generative recommendation. It proposes a dynamic N for the draft model and introduces a technique to perform limited beam search, using prefixes generated by the first few steps of the target model to guide the draft model. I believe this work shares some conceptual similarities with this paper, so I thought it worth mentioning.
soundness: 3
strengths: 1. A timely study addressing inference efficiency in generative recommendation.
2. The ideas of (1) fine-tuning the draft model to align with top-K items of the target model and (2) adding a probability to accept rejected items in a more flexible verification setting are both novel and interesting.
3. The paper is well-written and easy to follow.
4. Experiments on two public datasets demonstrate the efficiency of the proposed method.
5. Code is available during the review phase, enhancing reproducibility.
summary: This paper focuses on accelerating inference in LLM-based generative recommendation using speculative decoding. It highlights the challenges of applying speculative decoding directly to the generative recommendation, due to the N-to-K issue. The authors introduce two improvements in both the drafting and verification stages. Experiments on two public datasets demonstrate the efficiency of the proposed method.
weaknesses: 1. Performance metrics (e.g., NDCG and Recall) are not well-presented. Only Table 2 includes some ranking metrics (also only Recall, without NDCG), which may raise doubts about the proposed method's ranking performance. Including these metrics in Table 1 and Figure 3 would strengthen the results. The limited metrics reported make it challenging to fully assess AtSpeed's ranking performance.
2. Presentation issues. Reporting WS@K and AS@K for all values of K in {1, 3, 5, 10, 20} in Table 1 seems unnecessary, especially since the discussion focuses on average WS and AS. I suggest presenting only representative Ks alongside the averages, freeing space for additional ranking metrics.

---

confidence: 4
contribution: 2
initial_rating: 5
presentation: 2
questions: - [Q1] The paper primarily compares AtSpeed with KD-based baselines. Existing SD-based baselines should also be compared including the paper I mentioned before (A Decoding Acceleration Framework for Industrial Deployable LLM-based Recommender Systems). 
- [Q2] Have the authors tested their framework on any larger and more diverse datasets, such as MovieLens or more complex datasets like Goodreads? If not, can the authors comment on the expected performance and generalization ability of AtSpeed in these contexts?
- [Q3] The paper mentions the use of LLaMA-7B, but it would be interesting to know how AtSpeed scales with even larger models (e.g., LLaMA-13B or GPT-3). Do the authors anticipate any bottlenecks or limitations when scaling to larger models, especially concerning memory usage and GPU efficiency?
soundness: 2
strengths: - The paper extends the N-to-1 verification to the N-to-K verification in the context of generative recommendation, which fits the setting of real-world recommender systems.
- The authors provide a solid theoretical foundation for AtSpeed to align the draft and target models. The optimization objectives are clearly motivated and mathematically sound.
- Empirical results are compelling, showing that AtSpeed can achieve up to a 2.5× speedup while maintaining competitive recommendation accuracy. The results are well presented and highlight the practical utility of the proposed method.
summary: This paper proposes AtSpeed, a framework to accelerate LLM-based generative recommendation systems through speculative decoding. The main challenge addressed is the inherent inefficiency of autoregressive beam search in generating top-K recommendations. The authors identify that traditional SD methods, which focus on N-to-1 verification, are insufficient for recommendation tasks that require N-to-K verification to output a ranked list of K items. To tackle this, the paper introduces two methods: AtSpeed-S for strict top-K alignment and AtSpeed-R for relaxed sampling verification, which aims to reduce the number of LLM calls while preserving accuracy. Experimental results demonstrate that AtSpeed achieves significant speedups (up to 2.5×) with minimal degradation in recommendation accuracy.
weaknesses: - The paper may overclaim their contribution to be the first to propose the speculative decoding task for LLM-based recommender acceleration. There already exists prior work on speculative decoding for LLM-based recommendation: *A Decoding Acceleration Framework for Industrial Deployable LLM-based Recommender Systems (Xi, Yunjia, et al)*, which needs to be compared and discussed.
- The experiments are somewhat limited to two datasets (Amazon Beauty and Games). While these datasets are commonly used, the paper would benefit from broader validation across additional domains or larger-scale datasets.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 2
questions: - In Section 3.1, paragraph "Acceptance Rate", the condition given for having $\beta = 1$, namely that $p(\mathbf{y}) \geq p(\mathbf{y}_K)$ for all $\mathbf{y}$ in $\mathcal{Y}_q$, doesn't seem to be fulfillable. By definition of $\mathbf{y}_K$, there exists only $K-1$ sequences with greater probability according to $p$, yet the condition requires that all $N$ ($\geq K$) sequences in $\mathcal{Y}_q$ have a probability greater than $\mathbf{y}_K$. The only possibility for this condition to be realized is if $\mathcal{Y}_q$ contains duplicates, which should not happen in the case of beam search.
- Derivation of Eq 15 in App A.2 (which leads to the definition of the alignment objective in Eq 3) seems incorrect or at least misses important steps to be understandable for the reader. More steps or explanations are needed.
- Eq 3 introduces $\mathcal{D'}$ in which $\mathcal{Y}$ is the top-$K$ of a mixture of $q$ and $p$. Following Gu et al (2024) is mentioned as the motivation for this, but it would be appreciated to have more intuitions on this choice. Moreover, the $\mathcal{D'}$ used later in the relaxed alignment objective (Eq 8) is different. What is the rationale to have different $\mathcal{D'}$ in the strict and relaxed objectives?
- What loss is used in practice for $\mathcal{L}_{Rec}$? It is only mentioned to be a recommendation loss but additional details would be appreciated (at least in the appendix).
- The relaxation sampling verification strategy misses some intuition: why is $p(\mathbf{y}) \geq q(\mathbf{y})$ the right criterion for accepting a sequence $\mathbf{y}$? Why are such $\mathbf{y}$'s good candidates? Moreover, in the case of rejection, $\mathbf{y}$ is drawn from $p' = norm(max(0, p(\mathbf{y}) - q(\mathbf{y})))$ but it is unclear whether this is an actual distribution and what the norm operator exactly consists of. Is $p'$ denoting the uniform distribution over the $\mathbf{y}$'s such that $p(\mathbf{y}) \geq q(\mathbf{y})$? If so, how does one sample from this in practice? The definition of this distribution would deserve more clarifications and details.
- The "with-replacement sampling approximation" paragraph in App A.2 is difficult to follow so it would benefit from being reworked.
- The proof of Lemma 1 in App A.2, which corresponds to Lemma 3.3 from Leviathan et al (2023), is missing the step with the term $1 - \sum_{\mathbf{y}} \frac{p(\mathbf{y})+q(\mathbf{y})-|p(\mathbf{y})-q(\mathbf{y})|}{2}$.
- In Eq 7, what does $\sum_K$ denote? It seems like there is an index variable missing there.
- The strategy relying on tree-based attention to speed up inference would benefit from being described in more details (at least in Appendix). Section 3.3 only refers to Figure 2(c) to describe the strategy, but this figure is not self-explanatory.
-  The WS metric represents the walltime speedup, but with respect to which baseline? I assume this is in comparison to directly running the target model without speculative decoding, but it would be helpful for the reader to mention this when defining the metric.
- Table 1 reports the results for AtSpeed-S and AtSpeed-R on both the strict and the relaxed settings. How can AtSpeed-S be applied to the relaxed setting and AtSpeed-R to the strict setting?
- In Figure 5 of the Appendix, it seems that a larger value for $\alpha$ is always beneficial for AtSpeed-R, whereas Figure 3 (c) showed that $\alpha$ should neither be too small nor too large for AtSpeed-S. Are there any intuitions on these different behaviors between AtSpeed-R and AtSpeed-S?
soundness: 3
strengths: - The approach proposed for applying speculative decoding to generative recommendation is both novel and intuitive.
- The experiments are comprehensive and provide convincing evidence of the benefits of AtSpeed from an empirical standpoint.
- The source code was made available.
summary: This paper introduces a speculative decoding approach for generative recommendation. In traditional speculative decoding, a cheap draft LLM is given a prefix and at each decoding step it suggests $N$ tokens among which the token predicted by the target LLM should be. This enables the target model to verify all the drafted predictions in parallel through a single call, conditioning on the draft model's previous predictions. The sequence of drafted predictions is then accepted up to the decoding step where the draft model and the target model disagree in their predictions.

In top-$K$ generative recommendation, a beam search is performed to generate the $K$ item identifiers. Applying speculative decoding to this problem then requires the $N$ tokens suggested by the draft model to contain the $K$ tokens predicted by the target model to accept the current decoding step. This condition is hard to fulfill in practice. To address this, the paper defines a framework named AtSpeed, which trains the draft model to be more aligned with the target model and optionally relaxes the acceptance condition to allow the $N$ drafted tokens to contain tokens that are similar (rather than identical) to the $K$ target tokens. AtSpeed was validated through experiments on the Amazon Beauty and Games datasets.
weaknesses: - The paper suffers from an overall lack of mathematical rigor, both in the proofs and notations, which raises concerns about the theoretical soundness of the approach. In particular, some key formulas, such as the proposed alignment objective, appear to be either incorrect or lack sufficient derivation to validate their correctness (see specific points in the 'Questions' section).
- The paper is overall lacking polish and contains multiple typos in mathematical formulas, which makes it hard for the reader to follow the details of the approach. Thorough proofreading would be needed to improve the paper's readability. Certain parts of the paper could also benefit from being further clarified, as pointed out in the 'Questions' section.

Meta-review: This paper studied the problem of speeding up using LLM-based model for top K recommendations, based on the framework of speculative decoding. 

Strength: 
1. An potentially useful technique for speeding up with LLM-based generative top K recommendation with some promising results.


Weakness:
1. Presentation and experimental  needs improvement.
2. Experimental results are a bit limited to two Amazon datasets. (Authors did expand on Movie-Lens in rebuttal.)

Decision: Accept (Poster)