Gated Slot Attention for Efficient Linear-Time Sequence Modeling

Authors: yue  zhang
songlin  yang
ruijie  zhu
leyang  cui
yiqiao  wang
bolun  wang
freda  shi
bailin  wang
wei  bi
peng  zhou
guohong  fu
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-15 08:54:40

Abstract: Linear attention Transformers and their gated variants, celebrated for enabling parallel training and efficient recurrent inference, still fall short in recall-intensive tasks compared to traditional Transformers and demand significant resources for training from scratch.
This paper introduces Gated Slot Attention (GSA), which enhances Attention with Bounded-memory-Control (ABC) by incorporating a gating mechanism inspired by Gated Linear Attention (GLA).
Essentially, GSA comprises a two-layer GLA linked via $\operatorname{softmax}$, utilizing context-aware memory reading and adaptive forgetting to improve memory capacity while maintaining compact recurrent state size.
This design greatly enhances both training and inference efficiency through GLA's hardware-efficient training algorithm and reduced state size.
Additionally, retaining the $\operatorname{softmax}$ operation is particularly beneficial in ``finetuning pretrained Transformers to RNNs'' (T2R) settings, reducing the need for extensive training from scratch.
Extensive experiments confirm GSA's superior performance in scenarios requiring in-context recall and in T2R settings.

Main paper: 
 introduction: 
 Transformers [88] have emerged as the predominant architecture for most, if not all, sequence modeling tasks. Nevertheless, the quadratic complexity of softmax-based standard attention (SA) poses significant challenges for long sequence modeling (e.g., video understanding and biological sequence modeling). In the context of language modeling, where sequence lengths are moderate, training efficiency is generally not a primary concern. However, during inference, the Key-Value (KV) cache [34, 64] grows linearly with the generation length, resulting in substantial memory burdens and throughput bottlenecks due to high I/O costs. Linear (kernelized) attention [42] and its gated variants [96, 82, 68, 61, 16, 69] have received interest as promising alternatives to softmax attention. These models demonstrate strong performance in language modeling and understanding tasks. Notably, they can be reframed as RNNs during inference, achieving constant memory complexity and thereby significantly enhancing inference efficiency.However, two key issues persist with these models: (i) Performance-wise, recent research indicates that linear recurrent models still struggle with tasks requiring in-context retrieval or learning [2, 1, 37, 28] , and there is a fundamental recall-memory trade-off [3, 91] where all inference-time-constantmemory models face inherent limitations. (ii) In terms of training efficiency, while linear attention supports hardware-efficient chunkwise training [96] as implemented in FlashLinearAttention (FLA [95] ), training from scratch on trillions of tokens remains prohibitively expensive. A paradigm, "finetuning pretrained Transformers to RNNs" (short for T2R [41] ), has recently gained great attention [101, 10, 54, 13, 7, 90] . This approach circumvents the high cost of training from scratch by requiring only a few billion tokens for finetuning-about 1-3% of the total cost. However, linear attention uses a different kernel method from softmax, leading to performance discrepancies when finetuning pretrained softmax attention models to linear attention [101] .To address these issues, we revisit the Attention with Bounded-Memory Control (ABC) model [63] , which retains the softmax operation, thereby reducing training-finetuning discrepancies between standard and linear attention, making it ideal for T2R settings. Additionally, ABC enables more effective state utilization, requiring less state size to achieve similar performance, as observed in Peng et al. [63] . This results in more efficient inference and potentially expands the Pareto frontier of the recall-memory tradeoff [3] . However, ABC has not gained significant attention due to its mediocre language modeling performance and slow training speed.In this work, we first reformulate ABC as two-pass linear attention linked via softmax, allowing us to leverage the hardware-efficient chunkwise implementation from FLA [95] for more efficient training. We then identify several limitations of ABC and propose a new model, dubbed Gated Slot Attention (GSA), which is essentially a gated version of ABC, following the recent trend of enhancing linear attention with gating mechanisms [96, 69, 61, 16, 6, 62, 52, 65] .Our extensive evaluation shows that GSA not only matches performance in language modeling and understanding tasks but also significantly outperforms other linear models in in-context recallintensive tasks [3, 4] , without requiring a large state size like RetNet [82] or GLA [96] . In the T2R finetuning setting, we found that finetuning Mistral-7B [39] to GSA surpasses large recurrent language models (e.g., RWKV6-7B, Mamba-7B) and also outperforms finetuning Mistral-7B to other linear models (e.g., RetNet, GLA) and other T2R methods like SUPRA [54] , verifying the importance of retaining the softmax operator. Finally, we remark that GSA achieves similar training speeds to GLA while offering an inference speedup due to its smaller state size. 
transformers as unbounded key-value memories: 
 Given X = [x 1 , . . . , x T ] ⊤ ∈ R T ×d , where T is the sequence length and x i ∈ R d is the i-th input vector with d dimensions, SA with causal masking computes the output matrix:EQUATIONwhere Q, K, V ∈ R T ×d are linear mappings of the input X via learnable weightsW q , W k , W v ∈ R d×d , M = {M ij = 1 if i ≥ j o.w.-∞} is the causal mask to prevent future information leakage, ⊙ denotes element-wise production, and f (•) is softmax (•).Generally, K, V can be viewed as neural key-value memories K t , V t ∈ R m×d , respectively [81, 24] , where m is the number of memory slots. At step t, the query q t = W q x t ∈ R d first attends to the key memories K t to retrieve relevant information, which is then summarized into o t by computing a weighted sum of the value memories V t [104] , where the weights are the normalized attention scores:EQUATIONFrom this perspective, Transformers are equipped with an unbounded number of memory slots, which grow linearly with respect to the sequence length [57] (i.e., m = t for step t)-a new key k t = W k x t ∈ R d is assigned with a unique memory slot upon its introduction. This leads to a simple memory updating rule:K t = K t-1 ∪ {k t }.The value memories V t are updated in a similar way. This mechanism, however, comes at the cost of quadratic time complexity in terms of the sequence length for training and O(T d) time/memory complexity for inference [64] , posing challenges for large-scale models.From a key-value memory perspective, the training and inference complexity of self-attention (SA) can be reduced by fixing the number of memory slots to a constant size m ≪ T [27, 51, 63] . One straightforward way to achieve this is by employing a first-in-first-out memory management strategy, commonly known as sliding window attention (SWA). However, SWA is inefficient because it discards all information outside the window, leading to poor performance in balancing the recall-memory tradeoff [3] . To achieve acceptable performance, SWA often requires a large window size (e.g., 4,096 tokens in Mistral [39] ), which diminishes its advantage over to global attention.When the number of tokens in a sequence exceeds the number of memory slots, it becomes necessary to store information from multiple tokens in a single slot. To address this challenge, Peng et al. [63] propose the Attention-with-Bounded-memory-Control (ABC) mechanism, which allows multiple tokens to be written into a single slot:EQUATIONHere, (ϕ i ) j represents the writing intensity of the ith token to the jth slot, obtained using a cumulative softmax function (cf. [63, footnote 5]), which can be computed with a prefix sum.ABC as two-pass linear attention. The outer-product-based additive memory update rule in Eq. 3 bears a resemblance to linear attention [42] , which involves the following recurrence3 :EQUATIONWe denote this linear attention operator that computes o i from q i , k i and v i (Eq. 5) by{o i } T i=1 = LA({q i , k i , v i } T i=1). We show that the ABC operations can be written as{o ′ i } T i=1 = LA({q i , k i , ϕ i } T i=1 ), {o i } T i=1 = LA({softmax(o ′ i ), ϕ i , v i } T i=1 ),whereo ′ i ∈ R m , o i ∈ R d .Therefore, ABC can enjoy hardware-efficient linear-time chunkwise training [96] , as implemented in the FLA library [95] .Remarks on state size. Peng et al. [63] empirically demonstrated that ABC requires a smaller state size to achieve comparable performance to other linear attention models, resulting in improved inference efficiency. We offer the following intuitive explanation: the new query o ′ aggregates the entire history through the initial pass of linear attention, making it more context-aware and better at locating desired items for retrieval. The subsequent softmax operator helps mitigate the attention dilution issue [66] . From the perspective of Hopfield networks, softmax can exponentially increase the memory size [45] . Together, these factors suggest that ABC may possess an implicit large memory capacity, even with a small actual recurrent state size.Linear attentions underperform softmax-attention Transformers in language modeling by a notable margin. RetNet [82] and TransnormerLLM [68] incorporate a data-independent exponential decay factor for memory update asS t = γS t-1 + k t ⊗ v t ∈ R d×d ,where γ ∈ (0, 1) is a scalar data-independent decaying factor; that is, the decay rate is fixed across time steps and hidden channels (under the same head), disrespect to the input tokens. RetNet has shown better language modeling performance compared to vanilla linear attentions thanks to the decaying mechanism. However, research in recurrent neural networks (RNNs) has shown that data-dependent decay (or forget gates) is crucial for selectively retaining and forgetting information [22, 26] , thus better leveraging the fixed recurrent hidden state. This selective mechanism has been revisited in recent state-space models [29, 16] . Inspired by LSTMs, Gated Linear Attention (GLA) [52, 96] introduces data-dependent decay parameters G t ∈ (0, 1) d×d to gate the hidden state as follows, [96] show that if gates are parameterized in an outer product form G t = α t ⊗β i , and α t , β t ∈ [0, 1] d depend solely on input x t , such recurrence can be rewritten as matrix multiplication, allowing for hardware-efficient training with a chunkwise parallel form. In what follows, we will use the following notation GLA({q i , k i , v i , α i , β i } T i=1 ) = {o i } T i=1 to denote this computation. It is common to set β i = 1 as in [96, 69, 61] , which is also often written in the following equivalent form:S t = G t ⊙ S t-1 + k t ⊗ v t ∈ R d×d , o t = S T t q t ∈ R d .S t = Diag(α t )S t-1 + k t ⊗ v t .Here k t can be viewed as the input gate, and α t can be viewed as the forget gate. In gated RNN literature, it is common to couple these two gates via k t = 1 -α t [12, 106, 67] . In particular, Qin et al. [69] proposed HGRN2, which uses this strategy as an improved parameterization of GLA, showing better performance in language modeling. 
motivation: issues with abc: 
 We identify two primary limitations in ABC's memory update rule. Firstly, it lacks a forgetting mechanism, resulting in indefinite retention of items once written into memory slots. This prevents efficient memory reuse by impeding the prompt clearance of slots for new information.Secondly, the rule introduces an unwarranted inductive bias favoring tokens at the sentence's beginning. This contradicts the recency bias in natural language, where more recent information is often more relevant. Prioritizing initial tokens over the recent ones conflicts with this inherent tendency in natural language processing. Specifically, for the first token, the writing strength to all slots is maximized (i.e., ϕ 1 = 1 ∈ R m ), causing every memory slot to retain a copy of the first token's representation. The absence of a forgetting mechanism exacerbates this issue. For subsequent tokens, the writing strength diminishes due to the influence of earlier tokens, as a result of the cumulative softmax in Eq. 4. This makes it challenging for the model to retain later tokens without learning a significantly large α i , potentially leading to instability in long-context settings, as observed by Zhang et al. [100] .To address these limitations, we propose Gated Slot Attention (GSA), which incorporates a gating mechanism to simultaneously resolve both issues by: (i) enabling the forgetting of historical information, and (ii) introducing a recency inductive bias, as detailed below.For each memory slot, the update rule is a simple gated RNN with a scalar data-dependent gating value α i ∈ [0, 1],( K t ) i = α i ( K t-1 ) i + (1 -α i )k t ∈ R d , ( V t ) i = α i ( V t-1 ) i + (1 -α i )v t ∈ R dand these can be written in matrix form, which is reminiscent of HGRN2 [69] .EQUATIONGSA as two-pass GLA. It is straightforward to see that we can write GSA as a two-pass GLA as shown below:EQUATIONTherefore, we can adapt GLA's hardware-efficient chunkwise training algorithm for GSA training, as shown in § A and § B. We illustrate the recurrent representation of GSA in Figure 1 .Vt-1 Vt The overall architecture of our proposed model, GSA, is shown in Figure 2 . Following the Llama architecture [86] , we use a stack of L GSA blocks, each comprising a GSA token mixing layer followed by a Gated Linear Unit (GLU) channel mixing layer [19, 33] .σ αt 1- kt vt q t + + × × × softmax × otWe utilize the multi-head attention mechanism [88] to capture different aspects of the input. For each head h, the input to GSA token mixing is defined asEQUATIONwhere ϕ is the Swish activation following [68] . The forget gate is obtained by a linear transformation followed by a sigmoid activation σ with a damping factor τ [96, 83] : 4 where the damping factor is to regulate the forget gate value to one, which has been shown to be crucial for long-term dependency modeling [30, 67] . We feed them into a GSA layer to obtain outputs as described in Eq. 7:α h i = σ(W h α x i ) 1/τ ,{o h i } T i=1 = GSA({q h i , k h i , v h i , α h i } T i=1) Finally, we obtain output viaEQUATIONThe total number of parameters for W q , W k , W v , and Wo is already 4d 2 , which is the same as in a single standard softmax-attention layer. To control the overall parameter count, we aim to keep the parameters for W α , which amount to dHm, relatively small. In practice, we set m = 64 to achieve a balance between efficiency and effectiveness ( § 4.1.4). One way to further manage the total parameter count is by reducing the number of heads. In practice, we set H = 4, ensuring that Hm ≪ d. This keeps the total number of parameters approximately equal to 4d 2 . 54 ExperimentsQuestion: For each theoretical result, does the paper provide the full set of assumptions and a complete (and correct) proof? Justification: We foresee no potential societal impact of this work. 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). 
language modeling: 
 We perform moderate-scale language modeling experiments with 1.3B and 2.7B parameters on Slimpajama corpus [79] for 100B tokens each.We compare the performance of GSA against Llama Transformer architecture (i.e., Xfmr++ [86] and recent subquadratic architectures including: Mamba [29] , RetNet [82] , GLA [96] and HGRN2 [69] .We refer readers to § C for more details on baselines and other experimental setups.Following [29, 96] , we report the perplexities and zero-shot performance of commonsense reasoning tasks including ARC e & ARC c (ARC-easy, ARC-challenge) [14] ; Hella. (Hellaswag) [99] , Lamb. (Lambada) [59] , PIQA [8] , Wiki. (Wikitext) [55] , and Wino. (Winograde) [73] . We note that these tasks are typically short in length and do not require in-context learning capabilities, thus they do not adequately reflect long-context modeling or in-context learning retrieval abilities. Nevertheless, as shown in Table 1 , we found that GSA performs comparably to the recent strong model HGRN2 with an equally sized hidden state, while outperforming GLA and RetNet even with a smaller state size. While subquadratic models can achieve comparable performance to (softmax-based) Transformers in language modeling and understanding tasks, their performance on recall-intensive tasks significantly lags behind Transformers and varies greatly across different subquadratic models, as observed in many recent studies [3, 4, 96, 97] . Therefore, it is crucial to improve linear models on in-context recall-intensive tasks. (a) Results on the synthetic MQAR task. We adopt the most challenging settings in [2] , utilizing a sequence length of 512 and 64 keyvalue pairs. Xfmr++ with standard attention achieves near-perfect results in this settings and is thus omitted for brevity.(b) Results on the recall-intensive tasks used in [4] . We truncate the input to a maximum of 2K tokens.State size FDA SWDE SQuAD NQ TriviaQA Drop Avg. MQAR. We first present the results on the multi-query associative recall (MQAR) task [2] , a diagnostic synthetic task that requires models to retrieve multiple associative key-value pairs from the context. This task has been shown to strongly correlate with language modeling performance [2] .The results in Table 3a validate the effectiveness of GSA. Real-world tasks. Next, we evaluate the zero-shot incontext learning performance on recall-intensive tasks, as used in Arora et al. [4] . 6 Specifically, we assess information retrieval on FDA [93] and SWDE [49] , which are designed to evaluate retrieval from in-context passages scraped from HTML/PDFs. We also evaluate question answering on SQuAD [70] , NQ [46] , TriviaQA [40] , and Drop [20] , where models must ground their answers in in-context documents.As shown in Table 3b , Xfmr++ achieves the best average performance, as expected. Meanwhile, GSA outperforms all other subquadratic baseline models by a notable margin without requiring a larger state size. We believe this advantage stems from GSA's context-aware memory readout mechanism (as discussed in §2.2) and its forgetting mechanism (i.e., the gating mechanism), enabling it to manipulate finite-sized memory more effectively.Table 2 presents the results of our ablation studies. Our findings indicate that: (i) the inclusion of the gating mechanism in GSA is crucial for improving language modeling perplexity; (ii) applying softmax non-linearities after the first recurrent pass is beneficial; and (iii) using 64 slots strikes an optimal balance between performance and efficiency. 7 Fig. 4a illustrates the training throughput for four models on a single H800 GPU 8 . To optimize memory usage, we employ the technique of recomputing the recurrent hidden state during the backward pass, as done in FLA [95] and Mamba2 [16] . This approach results in reduced memory consumption (Fig. 4b ) at the cost of slightly lower training throughputs (Fig. 4a ).Despite requiring two GLA passes, GSA maintains comparable training throughputs to GLA due to its reduced state size. Since inference is primarily memory-bound, inference speed highly correlates with state size. As a result, GSA, with its smaller state size compared to RetNet and GLA, achieves faster inference speeds, as shown in Figure 4c .The concept of finetuning pretrained Transformers to linear Transformers for recurrent inference was first introduced in T2R [41] . This approach uses pretrained language model weights to initialize all parameters, leveraging the similarity between linear attention and softmax attention, and finetunes all parameters, significantly reducing the total training time compared to training from scratch. Kasai et al. [41] also introduced a parametric feature map, implemented as a learnable MLP layer followed by ReLU, applied after the query/key projections. SUPRA, a follow-up to T2R, found that the original T2R approach did not perform well in the era of LLMs, and highlighted the importance of 6 Since our pretrained models are neither instruction-tuned nor instruction-aligned, following Arora et al. [4] , we use their Cloze Completion Formatting prompts for evaluation. It is noteworthy that results for certain tasks may differ significantly from those obtained using lm-evaluation-harness [21] due to variations in prompt templates. 7 Empirically, we found that 32, 64, and 128 slots result in training throughputs of 46.7K, 44.1K, and 37.1K tokens/s, respectively, under the settings described in the next section. Given the marginal improvement when increasing the slot size from 64 to 128, along with the significant slowdown in training, we chose 64 slots. 8 We utilize the training throughput benchmark scripts provided by FLA [95] for our measurements. output normalization and a decay mechanism-adopted from RetNet [82] -as critical for finetuning performance. As a result, SUPRA essentially combines T2R and RetNet by finetuning pretrained Transformers into a RetNet architecture, though it excludes the Swish output gate.Settings. In our preliminary experiments, we found that the learnable MLP layer was unnecessary and could be merged into the query and key projections, similar to the approach in Peng et al. [63] .We finetuned the pretrained Transformer Mistral 7B [39] to RetNet, as well as to GLA and GSA models. Following SUPRA, we add ReLU as the feature map activation for RetNet and GLA, which originally used an identity feature map without activation 9 , and also excluded the Swish output gate. For RetNet, there were no additional parameters; for GLA, the low-rank forget gate, and for GSA, the W α matrix are trainable parameters, though both are small in parameter count and negligible in terms of the total model size. We set the peak learning rate to 3 × 10 -5 with 1K steps of linear warmup following SUPRA. The training length was set to 2K tokens, with a batch size of 2M tokens.For convenience, we trained on the SlimPajama corpus, while SUPRA used RefineWeb [60] , a higher-quality corpus. We leave the use of RefineWeb for future work.Main results. Following Jiang et al. [39] , Touvron et al. [87] , we evaluated the models on commonsense reasoning tasks: ARC e and ARC c [14] , Hellaswag [99] , PIQA [8] , and Winogrande [73] ; world knowledge tasks: NQ [46] and TriviaQA [40] ; and popular aggregated benchmarks: MMLU [31] and BBH [85] . Results are shown in Table 3 . We observed a clear advantage in finetuning Mistral to GSA compared to GLA or RetNet, confirming our intuition that preserving softmax is beneficial in T2R settings. When trained with 100B tokens, Mistral-to-GSA outperforms RWKV6 and Mamba on average, even though those models were trained on over 1T tokens, thereby reducing the required training data size. Long-context ability evaluation. Following Xiong et al. [94] , we evaluated the models on long-sequence tasks, including Qasper [18] , Nar-rativeQA [44] , QuALITY [58] , and QMSum [105] . For each task, the input was truncated to 16K tokens, which is 8× the training length.The results are shown in Table 4 . Notably, GSA consistently outperforms other subquadratic models across all four tasks. We attribute this to the same factors observed in in-context recallintensive task settings. Interestingly, Mistralto-GSA also demonstrates overall better performance compared to RWKV6 and Mamba, which were trained from scratch on >1T token. 
related works: 
 Matrix-valued linear RNNs with hardware-efficient training. Traditional RNNs (e.g., LSTM [32] , GRU [12] ) maintain 1-dimensional hidden states, which are often too small to capture sufficient information. Recent work emphasizes the importance of expanding the size of recurrent states [29, 69, 96, 82, 61, 16] . However, naive state expansion dramatically increases FLOPs and I/O costs, making training impractical. To address this, Mamba introduces an I/O-aware approach, reducing I/O costs by materializing parameters and hidden states only on SRAM (instead of HBM). However, Mamba's recurrence cannot be expressed in matmul form, leading to two key issues: (i) high FLOP count cannot be optimized via tensor cores (the GPU's fast matmul unit), resulting in slower runtimes; and (ii) the recurrent hidden states cannot be compactly represented and must be materialized on SRAM during backpropagation, limiting the recurrent state size due to SRAM constraints.Mamba2 [16] addresses these limitations by adopting a linear attention [42] -like approach that enables hardware-efficient training. Linear attention expands the state using outer products, allowing for both parallel attention-style computation and recurrent inference (also known as state-space duality in Mamba2). The chunkwise algorithm interpolates between parallel and recurrent forms, enabling hardware-efficient, linear-time training [33, 82, 96] . However, vanilla linear attention underperforms softmax attention in various tasks. Recent research has explored incorporating various decay or gating mechanisms to enhance model expressiveness and performance while maintaining matmul-based parallelism and chunkwise training. These include head-wise data-independent decay [82, 68] ; head-wise data-dependent decay [62, 16, 6, 83] ; and channel-wise data-dependent decay [96, 52, 43, 69, 61] . GSA leverages two-pass gated linear attention to further enhance capacity while allowing hardware-efficient training.Fast weight RNNs. Fast weight programming [77] , a classical concept intensively investigated in deep learning [5, 103, 74, 76, 56, 75, 35, 36, 52] , has been shown to be closely related to (linear) Transformers [75] . The core idea involves using a slow network to produce rapid context-dependent weight modifications for the fast network. In linear attention, the fast network is a single-layer FFN with weight matrix S t (Eq. 5), while the slow networks are the query/key/value projections.Linear attention is known to suffer from limited memory capacity [75] , potentially due to the constraints of a single-layer FFN without a large representation. In contrast, ABC and GSA can be viewed as implementing a two-layer fast FFN with either additive update rule or gated update rule [74, 52] , where the weight matrices are K t and V t connected by the softmax activation function (Eq. 3 and Eq. 6). This structure resembles DeltaMLP [35] , which uses a delta update rule [92, 75, 98] and a multi-layer (potentially beyond two layers) fast FFN. The greater capacity of a two-layer FFN compared to a similarly sized single-layer FFN could explain why GSA requires a smaller state size to achieve similar or even better performance, especially in long sequence and recall-intensive tasks.Finetuning Transformers to RNNs. As discussed, this paradigm could significantly reduce the training cost for large-scale recurrent language models. The idea of distilling Transformers to RNNs to improve inference efficiency can be traced back to Gerstenberger et al. [23] . In the following, we briefly introduce some recent works that complement those already mentioned in §4.2 . Zhang et al. [101] highlight the desirable properties of softmax, such as attention spikiness and dot-product monotonicity, and employ a learnable MLP layer to approximate softmax behavior using logit distillation loss (while freezing other parameters). Chen et al. [10] introduce DiJiang, an effective method for approximating attention distributions using the Discrete Cosine Transform (DCT) to enable frequency-domain kernelization, leading to faster feature mapping. Bick et al. [7] propose a multi-stage distillation approach, aligning attention distributions (similar to Hedgehog [101] ), hidden states, and output logits to transfer knowledge from a pretrained Transformer teacher to a student Mamba model. Wang et al. [90] distill Transformer-based LLMs into hybrid Mamba-Attention architectures in the spirit of Ren et al. [71] , Lieber et al. [47] , Waleffe et al. [89] . However, they freeze the FFN weights, while Choi [13] suggest that it might be more effective to unfreeze them. In this work, we highlight the importance of the softmax operator, as discussed in Zhang et al. [101] , except that GSA directly incorporates softmax, while Zhang et al. [101] learns a feature map to mimic softmax, without actually including any softmax operator in the resulting model. 
limitations and future work: 
 Due to the relatively small scale of our pretrained models (compared to large-scale models trained on trillions of tokens), we did not report any results on long-context tasks, as the performance would all be poor. However, we believe Table 4 provides positive indications of GSA's long-context capabilities, and training on a larger token horizon and with larger models would address this. For copy-oriented tasks, we observed negative results on the Phonebook Lookup [38] and Needle-In-Haystack evaluations compared to Transformers, revealing the fundamental limitations of linear recurrent models in handling "precise local token shifts and comparison", as discussed in Arora et al. [3] . Nonetheless, we expect this limitation could be significantly mitigated by pretraining a hybrid GSA-attention model, as recently explored [3, 71, 89, 47, 98] , or by distilling pretrained Transformers into hybrid GSA-attention models, as in Wang et al. [90] , or using different training objectives with JRT prompts, as in Arora et al. [4] , or combining with YOCO [83, 25] .GSA follows GLA in using a gated update rule, although we acknowledge recent work on Parallel DeltaNet [98] , which parallelizes the delta update rule computations in DeltaNet [75] over sequence length, significantly enhancing training efficiency. The delta rule is known to improve in-context retrieval ability [75, 98] , aligning with one of the objectives of this work. We did not explore the analogous two-pass DeltaNet, but we leave this for future investigation, which would bring the approach closer to the original DeltaMLP [35] , as discussed earlier. It would also be beneficial to compare GSA with more recent strong RNN models, such as xLSTM [6] , Mamba2 [16] , TTT [84] ,and Longhorn [48] . 
conclusions: 
 This work introduces Gated Slot Attention (GSA), which enhances ABC [63] with a gating mechanism inspired by Gated Linear Attention (GLA [96] ). By framing GSA as a two-pass GLA, we can leverage hardware-efficient implementations of GLA [95] to train GSA. As such, GSA benefits from context-aware memory reading and forgetting, implicitly increasing the model's capacity despite a small actual state size, which improves training and inference efficiency. Through extensive experiments, we demonstrate the advantages of GSA in in-context recall-intensive tasks [4] and in "finetuning pretrained Transformers to RNNs" [41] scenarios. 
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: We foresee no such risks posed by this work.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 Question: Are the creators or original owners of assets (e.g., code, data, models), used in the paper, properly credited and are the license and terms of use explicitly mentioned and properly respected?Answer: [Yes] Justification: All of the datasets we use are publicly available at huggingface site, and we have properly cited all the training and evaluation datasets we used.Guidelines:• The answer NA means that the paper does not use existing assets.• The authors should cite the original paper that produced the code package or dataset.• The authors should state which version of the asset is used and, if possible, include a URL. • The name of the license (e.g., CC-BY 4.0) should be included for each asset.• For scraped data from a particular source (e.g., website), the copyright and terms of service of that source should be provided. • If assets are released, the license, copyright information, and terms of use in the package should be provided. For popular datasets, paperswithcode.com/datasets has curated licenses for some datasets. Their licensing guide can help determine the license of a dataset. • For existing datasets that are re-packaged, both the original license and the license of the derived asset (if it has changed) should be provided. 
 
 Appendix: Linear Attention (LA) [42, 66, 68] emerges as an alternative to resolve the quadratic complexity of self-attention (SA). The key idea is to use the kernel trick, which replaces softmax with a decomposable kernel function, resulting the following parallel form:EQUATION)where ϕ : R d → R m functions as feature mapping applied to each input. Unfolding Eq. 10, we haveEQUATION⊗ means outer product operation. It is clear that by leveraging the associativity, LA admits simple recurrent updating rules with matrix-valued hidden states S t ∈ R m×d :EQUATION) By reserving bounded m memory slots only, the overall computation complexity is reduced from O(T 2 d) to O(T md). When the sequence length is T ≫ m, d, the md factor has a minor impact on the complexity, and LA can be much more efficient than its counterpart with quadratic complexity.During inference, LA enjoys the merits of RNNs, which only need to maintain O(md) hidden memories, helping avoid the memory-cost KV cache management in SA mechanisms. However, Eq. 12 employs a simple additive updating rule and can be hard to "forget" unrelated information if necessary [62] , making the limited memory states vulnerable to be chaotic.Gating mechanism has played a key role in classical RNNs [32, 22, 12] , which serves as a mechanism to control the information flows in the network and help read and write from the memory selectively. [82] propose to apply a data-independent gate to LA, significantly narrowing the gap between LA and SA: [96, 43] further imposes a finer-grained data-dependent gate:S t = λS t-1 + ϕ(k t ) ⊗ v t , λ ∈ [0, 1] is a non-learnable scalar. Recent workEQUATIONwhere each α t ∈ [0, 1] m from A := {α i } T i=1 ∈ [0, 1] T ×m is dependent on the input. Alternatively, we can couple the key values with the forget gates by allowing ϕ(k t ) = 1 -α t in spirit of [12, 106] and [69] , which reduces the number of parameters and improves efficiency accordingly.Despite the theoretical advantages of linear complexity, the recurrent form of Eq. 12 is still inefficient during training. Such recurrent computation prevents the full utilization of modern GPU parallelism over sequence lengths [53, 72] . On the other hand, the parallel form (Eq. 10) can be parallelized in similar vein as in flash attention [17, 15] . However, due to the existence of the casual mask M, we can not rearrange its computation order by KV first, so that the parallel form still adheres to the quadratic complexity, which can hardly be scaled to very-long training context (e.g., sequences with more than 8K tokens).Chunkwise form recurrences have been carried forward by [82] , and achieve a good trade-off between the recurrent and parallel forms. [96] further disclose that the element-wise gating of Eq. 13 also satisfies the associative property required by parallel scan [9] and derive a parallelized chunkwise gated linear attention in a similar vein. The key idea is to partition the sequence into N = ⌈ T C ⌉ chunks of size C with Q [t] = q tC , q tC+1 , . . . , q tC+C , and so forth forK [t] , V [t] ∈ R C×d , A [t] ∈ R C×m .Firstly, unrolling the i-th hidden state in the t-th chunk in Eq. 13, we getEQUATIONWe write the last hidden in the chunk S [t],C as S [t] interchangeably for simplicity. Define- → A [t],i = i j=1 A [t],j ∈ [0, 1] d as the cumulative decay from the start of chunk to i, and likewise← - A [t],i = C j=i+1 A [t],j ∈ [0, 1] d from i + 1 to the end of the chunk, then S [t] = Diag( - → A [t],C )S [t-1] + (K [t] ⊙ ← - A [t] ) ⊤ V [t] (15) - → A , ← - A can be absorbed into Q, K first : Q [t] = ϕ(Q [t] ) ⊙ - → A [t] , K [t] = ϕ(K [t] ) ⊙ ( ← - A [t] / - → A [t],C). Combining them with Eq. 10 and Eq. 14, we derive the following vectorized updating rulesEQUATIONThe first term is referred to as the inter chunk part and the second term is the intra chunk part. The process to get this intra part is a little more involved as the cumulative productions of ← -A [t] / - → A [t],C is greater than 1, which can lead to numerical instability. [96] deal with this issue by proposing a secondary-chunking strategy, and we refer readers to their paper for more details.Hardward considerations Modern GPU architectures, such as the NVIDIA A100, offer highly optimized matrix multiplication (matmul) operations through specialized Tensor Cores, achieving up to 16× higher throughput than non-matmul operations [17] . However, this incurs IO overheads due to data transfer from slower, off-chip global high bandwidth memory (HBM) to on-chip shared memory (SRAM). The chunkwise form balances I/O and computation complexity tradeoffs. As shown in Eq.16, it improves parallelism over the sequence dimension while reducing non-matmul FLOPs greatly. Also, the chunk recurrent updating conducts the query and hidden states reduction in an online manner, requiring only O(N dm) hidden states materialized into HBMs, so that it can significantly reduce the memory/IO overheads. While LA enjoys much lower overall running FLOPs than SA, the chunkwise form displays a practical significant wall-clock speedup against SA, due to its hardware-efficient implementations [95] . Beyond the recurrent GSA form provided in Figure . 1, we give detailed, hardware-efficient procedures for the forward and backward passes of Gated Slot Attention (GSA) in Algorithm 1. For simplicity, we defineQ[1] K [1] ; I [1] Q[2] K [2] ; I [2] S k [0] S k [1] S k [2] O k [1] I [1] ; V[1] O k [2] I [2] ; V[2] S v [0] S v [1] S v [2] O [1] O [2]A = {α i } T i=1 ∈ [0, 1] T ×m , and I = {1 -α i } T i=1 ∈ [0, 1] T ×m .The algorithm demonstrates that GSA can be modeled as a two-pass GLA, as illustrated in Fig. 5 .In the preprocessing step, we precompute the chunkwise cumulative sum of the forget gate, resulting in -→ A . Subsequently, -→ A along with the queries, keys, and values are passed to engage in two GLA passes. For each chunk of size C, we define ← -A [i] := - → A [i],C / - → A [i]as in Eq. 15 and Eq. 16.In the first pass,- → A , ← - A is absorbed into Q, K : Q[i] = Q [i] ⊙ - → A [i] , K[i] = K [i] ⊙ ( ← - A [i] / - → A [i],C), then Q and K function as usual queries and keys, and the slot representations I serve as the value vectors.O k[i] = Qk [i] S k [i-1] O inter [i] + (( Qk [i] K⊤ [i] ) ⊙ M)I [i] O intra [i] ∈ R C×mWe use different notations from those presented in Eq.6 to enhance clarity in the chunkwise updating rules. The output O k is decomposed into the inter-chunk recurrence and intra-chunk parallel computations [96] . for i in range(0, NC): • Mamba [29] : State-space models with data-dependent decay.20 # [C, K|V] chunking 21 c_q, c_k, c_v, c_g = q[i], k[i], v[i], g[i]• RetNet [82] : Linear attention with non-learnable, data-independent head-wise decay and rotary embedding.• GLA [96] : Linear attention with elementwise data-dependent decay.• HGRN2 [69] : Gated Linear RNN with state expansion, or GLA with improved parameterization.Setup. For a fair comparison, all models are trained from scratch with the same training recipes. We utilize a subset of 100B tokens picked from the Slimpajama dataset [79] . The input tokens are processed using the Mistral tokenizer [39] 11 . We use AdamW [50] with a weight decay 0.01 as the optimizer. During training, the learning rate is first warmed up to 3 × 10 -4 in the first 1B tokens, and then decayed to 3 × 10 -5 gradually with a cosine schedule. The number of attention heads is set to 4 and 5 for 1.3B and 2.7B models, respectively. The number of memory slots is uniformly set to 64 for all models. We utilize the open-sourced Triton-based library FLA [95] to run all compared models.We ran all models on 32 Nvidia H800 GPUs. To facilitate distributed training and accelerate the process, we utilized the DeepSpeed framework and fused all necessary modules, including ROPE, cross-entropy, and LayerNorm, following the practice of [102] . The training of a GSA model with 2.7B parameters took approximately 2 days, while the 1.3B model required 1 day to complete training.Remark on state size. Let the model dimension be denoted as d. Mamba expands the value projection to 2d and uses a state expansion ratio of 16, resulting in a state size of 32d per layer. Since Mamba also replaces the FFN with a Mamba layer, this effectively doubles both the number of recurrent layers and the state size, leading to a total recurrent state size of 64Ld.Similarly, RetNet expands the value projection to 2d and sets the head dimension of queries/keys to be half that of the value head dimension. RetNet also reduces the number of heads to increase the head dimensions of queries and keys. We fix the query/key head dimension to 256 and adjust the number of heads accordingly, resulting in a recurrent state size of 512d per layer and 512Ld in total.GLA does not expand the value projection but reduces the head dimensions of queries and keys to half of the value head dimension to save parameters for the Swish output gate, ensuring each layer contains 4d 2 parameters. We fix the query/key head dimension to 256 and adjust the number of heads accordingly, resulting in a recurrent state size of 256d per layer and 256Ld in total.HGRN2 follows a similar approach to GLA but without the Swish output gate, keeping the head dimensions of queries/keys and values equal, as in standard softmax attention, while still retaining 4d 2 total parameters per recurrent layer. We set the head dimension to 128, resulting in a recurrent state size of 128d per layer and 128Ld in total.GSA maintains hidden states for both keys and values, so each layer contains a recurrent state size of 2 × 64 × d. We fix the state expansion (i.e., number of slots) to 64 12 , resulting in a total recurrent state size of 128Ld. Guidelines:• The answer NA means that the paper has no limitation while the answer No means that the paper has limitations, but those are not discussed in the paper. • The authors are encouraged to create a separate "Limitations" section in their paper.• The paper should point out any strong assumptions and how robust the results are to violations of these assumptions (e.g., independence assumptions, noiseless settings, model well-specification, asymptotic approximations only holding locally). The authors should reflect on how these assumptions might be violated in practice and what the implications would be. • The authors should reflect on the scope of the claims made, e.g., if the approach was only tested on a few datasets or with a few runs. In general, empirical results often depend on implicit assumptions, which should be articulated. • The authors should reflect on the factors that influence the performance of the approach.For example, a facial recognition algorithm may perform poorly when image resolution is low or images are taken in low lighting. Or a speech-to-text system might not be used reliably to provide closed captions for online lectures because it fails to handle technical jargon. • The authors should discuss the computational efficiency of the proposed algorithms and how they scale with dataset size. • If applicable, the authors should discuss possible limitations of their approach to address problems of privacy and fairness. • While the authors might fear that complete honesty about limitations might be used by reviewers as grounds for rejection, a worse outcome might be that reviewers discover limitations that aren't acknowledged in the paper. The authors should use their best judgment and recognize that individual actions in favor of transparency play an important role in developing norms that preserve the integrity of the community. Reviewers will be specifically instructed to not penalize honesty concerning limitations.For simplicity, we omit the normalization term, which has been shown to be unnecessary[75,66,52,82,96].In practice we set τ = 8.For instance, in a 1.3B model with H × m =× 4 = 256 and d = 2, 048, the total number of parameters amount to 4.125d 2 , introducing only a 0.125d 2 overhead.However, SUPRA reported poor performance with this strategy due to a significant discrepancy between training and finetuning, where an identity map can lead to negative attention scores, a pattern unseen in pretrained Transformers due to the nonnegativity of softmax.There is a normalization term in vanilla LA similar to softmax,[66] reveal that removing it could avoid potential gradient explosions.def gsa_fwd_k(q, k, v, g, C):https://huggingface.co/mistralai/Mistral-7B-v0.1Note that in this case, the number of heads is independent of the state expansion ratio 


Decision: This paper introduces Gated Slot Attention (GSA) for linear-time sequence modeling, which effectively addresses inefficiencies in traditional attention mechanisms for large language models. All reviewers agree that the method is both novel and impactful. During the rebuttal period, the authors provided additional empirical evidence and clarifications, particularly around memory management and computational performance, which directly addressed the reviewers' concerns. The discussions further solidified that the GSA approach offers substantial advancements over existing methods, validating its effectiveness in a variety of tasks. Based on the strong consensus among reviewers, the thoroughness of the rebuttal, and the high quality of the work, I recommend that the paper be accepted for publication.

Reviews: review: paper_summary: paper_summary: The paper explores a new variant of attention with bounded memory to reduce the growing memory size and thus mitigates the memory-intensive challenges of Transformers. The key idea is to set a memory bound, with a predetermined number of usable memory slots, and a gating mechanism to select or mix KV vectors from the previous step.
strength_weakness: strength_weakness: * The paper could clarify the significance of its proposed method. The results show not so much improvements compared with prior work in terms of performance and memory costs. The effectiveness and efficiency of the proposed method remain unclear.
* The writing on the presentation of the proposed method and the evaluation and insightful discussion could be improved.
questions: questions: * Fig. 1 can be better illustrated and explained how the proposed Gate Slot Attention works.
* What is the reason for choosing memory slots to fit in SRAMs? Particularly when the claim is for efficient training. 
* What is the contribution when the memory footprint as shown in Table 2 is larger than other methods? 
* What are the overheads, say additional parameters and operations, as introduced by this work?
* Some key results could be mentioned in the abstract and introduction.
* Fix the extra line-breaker as in line 255?
* The quotation marks used in line 128 to 135 are bizarre.
limitations: limitations: The limitation mentioned in the paper is moderate.
paper_summary: paper_summary: A major challenge is storing information in a bounded number of memory slots. This work builds on ideas from ABC and gated linear attention. ABC recursively updates the bounded-memory keys and values states over time, and computes a softmax with the queries at timestep t to produce the output at t. Gated linear attention and Mamba use data-dependent decays over time to better decide what information to keep versus throw away given the limited memory. GLA, unlike Mamba, enables the use of GPU tensor cores through its parameterization.

GSA retains the selective gating from GLA and the update rules from GSA. The architecture remains chunk-wise parallelizable (like GLA) and provides inductive biases that address limitations of GLA and ABC respectively. GSA is validated up to 2.7Bn parameters from scratch and 7Bn parameters in continual training, providing promising results on standard LM-eval harness benchmark tasks.
strength_weakness: strength_weakness: Building on my comment on the compelling properties of GSA, the paper does not extensively show how these properties make a difference in language modeling. It would be interesting to know how the “context aware query vectors” help GSA on real-world data by comparing to models without this property. OR for the authors to include discussion on what kind of sequences this property might help with. The architectural modifications are not tied to empirical insights beyond lm-eval harness scores in the current submission.

GSA is only evaluated on LM-eval harness. It is known that models perform somewhat similarly on these short-context tasks with very little memory (Arora et al, 2024) and mentioned in the paper’s limitations section. The paper does not dive into any tasks that require longer context reasoning or retrieval, making it unclear how GSA behaves. 
- "GSA only needs half the recurrent state size of GLA and a quarter the recurrent size of RetNet, while having better performance, thus enjoying a lower memory footprint during inference". The claim is not fully validated unless the GSA models are evaluated on tasks that stress-test memory utilization (like retrieval, long-context tasks).

The MMLU scores of the continually fine-tuned 7B checkpoints remains very low, just like the baseline – the other scores are roughly comparable across models. There is no analysis as to why this is. The paper claims that GSA is drastically better than SUPRA, but the delta is small (<1 point on average), so it is not clear what is meant by this claim.
questions: questions: 1. Why do the authors believe the current set of benchmarks is sufficient? Is it possible to include results on retrieval and longer context benchmarks? 

2. Can the authors perform error analysis on the continually trained models to help understand why SUPRA and GSA perform poorly on MMLU? 

3. Can the authors provide more concrete hypotheses as to where context-aware query tokens (resulting from the first GLA pass) could help in real language modeling settings? 

In the introduction, “slots” are not defined. They are first defined in section 2.
limitations: limitations: The authors do mention that they ignore retrieval style tasks in their analysis (in Section 6), however if the paper makes claims about memory-efficiency then it is important to evaluate quality on this style of tasks. This is because it is known that there are fundamental memory and quality tradeoffs.

If the reviewers address these concerns, I will consider increasing my score!
paper_summary: paper_summary: The paper introduces Gated Slot Attention (GSA), an enhancement of Gated Linear Attention (GLA), aimed at improving the efficiency of sequence modeling. GSA incorporates a selective gating mechanism to manage memory updates, leveraging a two-pass GLA structure. This approach allows GSA to be more context-aware and to retain a bounded memory footprint, making it suitable for long sequence tasks. 
The key improvement is the incorporation of a softmax operation to retain sharp attention distributions, which enhances sequence modeling by reducing dilution.
strength_weakness: strength_weakness: - While GSA presents improvements, it largely builds on existing GLA techniques. The enhancements, though valuable, might be seen as incremental rather than revolutionary, potentially limiting the perceived impact of the work.
- Despite efforts to reduce computational overhead, the softmax operation on $QK^T$ still retains a quadratic complexity in training. This raises questions about the authors' claim of linear-time sequence modeling in the title, which could be misleading.
- The authors do not specify explicitly whether GSA inherits the recurrent architecture of GLA. If this is the case, it would be necessary to compare GSA to other recurrent models like RWKV to provide a comprehensive evaluation of its performance and advantages in sequence modeling tasks.
questions: questions: How does the inference performance of GSA compare to other SOTA models in terms of speed and memory usage?
limitations: limitations: Yes

Comments: title: Response to All Reviewers
Thanks
Response to Reviewer eYuC: additional inference efficiency comparisons
Response to Reviewer LU5r13: speed analysis
Thank you for your response
comment: We sincerely thank each reviewer for their thoughtful feedback and recognition of the improvements presented in our rebuttal.
We've added new results on recall-intensive tasks and challenging language understanding and reasoning tasks, as well as length extrapolation to address the concerns raised by Reviewers AbD2 and LU5r. Further analysis on time and memory complexity and comparisons of inference performance were also provided in response to common concerns.

We are pleased that our additional empirical results, detailed analysis, and explanations have addressed your concerns and contributed to raising your scores. 
All reviewers have acknowledged our contributions and given positive feedback to our work.

We are committed to further enhancing our work. 
In the next version, we will incorporate all suggested revisions to improve clarity, polish the writing, and rectify any remaining errors. 
Additionally, we will:
* Release our code: Make our codebase publicly available to facilitate further research and validation of our methods, including Triton kernels for training and inference.
* Provide pretrained weights: Release all pretrained weights, including 1.3B, 2.7B, and 7B parameters.

We sincerely value your input and look forward to sharing our work more widely.
Thank you once again for your detailed reviews and assistance in enhancing our submission.
Thank you! We're glad our clarifications were helpful. We'll include these new results in the next version.
Thank you for the clarification, and the new results are helpful. I will revise my evaluation.
Dear Reviewer AbD2,

This is a kind reminder that today is the last day of the author-reviewer discussion period. If you have any concerns, please let us know as soon as possible so that we can address them.
Thank you very much! We are delighted that our response has addressed your concerns. We will incorporate these new results in the next iteration of the paper.
I have raised my score
To provide more clarity, we conducted additional comparisons on an H800 GPU, optimizing our inference kernel for GSA to perform one-by-one generation. 
This optimization significantly reduces I/O overhead for 2-pass recurrences, which is crucial for auto-regressive generation. 
Our updated results show:

|     | Transformer++ |          GLA |          GSA |
| --- | ------------: | -----------: | -----------: |
| 2k  |   85.0 (14.9) |  77.3 (14.0) |  78.0 (14.1) |
| 4k  |  169.4 (15.5) | 140.9 (13.9) | 141.7 (14.1) |
| 8k  |  350.5 (16.6) | 274.6 (13.9) | 269.2 (14.0) |
| 16k |  783.1 (18.8) | 528.0 (13.9) | 517.1 (14.1) |


We compare the inference latency (seconds) as well as the memory consumption of Transformer++, GLA, and GSA for a single sequence.
By varying the generation length from 2k to 16k:
* GSA maintains consistent memory usage across different sequence lengths, unlike Transformer++ which consumes up to 4GiB more for 16k sequences.
* GSA shows comparable or slightly better inference speed than GLA, especially for longer sequences, thanks to our optimized fused kernel.

These findings underscore GSA's competitive performance in real-world scenarios, combining the theoretical advantages of linear attention models with practical optimizations. 
We are committed to further exploring and implementing optimizations to fully realize GSA's potential and enhance its real-world performance.

We hope this clarifies our contribution and strengthens our paper's position.
Thank you for your question and we are happy to provide further clarifications on the speed comparisons during both training and inference:

**Training** 

For sequence length $N$, chunk $C$, and head dimension $d$:
* GLA with chunkwise parallelism requires $O(NC d + N d^2)$ FLOPs and $O(Nd)$ additional memory for forget gates [1].
* GSA with $m$ memory slots (modeled as two-pass GLA recurrences) requires $O(NC m + NC d + 2N md)$ FLOPs and $O(Nm+Nd)$ memory.
  
In our experiments, we set $m=64$ to leverage tensor core accelerations, as matmuls operating on $64\times 64$ tiles are shown to be highly hardware-efficient [2]. 
For models > 1B, $d$ is larger than 512. 
In these cases, despite the two-pass nature, GSA's complexity ($O(NC m + NC d + 2N md)$) can be lower than that of GLA ($O(NC d + N d^2)$) since $2md=128d < d^2$.

**Inference**

Both GLA and GSA maintain constant time and memory complexity during token-by-token generation. We also implemented fused kernels to reduce the IO overhead for operations like $\mathtt{softmax}$, potentially making GSA faster than GLA implementations in FLA [3].

For comparison, Transformers require quadratic time complexity for training and $O(N)$ time and memory for inference.

To illustrate the efficiency, we provide inference latency (seconds) for a single sentence beyond the training speed / memory analysis in Table 2 of our paper:

|     | Transformer++ |   GLA |   GSA |
| --- | ------------: | ----: | ----: |
| 2k  |          85.0 |  77.3 |  78.0 |
| 4k  |         169.4 | 140.9 | 141.7 |
| 8k  |         350.5 | 274.6 | 269.2 |
| 16k |         783.1 | 528.0 | 517.1 |

Note: We used the basic Huggingface `model.generate` API for demonstration, leaving room for further optimization.
* Transformer++ underperforms even at moderate lengths (2k) and scales poorly.
* GSA performs comparably to GLA, slightly outperforming it for sequences >8k due to our optimized fused inference implementations.

We will include a detailed speed analysis for both training and inference in our revised manuscript. 
Thank you for bringing this to our attention.

[1] Gated Linear Attention Transformers with Hardware-Efficient Training: https://arxiv.org/abc/2312.06635

[2] GPUs Go Brrr: https://hazyresearch.stanford.edu/blog/2024-05-12-tk

[3] FLA: A Triton-Based Library for Hardware-Efficient Implementations of Linear Attention Mechanism: https://github.com/sustcsonglin/flash-linear-attention
The new experiments are helpful. 

Can the authors further explain why GSA should be faster or equal in speed to GLA, despite using two-passes? The writing around this point could be clarified.
Dear Reviewer eYuC,

Could you please let us know if our response has addressed your concerns? If you have any further questions, please feel free to raise them at any time.
Dear Reviewer LU5r,

Could you please let us know if our response has addressed your concerns? If you have any further questions, please feel free to raise them at any time.
Dear Reviewer AbD2,

Could you please let us know if our response has addressed your concerns? If you have any further questions, please feel free to raise them at any time.