Stick-breaking Attention

## Abstract

Abstract The self-attention mechanism traditionally relies on the softmax operator, necessitating positional embeddings like RoPE, or position biases to account for token order.
But current methods using still face length generalisation challenges.
We propose an alternative attention mechanism based on the stick-breaking process:
For each token before the current, we determine a break point β i , j subscript 𝛽 𝑖 𝑗 \beta_{i,j} italic_β start_POSTSUBSCRIPT italic_i , italic_j end_POSTSUBSCRIPT , which represents the proportion of the remaining stick to allocate to the current token.
We repeat the process until the stick is fully allocated, resulting in a sequence of attention weights.
This process naturally incorporates recency bias, which has linguistic motivations for grammar parsing (Shen et al., 2017 ) .
We study the implications of replacing the conventional softmax-based attention mechanism with stick-breaking attention.
We then discuss implementation of numerically stable stick-breaking attention and adapt Flash Attention to accommodate this mechanism.
When used as a drop-in replacement for current softmax+RoPE attention systems, we find that stick-breaking attention performs competitively with current methods on length generalisation and downstream tasks.
Stick-breaking also performs well at length generalisation, allowing a model trained with 2 11 superscript 2 11 2^{11} 2 start_POSTSUPERSCRIPT 11 end_POSTSUPERSCRIPT context window to perform well at 2 14 superscript 2 14 2^{14} 2 start_POSTSUPERSCRIPT 14 end_POSTSUPERSCRIPT with perplexity improvements. \faGithubSquare https://github.com/shawntan/stickbreaking-attention

## 1 Introduction

The Transformer architecture (Vaswani et al., ) uses a self-attention mechanism based on the softmax operator that enables the model to weigh the importance of different tokens in the input data.
However, the reliance on softmax requires using positional embeddings to introduce information about the order of tokens, as the attention mechanism itself is permutation-invariant.
The sinusoidal position embedding as proposed in Vaswani et al. () has since evolved to relative positional embeddings (Shaw et al., ).
Learned relative positional biases were used in the T5 model (Raffel et al., ), and later fixed relative positional biases in Press et al. ().
At the time of this writing, a commonly used form of position embedding is RoPE (Su et al., ).
Allen-Zhu & Li () observe that, in a context-free grammar parsing setting, attention mechanisms attend to the “most adjacent” non-terminal.
This suggests an inclination to attend to the most recent entry that matches a given criteria.
However, even with relative position information, it is possible to overfit on specific relative positions, resulting in failure to generalise.
Kazemnejad et al. () show that decoder-only Transformers with No Positional Embeddings (NoPE) can implicitly recover positional information, experimental results suggest that NoPE Transformers generalise better on length.
While this is promising, a higher attention score from an irrelevant token in the sequence can function as a distractor (Kazemnejad et al., ; Xiao et al., ).

The stick-breaking process may have properties that can alleviate the previously mentioned issues, and possess the ‘most recent’ bias from Allen-Zhu & Li () we want.
For a token at position $j$ attending to position $i$, suppose the attention weight is given by:

$$ ${\bm{A}}_{i,j}=\beta_{i,j}\prod_{i<k<j}\left(1-\beta_{k,j}\right)=\sigma(z_{i, j})\prod_{i<k<j}\left(1-\sigma\left(z_{k,j}\right)\right),$ $$

where $z_{k,j}$ are the attention logits.
To illustrate via intuition, for ${\bm{A}}_{i,j}$ to be high, all $\beta_{k,j}$ for $i<k$ have to be low.
Conversely, as long as any $\beta_{k,j}$ for $i<k$ is high, ${\bm{A}}_{i,j}$ will be low, as a token between $i$ and $j$ has already been attended to.

Figure: Figure 1: Differences in formulation between stick-breaking and softmax. Stick-breaking assigns high weights to the most recent high logit, while softmax will assign equal weightage to equal logits.
Refer to caption: extracted/5947554/figures/stickbreakingvsoftmax.png

Shen et al. () makes a similar observation as in Allen-Zhu & Li (), and explicitly uses a stick-breaking process to model local structure.
Csordás et al. () introduces Geometric attention, named after the Geometric distribution, which only has one parameter $p$, which gives the probability of success per trial.
The geometric distribution then gives the probability for which $k$ trials are needed for the first success: $(1-p)^{k-1}p$.
But in stick-breaking and in Geometric attention (Csordás et al., ), each $p$ is assigned a different value that corresponds to the attention score between two tokens.

In this paper, we expand upon prior work on this attention mechanism (Csordás et al., ; Shen et al., ).
We focus on the implications of replacing the softmax-based attention mechanism with the stick-breaking process:

- 1.
We compare the different properties of stick-breaking attention against softmax attention,
- 2.
We discuss numerically stable implementations of the stick-breaking attention, and make stick-breaking amenable for large-scale training by implementing a kernel for stick-breaking in Triton,
- 3.
We show the performance of stick-breaking attention on length-generalisation in language modelling, and evaluate 1B and 3B parameter models on various NLP tasks.

## 2 Stick-breaking Attention

For a sequence of $L$ tokens, we have query ${\bm{q}}_{i}\in\mathbb{R}^{d_{\mathrm{head}}}$, key ${\bm{k}}_{i}\in\mathbb{R}^{d_{\mathrm{head}}}$, and value ${\bm{v}}_{i}\in\mathbb{R}^{d_{\mathrm{head}}}$ vectors for $1\leq i\leq L$.
Then the attention weight for token at $j$ attending to position $i$ is computed by:

$$ $\displaystyle{\bm{o}}_{j}$ $\displaystyle=\sum_{i=1}^{j-1}{\bm{A}}_{i,j}\cdot{\bm{v}}_{i},$ $\displaystyle{\bm{A}}_{i,j}$ $\displaystyle=\beta_{i,j}\prod_{i<k<j}\left(1-\beta_{k,j}\right),$ $\displaystyle\beta_{i,j}$ $\displaystyle=\sigma\left(z_{i,j}\right),$ $\displaystyle z_{i,j}$ $\displaystyle=\frac{{\bm{q}}_{j}^{\top}{\bm{k}}_{i}}{\sqrt{{d_{\mathrm{head}}}}}$ (1) $$

Equation 1 is the main difference between our proposal and softmax attention.
As discussed earlier and in Csordás et al. (), this parameterisation biases towards recency.
Specifically, for any pair of $i$ and $i^{\prime}$ such that $i-j<i^{\prime}-j$ and $z_{i,j}=z_{i,j}$, then ${\bm{A}}_{i,j}\geq{\bm{A}}_{i^{\prime},j}$.
Consequently, this imposes an ordering on the attention, and we do not use position embeddings with the query and key embeddings.

We consider two sets of logits, $z_{i,j}$ and $z^{\prime}_{i,j}$ and their respective attention weights ${\bm{A}}_{i,j}$ and ${\bm{A}}^{\prime}_{i,j}$.
If $z_{i,k}=z^{\prime}_{i,k}$ for $i<k<j$, then ${\bm{A}}_{i,j}={\bm{A}}^{\prime}_{i,j}$.
Further, if $\sum_{k=i}^{j-1}{\bm{A}}_{k,j}=1$, then the output is invariant to appending additional context earlier than $i$.
This means that unlike softmax attention, a high attention score further back in the sequence does not ‘distract’ from a more recent high $z_{i,j}$ score.
We note that $\sum_{i=1}^{j-1}{\bm{A}}_{i,j}\leq 1$, which allows this attention mechanism to attend to nothing when all $\beta_{i,j}=0$.

## 3 Related Work

##### Stick-breaking Process

The stick-breaking process formulation of the Dirichlet process (Sethuraman, ) is also known as the GEM distribution, first coined in Ewens () after Griffiths (), Engen (), and McCloskey ().
The GEM is a specific case of what was known as a Residual Allocation Model (RAM; Allen & Lambie ).
There are instances of the distribution being used as a differentiable attention-like mechanism in neural models.
Shen et al. () used stick-breaking process for modelling language, and showed that the model can induce grammatical structure to some extent.
Csordás et al. () used stick-breaking attention, which they refer to as Geometric attention, in a bidirectional encoder set up.
Shen et al. () used stick-breaking attention in a decoding-only setup, but does not explicitly study the properties of stick-breaking.

##### Softmax attention, Positional embeddings, and Length Generalisation

Bondarenko et al. () observe that softmax attention tends to attend to low-information tokens with high scores in order to ‘do nothing’.
Xiao et al. () introduces *attention sinks*, a learnable token that the attention can assign attention weights to.
Irie et al. () and Haviv et al. () find that in a decoder-only setting, a Transformer with no positional embedding can work fairly well.
Kazemnejad et al. () also found similar results, while also showing that NoPE has a tendency to attend to the start of the sequence, while ALiBi (Press et al., ) has a tendency to only attend to the most recent tokens.
However, Zhou et al. () later found that Transformers without position embeddings do not generalise to out-of-distribution sequence lengths for an addition task.
At present, Rotary Positional Embeddings (RoPE; Su et al. ) are the most commonly used position embedding.
It encodes relative positions via multiplicative interactions with the key and query.
RoPE has been found to generalise to out-of-distribution lengths poorly (Press et al., ; Zhou et al., ; Kazemnejad et al., ), but a common trick to extend the context window RoPE-based Transfomers is to use NTK-aware RoPE scaling (bloc97, ).

##### Conditional Computation

The use of stick-breaking for conditional computation has also been explored.
Tan & Sim () uses a the stick-breaking distribution as a mixture over outputs for each layer in an MLP for an acoustic model.
Graves () also suggested a similar formulation for language modelling.
Later, Banino et al. () and Tan et al. () also use a stick-breaking formulation for dynamic depth modelling in a Transformer model.
These prior works use conditional computation on the *depth* of the model, while in our case, we use stick-breaking as a method of restricting the computation *length*-wise.

##### Connection to Selective State-space Models

Each stick-breaking attention head at every time-step can be viewed as the hidden state of the final step of a selective State-space Model (SSM;Gu & Dao ).
For a given time-step $j$, consider the following SSM and its convolutional form (as described in Merrill et al. ):

$$ $\displaystyle\hat{{\bm{o}}}_{i,j}=(1-\beta_{i,j})\cdot\hat{{\bm{o}}}_{i-1}+ \beta_{i,j}\cdot{\bm{v}}_{j},$ $\displaystyle{\bm{o}}_{j}=\hat{{\bm{o}}}_{j-1,j}=\sum_{1\leq i\leq j}\left( \beta_{i}\prod_{i<k<j}(1-\beta_{k})\right)\cdot{\bm{v}}_{i},$ (2) $$

which is equivalent to the first term in Equation 1.
Typically, an attention layer for a Transformer with hidden dimension $d_{\mathrm{hidden}}$ has $h$ heads such that $d_{\mathrm{hidden}}=h\cdot{d_{\mathrm{head}}}$.
For equivalence with an SSM, we need a constant query vector and each dimension as a separate head, e.g. ${\bm{q}}_{i}=\mathbf{1}$ for all $i$, and $h=d_{\mathrm{hidden}},{d_{\mathrm{head}}}=1$.

##### Connection to Additive Relative Position Encoding (Additive RPE; Kazemnejad et al. 2024 )

Generally, Additive RPEs incorporate an added bias function $g$ of the distance of the tokens $i-j$ and the maximum length of the sequence $L$:

$$ $\displaystyle{\bm{A}}_{ij}$ $\displaystyle\propto\exp\left({\bm{q}}_{j}^{\top}{\bm{k}}_{i}+b\right)$ $$

In the case of ALiBi (Press et al., ), this is a linear function $b=-m\cdot(j-i)$.
This implies that the attention weights will drop off exponentially the further $j$ and $i$ are apart, regardless of the attention scores.
In stick-breaking, Equation 3 has a form that accounts for the scores from $j$ to $i$ with the bias $b=-\sum_{k=i+1}^{j}\log\left(1+\exp(z_{k,j})\right)$.
Specifically, if $\log\left(1+\exp(z_{k,j})\right)\geq m$, then $b\leq-m\cdot(j-i)$.
This suggests a learnable relative position bias that is dependent on the intermediate scores between $j$ and $i$.

## 4 Implementation

Implementing stick-breaking attention naively in PyTorch results in realising the $L^{2}$ matrix for the attention logits (where $L$ is the length of the input).
FlashAttention (Dao et al., ) reduces the memory footprint of attention by side-stepping the $O(L^{2})$ memory complexity of realising the attention matrix.
In order to achieve this, it only realises tiles of the attention logits and weights at a time, and accumulates the resulting weighted sum of ${\bm{v}}_{i}$.
In this section we detail the important differences between computing softmax attention and stick-breaking.

Figure: (a) Forward pass

##### Forward

Computing Equation 1 directly will result in underflow issues, especially with lower precision training.
We perform the operations in log-space, which results in a cumulative sum instead:

$$ $\displaystyle{\bm{A}}_{i,j}$ $\displaystyle=\exp\left(\log\beta_{i,j}+\sum_{k=i+1}^{j-1}\log\left(1-\beta_{k ,j}\right)\right)$ $\displaystyle=\exp\left(z_{i,j}-\sum_{k=i}^{j-1}\log\left(1+\exp(z_{k,j}) \right)\right)$ (3) $$

Where $\log\left(1+\exp(\cdot)\right)$ is commonly known as the $\mathrm{softplus}$ operation, which we further numerically stabilise with the following computation:

$$ $\mathrm{softplus}(x)=\begin{cases}\log\left(1+\exp(x)\right),&\text{if }x\leq 1 5\\ x&\text{otherwise}\end{cases}$ (4) $$

to prevent overflowing of $\exp(x)$.

##### Backward

Let $\tilde{{\bm{A}}}_{i,j}=\log{\bm{A}}_{i,j}$, then:

$$ $\displaystyle\dfrac{\partial\mathcal{L}}{\partial\tilde{{\bm{A}}_{i,j}}}$ $\displaystyle=\dfrac{\partial\mathcal{L}}{\partial{\bm{A}}_{i,j}}\cdot{\bm{A}} _{i,j},$ $\displaystyle\frac{\partial\mathcal{L}}{\partial z_{i,j}}$ $\displaystyle=\underbrace{\dfrac{\partial\mathcal{L}}{\partial\tilde{{\bm{A}}_ {i,j}}}}_{\text{Contribution from }i,j}-\underbrace{\sigma(z_{i,j})\sum_{i^{ \prime}=1}^{j-1}\dfrac{\partial\mathcal{L}}{\partial\tilde{{\bm{A}}_{i^{\prime },j}}}}_{\text{Contribution from before }i,j}$ (5) $$

The above equations dictate the direction of the order of computation for our implementation.
For the forward pass (Eqn. 3), we compute from $j$ to $1$, backwards through time and accumulate $\sum_{k=i+1}^{j}\log\left(1+\exp(z_{k,j})\right)$.
For backward pass (Eqn. 5), we compute from $1$ to $j$, accumulating $\sum_{j^{\prime}=1}^{j-1}\frac{\partial\mathcal{L}}{\partial\tilde{{\bm{A}}_{i
,j^{\prime}}}}$.

### 4.1 Triton Specifics

We modify the Triton implementation of Flash Attention for accelerating the stick-breaking attention.
In theory, the memory complexity of implementing stick-breaking attention would be similar to that of Flash Attention, $O(L)$.
Due to the limitations of Triton, we borrow from Dao () and use a two-phased backward pass: the first phase accumulating gradients for ${\bm{Q}}$ , and the second phase accumulates gradients for ${\bm{K}},{\bm{V}}$.
Due to the intermediate accumulated values ${\color[rgb]{0.65234375,0.109375,0}\definecolor[named]{pgfstrokecolor}{rgb}{
0.65234375,0.109375,0}{\bm{a}}},{\color[rgb]{0,0,1}\definecolor[named]{
pgfstrokecolor}{rgb}{0,0,1}{\bm{b}}}$, our implementation results in a $O(L^{2})$ memory complexity.
However, the constant factor in the quadratic complexity here is inverse of the predetermined block size $d_{\mathrm{block}}$: larger block sizes reduces the memory allocation.
In our implementation, $d_{\mathrm{block}}=64$.
Algorithms 1 details the forward pass (illustrated in Figure 2(a)), and Algorithms 2 & 3 details the backward pass (illustrated in Figure 2(b)).

Figure: Algorithm 1 Forward thread $i$

Figure: Algorithm 2 Backward-${\bm{q}}$ thread $i$

##### Throughput

We measure throughput on Dolomite Engine (Mishra, ) with a 1B class model on a node with 8 H100 GPUs.
Stick-breaking attains a throughput of 16.27 billion tokens / day.
This is a a 19.9% performance drop compared to Flash Attention, which attains throughput of 19.5 billion tokens / day.
Despite the slowdown, the Triton implementation allows the method to be used for long sequences as the naive Torch implementation causes out-of-memory issues.

##### Conditional computation

We can incorporate speedups due to the specific nature of the stick-breaking process.
Since, we accumulate ${\bm{A}}_{k,j}\cdot{\bm{v}}_{k}$ from the diagonal to $k=1$, when $\sum_{i=k}^{j-1}{\bm{A}}_{i,j}=1$ for some $k$, we know that all ${\bm{A}}_{k^{\prime},j}=0$ where $k^{\prime}<k$.
Therefore, once the condition is met, we can skip all subsequent accumulations.
We implement block skipping only the forward pass, and measured the time elapsed on a subset of 10,000 instances of The Pile(^1^11[https://huggingface.co/datasets/NeelNanda/pile-10k](https://huggingface.co/datasets/NeelNanda/pile-10k)).
Evaluating on 16K context lengths using the the LM evaluation harness (Gao et al., ) with a batch size of 1, we find that early halting allows for a 9.3% percent speed improvement.

## 5 Experiments

In this section, we compare existing attention methods against stick-breaking.
We first look at a modification of a synthetic task from Arora et al. () to understand the inductive biases of stick-breaking.
We then compare the stick-breaking against existing length extrapolation methods on a 350M model setting.
We then pretrain a 1B parameter model, and evaluate it on various NLP benchmarks, and evaluate it for length extrapolation and retrieval capabilities on long context using the RULER benchmark (Hsieh et al., ).
We also report benchmark results for a 3B model we have trained.
For reference, the size of the models are detailed in Table 1.

**Table 1: Model hyperparameters and total size**
|  | $n_{\mathrm{layer}}$ | $d_{\mathrm{hidden}}$ | $d_{\mathrm{inter}}$ | $n_{\mathrm{head}}$ | $L$ | Total params. |
| --- | --- | --- | --- | --- | --- | --- |
| 350M | 24 | 1024 | 2730 | 32 | 2048 | 367,526,912 |
| 1B | 40 | 1536 | 4096 | 24 | 4096 | 1,208,083,968 |
| 3B | 40 | 2304 | 9216 | 36 | 4096 | 3,513,473,280 |

### 5.1 Multi-Query Repeated Associative Recall Task

To illustrate the inductive bias of stick-breaking attention, we first analyse its behaviour on a simple synthetic task.
Arora et al. () demonstrate that there is a correlation between *multi-query associative recall* (MQAR) and the performance of language modelling.
They show that while Transformers, which are based on attention can easily handle MQAR, the current linear state-space models cannot.

Figure: Figure 3: MQRAR performance on increasing key-value pairs.
Refer to caption: extracted/5947554/figures/mqrar.png

While stick-breaking can also solve the MQAR task, we formulated a different version of this toy task and tested it on both softmax attention and stick-breaking.
As before, each instance of the task has an initial assignment of values to variables.
However, in the query sequence, the same variable can be queried multiple times, and each query is then followed by a variable assignment, which successive queries must recall.
We refer to this task as *multi-query repeated associative recall* (MQRAR).

| Input | B | 6 | P | 4 | E | 3 | X | 1 | Z | 2 | E | 2 | B | 1 | E | 5 | B | 4 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Output | $\phi$ | $\phi$ | $\phi$ | $\phi$ | $\phi$ | $\phi$ | $\phi$ | $\phi$ | $\phi$ | $\phi$ | 3 | $\phi$ | 6 | $\phi$ | 2 | $\phi$ | 1 | $\phi$ |

We compare Transformer models with Softmax and RoPE against stick-breaking attention, comparing their ability to handle MQRAR with increasing key-value pairs: from 32 to 192, in increments of 32.
The full sequence length is 768.
Both models are 2-layer Transformers with 256 hidden dimension and one attention head.
We sweep through 4 learning rates of $\{10^{-4},10^{-\frac{10}{3}},10^{-\frac{8}{3}},10^{-2}\}$, and report the results of the best performing model.
Softmax+RoPE is able to perform perform this task up to 128 key-value pairs, while stick-breaking is able to deal with sequences up to 192 key-value pairs.

Figure: Figure 4: Attention visualisation of the models trained on the MQRAR task. The figure shows the attention for each token for the 2-layer 100-dimension Transformer. Note that in the standard Softmax+RoPE setting (above), the attention head is “distracted" at the third retrieval of ‘E’, attending to the first instance of ‘E’ rather than the mroe recent one. In the stick-breaking setting (below), each attention head attends to the prior assignment of the variable.
Refer to caption: extracted/5947554/figures/softmax_attention.png

For a more qualitative analysis, we trained another set of 2-layer Transformers of 100 dimensions on 16 key-value pairs, and visualised the patterns of the attention head.
In Figure 4, we visuallised the above given example.
Note here that the retrieval of the third ‘E’ is distracted by the earlier assignment of 3 to ‘E’, while stick-breaking attention correctly retrieves the later assignment of 2.
This may be due to the limitations of RoPE with fewer layers and fewer head dimensions (here we use 32).

### 5.2 350M Model Length Extrapolation

Figure: (a) Position bias and embeddings
Refer to caption: extracted/5947554/figures/length_generalisation.png

We test the ability of stick-breaking for length generalisation, where we train on a fixed context length ($L=1024$) and test it on longer context lengths.
We started with the LLaMa 2 (Touvron et al., ) architecture, and modified the attention module to use the various baselines we compare against:
ALiBi (Press et al., ), FIRE (Li et al., ), NoPE (Kazemnejad et al., ) and the default Llama position embedding RoPE (Su et al., ).
We trained on the first 15B tokens of SlimPajama (Soboleva et al., ), and evaluate it on the Wikitext benchmark in the LM evaluation harness (Gao et al., ) , with context lengths of 2048 to 64K.
As control, we also trained a model with a context of $L=8192$, and as expected, the performance on longer sequences was better when RoPE scaling is used (See Figure 5(b)).

Intuitively, we should expect a model that generalises well on longer sequences to have better likelihood as the context length is increased — longer contexts mean more information for predicting the next word.
However, most methods do not generalise well to longer contexts (See Figure 5(a)).

Contrary to the results in Kazemnejad et al. (), NoPE loss increases as context lengths are extended.
We also find that RoPE embeddings alone do not generalise, despite being a relative position encoding
Using RoPE scaling with the scaling factor $f=1.0$ does alleviate the issue, but still results in an increase in the loss.
Surprisingly, while ALiBi is a fixed linear bias that increases with relative distance, it performs better than FIRE, which learns a function of the bias for a given relative distance.
For position embeddings, our experiments suggest that RoPE with scaling works best for length extrapolation.
ALiBi is an incremental bias for the logits, effectively down-weighting positions further away, eventually approaching 0.
This can be viewed as a ‘soft’ windowed attention, and given the relatively good performance, we also trained 3 models with windowed attention of $W\in\{512,1024,2048\}$.
The results suggest that windowed attention helps with preventing the loss from spiking when the context length is extended.
As expected, $W=512$ performs the worst.
However, $W=2048$ increases slightly as the context length is increased, while $W=1024$ decreases till $L=2^{13}$ and stays constant.
The $W=1024$ model is trained on context lengths of $L=2048$, which would allow the model to learn to deal with context lengths longer than the window size, while $W=2048$ is trained similar to the standard non-window attention model.
Figure 5(c) shows the generalisation curves.
Note that the $y$-axis in the plot is on a smaller scale than that of Figure 5(a), indicating that the sliding window method is a relatively good method for length extrapolation as well.
In all cases, stick-breaking negative log-likelihood still decreases as the context length increases, outperforming the other methods.

### 5.3 Model Pretraining

**Table 2: Results on the various NLP benchmarks for the 1B and 3B pretrained model. ‘Softmax’ benchmark is the standard Softmax + RoPE setting.**
| Task | ARC-c | ARC-e | Hella. | OBQA | PIQA | RACE | SciQ | Wino. | Avg. | Wiki. |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  | Accuracy (normalised) | Accuracy | Ppl. |  |  |  |  |  |  |  |
| 1B Parameter Models |  |  |  |  |  |  |  |  |  |  |
| Softmax | 35.8 | 65.6 | 64.8 | 38.8 | 75.0 | 36.5 | 90.5 | 63.4 | 58.8 | 13.8 |
| Stick-breaking | 37.7 | 67.6 | 65.4 | 36.6 | 76.0 | 37.4 | 91.9 | 63.1 | 59.5 | 13.4 |
| 3B Parameter Models |  |  |  |  |  |  |  |  |  |  |
| Softmax | 42.2 | 73.1 | 73.2 | 40.8 | 78.8 | 37.4 | 93.5 | 67.6 | 63.3 | 11.3 |
| Stick-breaking | 44.9 | 74.3 | 74.1 | 40.4 | 79.7 | 37.8 | 93.9 | 68.0 | 64.1 | 10.8 |
| Gemma2-2B | 50.0 | 80.2 | 72.9 | 41.8 | 79.2 | 37.3 | 95.8 | 68.8 | 65.8 | 13.1 |
| Qwen1.5-4B | 39.6 | 61.5 | 71.4 | 40.0 | 77.0 | 38.2 | 90.0 | 68.1 | 60.7 | 12.5 |

**Table 3: MMLU few-shot results**
|  | MMLU |  |
| --- | --- | --- |
|  | 0-shot | 5-shot |
| 1B Parameter Model |  |  |
| Softmax | 25.7 | 25.2 |
| Stick-breaking | 28.4 | 29.3 |
| TinyLlama | 25.3 | 26.0 |
| 3B Parameter Model |  |  |
| Softmax | 46.1 | 49.1 |
| Stick-breaking | 50.8 | 52.9 |
| Gemma2-2B | 49.3 | 53.1 |
| Qwen1.5-4B | 54.2 | 55.2 |

We pretrain the 1B and 3B models in this section using a two-stage training scheme in Hu et al. () and the Power learning rate schedule (Shen et al., ).
In the first stage, there is a warmup for the learning rate to 0.01, then we apply Power decay.
Our training corpus has 1T tokens and mixes large-scale open-source datasets of medium quality with permissive licenses.
In the second stage, we exponentially decay the learning rate to zero.
The stage 2 training corpus is a mix of stage 1 data and a small amount of high-quality open-source and synthetic corpora with permissive licenses.
The training batch size is 1024 and uses padding-free sequence packing for training in Dolomite Engine (Mishra, ).
We evaluate the pretrained models on language model tasks and multiple-choice tasks from LM evaluation Harness (Gao et al., ).
The multiple-choice tasks include:
grade-school science questions (ARC; Clark et al. ),
common sense reasoning (Hellaswag; Zellers et al. ),
open book question answering (OpenBookQA; Mihaylov et al. ),
physical questions (PIQA; Bisk et al. ),
reading comprehension (RACE; Lai et al. ), and
Winograd schema task (Winogrande; Sakaguchi et al. ).
Table 2 shows the performance.

Overall, we outperform our own pretrained standard attention models that are trained on the same settings.
We perform better on average, and attain better perplexity on Wikitext.
On the 1B experiment, we find that the stick-breaking without remainder performs better, so we only pretrained a 3B parameter model on this setting.
Subsequent experiments are also run only on the non-remainder setting.
We also evaluated the models on MMLU with 0-shot and 5-shot settings.
Due to the inductive bias of stick-breaking, we believed that stick-breaking would perform better on MMLU in a few-shot setting as it would not be distracted by the few-shot examples provided in the context.

Stick-breaking performs surprisingly well even in the 0-shot setting, and improves with few-shot examples provided.
Note that this may not always be the case, as in our Softmax + RoPE model, the performance decreases with few-shot examples in context.

**Table 4: 3B Model GSM8K Results**
|  | GSM8K |  |
| --- | --- | --- |
|  | 5-shot | 8-shot, CoT |
| Softmax | 44.1 | 44.2 |
| Stick-breaking | 42.3 | 49.7 |

We have included the the Qwen1.5-4B and Gemma2-2B models for comparison, and our 3B model underperforms Gemma2-2B, a smaller model, while it outperforms Qwen1.5-4B.
This may be attributable to a variety of factors, including data mixture or training hyperparameters.
Finally, we evaluate our 3B model on the GSM8K dataset (Cobbe et al., ).
Interestingly, the 5-shot setting underperforms standard attention while CoT with 8-shot sees a 5.5% improvement.

#### 5.3.1 1B Length extrapolation

We test the 1B stick-breaking and softmax model with the RULER benchmark (Hsieh et al., ).
The benchmark consists of ‘needle-in-a-haystack’-like tasks, and is generally used for testing retrieval capabilities of long-context models that are trained specifically for long contexts.
In our setting, we use RULER to evaluate both 1B models trained on 4096 contexts.
Accordingly, the general capabilities of these models on longer contexts are much worse than purpose-trained models.

Figure: (a) Overall
Refer to caption: extracted/5947554/figures/ruler_overall.png

On average, the performance of stick-breaking dominates Softmax + RoPE with scaling (Figure 6(a)).
In the breakdown, we find that the stick-breaking model is surprisingly good at extrapolating on NIAH tasks up to 16K context lengths, while the standard model significantly drops in performance.
Our results on the variable tracking (VT) task agrees with our experiments on MQRAR.
The task involves tracking the variable assignments provided in the context, and we find that even in-distribution ($L=4096$), the standard model does not perform well at this task.

## 6 Conclusion & Future Work

We propose a formulation for using the stick-breaking process as a replacement for softmax for attention.
Stick-breaking attention allows us to do away with position embeddings, while still retaining model performance.
We detail the specifics of implementing the stick-breaking kernel in Triton for large scale training.
We then demonstrate that stick-breaking is good at length extrapolation, performing better than other position embedding and position bias methods in our 350M class models.
We also show that our pretrained stick-breaking models peform better in a controlled experiment, given the same training data and training regime.
On retrieval in the RULER benchmark, stick-breaking outperforms softmax attention.

The drawbacks in efficiency can be improved in future work by making similar optimisations that Flash Attention (Dao et al., ; Dao, ) made for speedups.
These include making full use of features in CUDA, and by cache retrieval optimisations.
We believe there is plenty of room for improvement in computation efficiency that can be made in future versions of stick-breaking.
Overall, we find stick-breaking attention to be a promising replacement for Softmax + RoPE in Transformer models.

#### Acknowledgments

We would like to thank Mayank Mishra and Gaoyuan Zhang for their help during the training of the 1B and 3B models.

## Appendix A 1B Model Ruler Results

Figure: Figure 7: RULER length extrapolation results
Refer to caption: extracted/5947554/figures/all_ruler.png

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 5
presentation: 3
questions: - The differences between many models in Table 2 are fairly small and nothing is said about the detailed validation of the results. Are these from single runs rather than averages from 3-5 runs with different random initialization? How much variance would there be here, how confident can we be that a result of 63.4 is better than 63.1 for Winogrande on Softmax vs. SB w/o remainder correction, for example?
- I took the text around lines 101-107 as suggesting that things should work better doing stick-breaking with remainder, but the actual results go the other way. It would be good to provide more understanding of why this harms rather than helping.
- For the paper, you should explain lines 300-301. This isn't a question. I figured it out, but the text of the paper should explain MQRAR better for people who haven't seen it.
soundness: 4
strengths: - The paper provides thorough and useful experimental results on the performance of stick-breaking attention, providing good exploration of its effectiveness for artificial and natural language tasks, for length generalization, etc. The experimentation seem well thought through and well done.
- The paper is generally clear and easy to read.
- The paper is very honest about what it contributes and what it uses from prior work.
- The paper provides useful and new empirical results on different forms of attention on different tasks.
- The paper examines building an efficient, numerically stable Triton implementation of stick-breaking attention.
- It's good to include comparisons to Gemma2-2B and Qwen1.5-4B so that people can easily see that the results are decent, even though the papers own results are the apples-to-apples comparisons.
summary: This paper does a thorough evaluation of stick-breaking attention (also known as geometric attention) for synthetic test tasks and natural language tasks, showing its effectiveness at capturing a preference for locality, as is natural and correct for natural language tasks. The paper examines a fast, numerically stable implementation of stick-breaking attention in Triton, which enables larger scale experiments.
weaknesses: - The paper lacks originality in machine learning ideas. Stick-breaking attention has been previously explored by Yikang Shen (in multiple papers) and especially by Csordas et al. (2021), the latter under the name "Geometric attention". "Stick-breaking attention" is a better name for the model used, but the model is exactly the same as in these prior works, limiting the originality of this paper. The value is mainly in the more extensive experimentation, including showing performance on larger scale, standard natural language benchmarks.
- This paper lacks somewhat in significance because of this. It does have some significance, since it is really good to see that these ideas really do give gains on standard NL tasks like ARC, Hellaswag or RACE, but the basic correctness of the idea had already been established.
- The differences between many models in Table 2 are fairly small and nothing is said about the detailed validation of the results. Are these from single runs rather than averages from 3-5 runs with different random initialization? How much variance would there be here, how confident can we be that a result of 63.4 is better than 63.1 for Winogrande on Softmax vs. SB w/o remainder correction, for example?
- How to produce an efficient, numerically stable Triton kernel basically follows the methods of FlashAttention and standard good practice (using log(1 + exp(x)), etc.)

---

confidence: 5
contribution: 3
initial_rating: 8
presentation: 3
questions: - What is $\sigma$ function? It is never defined. is it sigmoid ?
soundness: 3
strengths: - The paper presents a novel addition to the zoo of "attention alternatives" by leveraging the stick breaking process, which performs both "attention" and positional embeddings intrinsically. The mechanism has a recency bias, meaning a token can prefer to allocate all its "energy" to few recent tokens, but it can also skip over and only attend to far-away tokens.
- The paper also include details implementation in Triton for flash-attention style efficiency and speed-up optimization, which is hugely appreciated, especially when nowadays efficiency and scalability is valued more for massive training of LLMs.
- The paper conducted diverse range of experiments, from throughput (only 20% slower than flash attention), perplexity and language modeling tasks (MMLU, ARC-c, hellaswag...), which all shows promising results.
- The main driver of this work is to solve the length generalization challenge of LLMs, which show good results.
summary: The paper introduce an alternative attention that includes a form of positional embeddings, avoiding the need to add PE techniques such as RoPE. The method is based on the stick-breaking process, which means for each token in the context (keys), they assign a break point that represents the remaining stick to the current token. This means that if 2 tokens have equal logits, the one closer to the current token will receive more stick value, representing the positional order.
Conducting this process through out the entire context results in a sequence of attention weights in lieu of traditional attention weights.
The paper suggests this process incorporate recency bias in nature without PE.
Experiments done show that the new method is better at length generalization in perplexity compared to attention+RoPE.
weaknesses: - Method can be explained more clearly with diagrams, formulation should be defined more thoroughly.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: What is the exact relationship of stick-breaking attention to geometric attention (Csordas et al 2021) and the stick-breaking attention of Shen et al (2023)?

Eq (1):
- I'd suggest not using \cdot, as it might be misinterpreted as an inner product in this context.
- The first summation only goes up to i-1, so a position cannot attend to itself, which is different from usual future masking. I didn't see this decision discussed; what's the reason for it?

Line 94: typo, should be $z_{i,j} = z_{i',j}$? 

Eq (4): I don't know if it matters, but you could use log1p(exp(z)) instead of log(1+exp(z)).

It may be interesting to node that while softmax with a temperature factor (α = softmax (z/T)) as T -> 0 approaches average hard attention, which is used in many theoretical studies of transformers (e.g., https://arxiv.org/abs/1901.03429, https://arxiv.org/abs/2106.16213), stick-breaking attention (β = σ(z/T)) as T -> 0 approaches strictly future-masked rightmost hard attention, which is the kind of attention studied by https://arxiv.org/abs/2310.13897.
soundness: 3
strengths: This softmax alternative is simple and induces a bias towards attending to recent positions in a very natural way.

The experimental results all look strong.
summary: This paper is about stick-breaking or geometric attention, an alternative to softmax that has a built-in bias towards more recent tokens. Given a query position j, each key/value position i < j computes a probability of "yes" or "no", and the attention weight on i is the probability that position j is "yes" but all intervening positions are "no".

Stick-breaking/geometric attention was introduced in previous work. It makes position embeddings unnecessary and can be computed in O(log n) parallel time. This paper presents an improved implementation, and shows that stick-breaking/geometric attention improves performance on the multi-query associative recall task and various benchmarks.
weaknesses: As far as I can tell, stick-breaking attention is exactly the same as geometric attention (Csordas et al 2021), and stick-breaking was previously introduced by Shen et al (2023). Both papers are cited in the introduction, and the introduction concludes with an accurate list of the novel contributions of the paper. However, 
- The paper's short title "Stick-Breaking Attention" may give the impression that this is the first paper about stick-breaking attention.
- The abstract does not mention previous work; on the contrary, it says "We propose an alternative attention mechanism."
- The introduction, probably inadvertently, could be mis-read as saying that geometric attention only has one parameter ("Geometric attention, named after the Geometric distribution, which only has one parameter").

Eq. (2): Putting the remainder of the attention onto position j itself does not seem like the right choice. Probability $(1-\beta_{i,j})$ is the probability of pushing the attention to the left of position i, so $\prod_i (1-\beta_{i,j})$ is the probability of pushing the attention all the way to the left. So it's not surprising that this turned out not to work well. Letting the attention weights sum to less than one (or equivalently, putting the remainder of the attention onto the zero vector) seems like the most sensible thing to do.

The Flash Attention-like implementation of stick-breaking attention is 20% slower than Flash Attention.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: 1. The keys and queries do not have positional encodings, but the values still do, right? Does the lack of PEs on queries and keys reduce the model's expressivity (i.e., are there certain functions that it can no longer implement because of the loss of PEs)? 474: Stick breaking attention doesn't completely get rid of PEs, right?
1. Although I intuitively understand the motivation for using stick-breaking, can you make a more rigorous case as to *why* stick-breaking has a recency bias? Is it not true that both softmax and stick-breaking attention can implement arbitrary attention patterns?
1. Related to the above, did you verify that the model actually attends to more recent tokens? Does this happen in wikitext?
1. 096: I'm not sure what this discussion is trying to say. Can you explain this more?
1. 094: I think $z_{i,j} = z_{i,j}$ is a typo.
1. Instead of using Eq 5, which is an inexact approximation, why not use the identity $\log(1 + \exp x) = c + \log(\exp(-c) + \exp(x - c))$, where $c = \max(0, x)$? This would solve the overflow problem while being an exact solution.
1. 208: Doesn't this make your method much less parallelizable than standard attention? I think you can actually get the same parallel time complexity using a variant of parallel prefix sum -- have you considered using that?
1. 304: How much of each sequence is devoted to the initial set of pairs, and repeated pairs?
1. Table 2, Figure 6: Why do you suppose stick-breaking attention helps on these tasks? It even gets slightly lower perplexity on wikitext, which is not a task that is specifically advantageous for recency-biased models. Can you spend more time discussing what kind of capability each natural language benchmark represents? Why do we expect recency bias to help with them? Do the gains come from recency bias, or is it more about length generalization thanks to the use of relative PEs?
1. Why does stick-breaking attention do better at length generalization on RULER if the retrieved data is not necessarily recent? I don't see why stick-breaking would be advantageous here.
1. Why does stick-breaking attention eventually fail on RULER at longer lengths? What is the failure mode?
soundness: 3
strengths: 1. The experiments include a variety of natural language benchmarks.
1. The authors include a thorough comparison to similar prior work.
1. The results as presented show that stick-breaking attention outperforms standard attention on a variety of benchmarks.
1. Their new attention mechanism is reasonably fast, and further optimizations are possible.
summary: This paper presents a new type of attention mechanism called "stick-breaking attention". It is meant to have a bias for attending to recent positions. Instead of using dot-products between keys and queries as logits and renormalizing them using a softmax to form the attention weights, the dot-products are each passed through the logistic function and then used as the probabilities in a stick-breaking process. In other words, the model first decides how much to attend to the current token, *then* decides how much of the remainder to allocate to attending to the previous token, and so on. It is a generalization of geometric attention proposed in prior work, where the probabilities at each timestep can be different. The authors discuss details for implementing it efficiently. They test it against standard scaled dot-product attention on a simple synthetic task that advantages recency bias, and on a variety of natural language benchmarks. Stick-breaking attention gets better scores on most tasks.
weaknesses: 1. ~~Their implementation relies on a very rough approximation of the exponential function to avoid overflow (Eq 5), so their method is implementing a function that is quite different from what is proposed. I think this can be avoided (see Questions), and I am curious to see if using an exact solution affects the results.~~
1. To improve the readability of the paper, a more intuitive explanation of stick-breaking would be useful, for those who are not familiar with the term. For starters, why is it called stick-breaking?
1. Although the results are encouraging in Section 5.3, it is not clear to me that there was much hyperparameter tuning on the baselines. I would like to see more discussion of this.
1. I would like to see more discussion of *why* recency bias helps on the natural language benchmarks tested (see Questions).

Meta-review: The paper explores a new type of attention mechanism for synthetic test tasks and natural language tasks. The proposed attention inherently incorporates positional embeddings, eliminating the need for additional positional encoding techniques like RoPE. The method assigns a breakpoint to each token, prioritizing tokens closer to the current one, thereby embedding a natural recency bias without explicit positional encodings. An efficient, numerically stable implementation in Triton enables large-scale experiments. 

The authors follow the reviewers suggestion to make modifications to the abstract and title (Scaling Stick-Breaking Attention: An Efficient Implementation and In-depth Study). AC appreciates the authors' effort in the rebuttal to dispel the reviewer's doubts.

Decision: Accept (Poster)