MAMBA STATE-SPACE MODELS ARE LYAPUNOV-STABLE LEARNERS

## Abstract

Abstract Mamba [ 21 , 11 ] state-space models (SSMs) were recently shown to outperform state-of-the-art (SOTA) Transformer large language models (LLMs) across various tasks. Despite subsequent widespread adaptation, little work has focused on Mamba LLMs’ amenability for fine-tuning frameworks ubiquitously used for Transformer-based LLMs, e.g., mixed-precision fine-tuning (MPFT) and parameter-efficient fine-tuning (PEFT). For the former, it currently remains an open question whether Mamba’s recurrent dynamics are robust to small input changes, such as those encountered during MPFT. Using dynamical systems theory (in particular, Lyapunov exponents), we answer this question in the affirmative. We empirically validate this result through several experiments, showing that Mamba SSMs are significantly more stable to changes introduced by mixed-precision than comparable Transformers, even when both MPFT and PEFT are combined. For PEFT, we show how targeting specific memory buffers in Mamba’s customized CUDA kernels for low-rank adaptation regularizes SSM parameters, thus providing both parameter efficient learning and computational savings.
Finally, with both MPFT and PEFT enabled, we explore the impact of instruction tuning Mamba SSMs for in-context learning (ICL) on natural language tasks . While pretrained Mamba and Mamba-2 models only achieve 38% and 82% (respectively) of the ICL improvements of comparable Transformer-based LLMs, we show that instruction tuning allows Mamba models to narrow this gap to 81% and Mamba-2 models to skyrocket over this gap to 132%.

## 1 Introduction

Innovating on previous state-space models (SSMs) [, ], Mamba [, ] has been recently proposed as an accurate, sub-quadratic alternative to Transformer large language models (LLMs). Upon their introduction in [], Mamba SSMs were shown to greatly outperform comparable attention-based LLMs [] across a large number of standard natural language benchmarks. Subsequently, pretrained Mamba models have been widely adapted across a large number of data modalities [, , , ], tasks [, ], and architectures  [, , ]. Despite such widespread adaptation and subsequent research threads [, , ], little work has been done to understand the amenability of Mamba SSMs for widely used fine-tuning frameworks, such as mixed-precision fine-tuning (MPFT) [] and parameter-efficient fine-tuning (PEFT) [, ].

MPFT and PEFT are arguably two of the most widely utilized techniques for LLM alignment [] and customization [], and are typically combined to drastically decrease hardware demands needed to fine-tune modern LLMs []. However, direct application of MPFT for Mamba SSMs is made difficult due to potential sensitivities of Mamba’s state-space dynamics, a common concern for recurrent-based deep models []. To combat this, both [] and [] suggest full precision (FP32) may be required to perform stable training for Mamba models. Thus, it is currently an open question whether Mamba’s recurrent dynamics are stable in the presence of small input deviations, such as those introduced in MPFT.

To answer this question, we leverage theory from dynamical systems. Deriving and bounding the Lyapunov exponents for both Mamba and Mamba-2 models, we show that small input changes within the SSM layer of either model do not lead to exponentially deviating outputs. Empirically, we validate this theoretical result; compared to full-precision, deviations due to mixed-precision for Mamba inference are on par with those demonstrated by Transformer LLMs, while deviations due to MPFT are significantly more stable than those of comparable Transformers (Section 5). Furthermore, this trend continues when MPFT and PEFT are combined, where Mamba SSMs again produce significantly smaller deviations compared to comparable Transformer LLMs.

For PEFT, we show that by targeting the large memory buffers exploited by Mamba’s highly customized CUDA kernels, LoRA may be used for extremely efficient fine-tuning, while simultaneously regularizing the majority of Mamba’s SSM parameters via weight tying. We show that this leads to extremely efficient PEFT, resulting in up to 2.15 times faster training and 65.5% reduced memory compared to the largest evaluated Mamba model without MPFT or PEFT. Furthermore, this allows even the largest (2.8 billion parameter) Mamba LLMs to be fine-tuned on a single GPU with as little as 24GB of onboard memory.

Finally, using both MPFT and PEFT, we complement existing studies [, ] by exploring the ICL capabilities of instruction-tuned Mamba and Mamba-2 models on *natural language tasks*. In particular, the ICL capabilities of both pretrained Mamba and Mamba-2 models lag behind those of comparable Transformer models from the Pythia suite []; averaged across five standard natural language benchmarks and foundation model sizes, Mamba and Mamba-2 models only achieve 38% and 82%, respectively, of the performance improvements (relative to zero-shot) of Pythia models. However, after instruction-tuning, Mamba models are able to achieve as much as 81.5% of the average few-shot learning improvement (relative to zero-shot) of comparable Transformers, while Mamba-2 models push this to 132% of the ICL improvements achieved by Pythia models. We note that, similar to Transformer foundation models [], (post) instruction tuning ICL appears as an emergent abilities for Mamba and Mamba-2 SSMs, manifesting for models of size 370 million parameters and greater, while failing to manifest for Mamba and Mamba-2 models of fewer parameter counts.

We note that herein, when describing a particular foundation model or result, we use the term “Mamba model” to refer to one of the original models released in [] and “Mamba-2 model” to refer to models released in []. While there are subtle architectural differences between these two SSMs, they share important similarities which allow our theoretical results to extend to both sets of models. In particular, Mamba and Mamba-2 models share the same state-space equations, support for SSM matrices, and design scheme of storing the majority of SSM parameters in a large memory buffer. Thus, we synonymously use the term MambaBlock to refer to the SSM layer of both Mamba and Mamba-2 models.

## 2 Background

Mixed-precision and parameter-efficient fine-tuning. In the current era of extremely large foundation models, both MPFT and PEFT have become ubiquitous tools for the rapid adaptation of Transformer-based LLMs towards specific applications. PEFT using adapters [] allows a large pretrained model to be efficiently adapted for a particular downstream task by freezing the full model and training only a small number of extra parameters. Arguably the most widely used such PEFT method is LoRA [], which injects trainable low-rank matrices into Transformer layers to approximate weight updates.

To further decrease the computational demands necessary for LLM fine-tuning and inference, MPFT via mixed-precision (i.e., FP16 or BF16) [, ] and quantized low-precision [] have proven effective strategies to reduce GPU memory and runtime requirements without deleterious effects on downstream performance [, ]. Additionally, mixed-precision approaches have paved the way for hardware-aware optimizations within the self-attention module [], greatly mitigating the quadratic complexity of Transformer LLMs. Together, PEFT and MPFT have created a rich ecosystem with which varying combinations of these approaches may be used to meet the computational constraints of a given training system. We note that post-fine-tuning quantization approaches [] may be further used to decrease Transformer LLM computational demands, but such approaches are not considered in this work.

State-space Models. *Structured state-space sequence* (S4) models [, ] are SSMs which leverage linear time-invariant (LTI) systems to combine the computational advantages of Transformers–i.e., highly parallelizable training–and recurrent neural networks (RNNs)–i.e., subquadratic autoregressive inference using recurrency. Within the S4 layer, an input signal is discretized and LTI parameters representing the input’s latent dynamics are learned. Owing to the S4 block’s latent dynamics being LTI, the S4 block’s output may be thus compactly represented as a single convolution between the input and an *SSM convolution kernel* (a matrix whose entries are products of LTI learnable parameters resulting from unrolling the state-space equations). However, despite hardware efficiency and long-dependency-modeling improvements, LTI-based S4 models remained inferior to Transformers of comparable parameter-sizes for natural language tasks, even when augmenting S4 layers with attention-layers for hybrid architectures [].

Innovating on these previous S4 approaches, Mamba utilizes time-*varying* parameters to model latent dynamics, thus broadening the ability to capture nuanced changes evolving in discrete-time. Without LTI dynamics, however, the input-output representation via the SSM convolution kernel is no longer applicable, thus voiding previous hardware-aware S4 optimizations []. To enable hardware efficiency with time-varying SSM parameters, [] thus introduced extensively customized CUDA kernels which implement highly parallelized prefix sums to compute recurrent states. Subsequently, [] considered the unrolled state-space equations and leveraged tensor contractions (i.e., einsum notation []) to efficiently calculate Mamba variables. The resulting Mamba-2 foundation models contained significantly larger latent-variable dimensions than the Mamba models of [], while maintaining efficiency on modern GPU accelerators.

In-context learning. ICL provides an adaptable alternative to fine-tuning. Rather than fine-tune the LLM directly, ICL augments a prompt with $n$ relevant examples (called *shots*) preceding the query of interest. Given sufficiently large models and pretraining data [, ], Transformer LLMs have proven adept at learning new concepts on the fly provided such few-shot prompting.
However, it is worth noting that ICL inference time increases dramatically as the number of shots grows (due to self-attention’s quadratic complexity) and PEFT (when possible) is known to produce more accurate downstream learning results [, ].

## 3 Mamba state-space models

For latent-variable dimension $d$ and maximum input sequence length $T$, the MambaBlock defines state-space parameters $\mathbf{A},\mathbf{B}_{t},\mathbf{C}_{t},\bm{\Delta}_{t}\in\mathbb{R}{}^{d
\times d}$ for $t\in\{1,\dots,T\}$. The matrix $\bm{\Delta}_{t}$ controls the discrete step-size.
Given an input sequence $\mathbf{u}_{1},\dots,\mathbf{u}_{T}\in\mathbb{R}{}^{d}$, the following linear mapping through latent states $\bm{x}_{1},\dots,\bm{x}_{T}\in\mathbb{R}{}^{d}$ is used to produce the output $\mathbf{y}_{1},\dots,\mathbf{y}_{T}\in\mathbb{R}{}^{d}$:

$$ $\displaystyle\bm{x}_{t}$ $\displaystyle=\bar{\mathbf{A}}_{t}\bm{x}_{t-1}+\bar{\mathbf{B}}_{t}\mathbf{u}_ {t}$ (1) $\displaystyle\mathbf{y}_{t}$ $\displaystyle=\bar{\mathbf{C}}_{t}\bm{x}_{t},$ (2) $$

where $\bar{\bm{\Delta}}_{t}=\texttt{softplus}(\texttt{Linear}(\bm{\Delta}_{t}))\in
\mathbb{R}{}^{d\times d}$, $\bar{\mathbf{A}}_{t}=\exp{(\bar{\bm{\Delta}}_{t}\mathbf{A})}$ and $\bar{\mathbf{B}}_{t}=\mathbf{A}^{-1}(\bar{\mathbf{A}}-\mathbf{I})\mathbf{B}_{t}$. In practice, $\mathbf{A},\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$ are diagonal matrices.

### 3.1 Stable dynamics in the MambaBlock

The Mamba foundation models were pretrained in full FP32 precision. Consequently, official Mamba implementations have cautioned against fine-tuning or training in reduced precision [, ], with potential sensitivities of MambaBlock recurrent dynamics remaining an open question. We answer the latter using theory from dynamical systems. For Mamba’s discrete dynamic system in Equations 1 and  2, define

$$ $\displaystyle\bm{x}_{t}$ $\displaystyle=F_{\theta}(\bm{x}_{t-1},\mathbf{u}_{t}),$ (3) $$

where $\theta$ denotes the time-varying parameters described in Section 3. For input sequence $\mathbf{u}_{1},\dots,\mathbf{u}_{T}$ and initial latent state vector $\bm{x}_{0}$, we thus write

$$ $\displaystyle\bm{x}_{T}$ $\displaystyle=F_{\theta}(F_{\theta}(\dots F_{\theta}(\bm{x}_{0},\mathbf{u}_{1} )))\coloneq F_{\theta}^{T-1}(\bm{x}_{0},\mathbf{u}_{1}).$ $$

The rate of divergence between two scalar $\varepsilon$-close inputs to a discrete dynamical system is bounded by the system’s maximal Lyapunov exponent $\lambda_{\mathtt{max}}{}$ []. Given $\lambda_{\mathtt{max}}{}$ and two initial values $(\bm{x}_{0},\mathbf{u}_{1})$ and $(\bm{x}_{0}+\varepsilon,\mathbf{u}_{1}+\varepsilon)$, the maximum deviation between these points grows as [, ]:

$$ $\displaystyle\max|F_{\theta}^{N}(\bm{x}_{0},\mathbf{u}_{1})-F_{\theta}^{N}(\bm {x}_{0}+\varepsilon,\mathbf{u}_{1}+\varepsilon)|\in\mathcal{O}(\varepsilon\exp {(N\lambda_{\mathtt{max}}{})}).$ $$

Thus, when $\lambda_{\texttt{max}}>0$, nearby trajectories exponentially separate and, when $\lambda_{\texttt{max}}\leq 0$, nearby trajectories ultimately converge to the same fixed point or periodic cycles.

The maximal Lyapunov exponent is defined as

$$ $\displaystyle\lambda_{\mathtt{max}}{}$ $\displaystyle\coloneq\lim_{T\to\infty}\frac{1}{T}\log\left\lVert\prod_{t=0}^{T }\frac{\partial\bm{x}_{t}}{\partial\bm{x}_{t-1}}\right\rVert_{2},$ $$

where $\left\lVert\right\rVert_{2}$ denotes the spectral norm for matrices. For an arbitrary MambaBlock, we prove the following:

###### Theorem 1 .

Let $(\bm{x}_{t-1},\mathbf{u}_{t})$ be the latent state and input at an arbitrary time $t\in\{1,\dots,T\}$ within a MambaBlock. Then small changes $(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)$ produce deviations which are exponentially non-increasing over discrete-time. That is, $\max|F_{\theta}^{N}(\bm{x}_{t-1},\mathbf{u}_{t})-F_{\theta}^{N}(\bm{x}_{t-1}+
\varepsilon,\mathbf{u}_{t}+\varepsilon)|\in\mathcal{O}(\varepsilon\exp{(N\zeta
)})$, for some scalar $\zeta\leq 0$.

The proof of Theorem 1 is available in Appendix B, where the maximal Lyapunov exponent for an arbitrary MambaBlock is first proven to be non-positive. The main result subsequently follows.

Thus, the latent states of Mamba and Mamba-2 models are stable under small input changes. However, variables $\mathbf{y}_{1},\dots,\mathbf{y}_{T}$ are the primary outputs for such models, particularly for LLM applications. We next show that, given Theorem 1, Mamba and Mamba-2 output variables are also stable.

###### Theorem 2 .

Assume $(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)$ produce deviations which are exponentially non-increasing over discrete-time. Then small changes to the output $\mathbf{y}_{t}$ are also exponentially non-increasing over discrete time.

The proof of Theorem 2 is available in Appendix C. Thus, by Theorems 1 and  2, the latent and output states of both Mamba and Mamba-2 models are stable to changes encountered during recurrency.

###### Theorem 1 .

###### Theorem 2 .

#### 3.1.1 Consequences for automatic mixed-precision

During a forward pass, automatic mixed-precision (AMP) saves time and memory by computing forward activations in half-precision (FP16 or BF16). During a backward pass, AMP computes gradients in half-precision and up-casts to full-precision prior to updating. In contrast to full-precision fine-tuning, MPFT within the MambaBlock thus results in small differences to the inputs $\mathbf{u}_{1},\dots,\mathbf{u}_{T}$ (which are passed through a Swish), $\bar{\bm{\Delta}}_{t}$ (which is passed through a softplus), and the gradients calculated during training.

For a discrete dynamical system with $\lambda_{\texttt{max}}>0$, changes due to AMP compound after repeated expansion of the recurrent state, thus leading to exponential deviations between quantities calculated using mixed- versus full-precision. We note that Transformers are not recurrent, and thus not susceptible to such issues. Yet, just as differences introduced by quantization/mixed-precision produce output differences in Transformer results, differences are expected in Mamba results using different precision strategies. However, by Theorem 1, such differences do not exponentially compound over discrete-time within the MambaBlock.

### 3.2 Hardware-aware optimizations and PEFT

As matrices $\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$ are time-varying, S4 optimizations via the SSM convolution kernel [] are no longer applicable. However, by diagonality, each dimension may be computed in parallel. Furthermore, the recurrence along every dimension is a prefix sum (also called a *scan*), which is highly parallelizable []. [] thus capitalizes on this through extensively customized CUDA kernels wherein the majority of temporal variables are carefully laid out in a large buffer of GPU memory and manipulated. Instantiated as a PyTorch linear layer’s weight matrix, this memory buffer $\mathbf{W}\in\mathbb{R}{}^{T\times 3d}$ is used to store and access the diagonal elements of $\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$ for all $t\in\{1,\dots,T\}$, such that

$$ $\displaystyle\mathbf{W}[t-1,:d]=\texttt{diag}(\bm{\Delta}_{t}),\mathbf{W}[t-1, d:2d]=\texttt{diag}(\mathbf{B}_{t}),\mathbf{W}[t-1,2d:3d]=\texttt{diag}( \mathbf{C}_{t}),$ (4) $$

where $\mathbf{W}[0,:d]=\texttt{diag}(\bm{\Delta}_{1}),\mathbf{W}[n-1,d:2d]=\texttt{
diag}(\mathbf{B}_{T})$, and so on. The customized Mamba prefix scan kernel heavily relies on this memory layout to optimize the access pattern of $\mathbf{W}$ in Equations 1 and 2.

Similarly, Mamba-2 stores diagonal elements of $\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$ in a large memory buffer $\mathbf{W}$. However, rather than utilizing the underlying recurrence to directly compute the hidden state and output at each time-step, [] consider the matrix resulting from unrolling Equation 2 across all $t$. Mamba-2 models thus leverage the structure of the ensuing semiseparable matrix to calculate $\bm{x}_{1},\dots,\bm{x}_{T}$ and $\mathbf{y}_{1},\dots,\mathbf{y}_{T}$ using tensor contractions, which are highly optimized on modern hardware accelerators.

When fine-tuning using LoRA, low-rank matrices are used to adapt the frozen weight matrices of targeted linear layers. The importance of $\mathbf{W}$ for both Mamba and Mamba-2 models makes it a primary candidate for LoRA adaptation. In such cases, selecting $\mathbf{W}$ for LoRA adaptation results in the following:

###### Theorem 3 .

Consider the weight matrix $\mathbf{W}$ of a MambaBlock from Equation 4. Targeting $\mathbf{W}$ for LoRA during fine-tuning ties adaptation weights across $\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$.

The proof of Theorem 3 is available in Appendix A. The specific affects of both targeting $\mathbf{W}$ for fine-tuning and Theorem 3’s impact on generalization are ablated in Appendix F.

###### Theorem 3 .

## 4 Related Work

Recent work has sought to understand how to efficiently increase Mamba’s hidden-state dimension by restructuring SSM operations using tensor contractions [], leading to Mamba-2 models. A separate line of work has sought to understand the in-context learning (ICL) capabilities of Mamba LLMs when trained from scratch for specific tasks [, ]. Another line of recent work has sought to understand how hybrid Mamba-Transformer models may be directly distilled from Transformer models []. However, to the best of our knowledge, no existing works have either theoretically explored the effects small input changes (e.g., due to mixed-precision) have on Mamba’s recurrent dynamics, empirically explored such effects downstream impact on fine-tuning and inference, or sought to understand the effects of LoRA adaptation on modules within the MambaBlock.

Lyapunov exponents have previously been considered for classic RNN structures (e.g., vanilla RNNs, LSTMs, GRUs, PLRNNs, etc.) [, ], to determine when such models exhibit chaotic dynamics and the impact on the exploding/vanishing gradient phenomena(^*^**We note that this continues a long line of research exploring RNNs sensitivity to initial conditions and their subsequent ability to produce chaotic output [, , , ], although previous work did not leverage Lyapunov exponents.).
For more recent S4 neural models, [] used Hurwitz matrices to characterize the numerical stability of linear time-invariant (LTI) S4 models. However, such analysis is not applicable to time-varying models, such as Mamba, nor does it characterize the effects of sensitive dependence on initial conditions (e.g., divergence of two $\varepsilon$ close inputs). To the best of our knowledge, no previous works have used Lyapunov exponents to explore the effects of mixed-precision on recurrent neural models or Mamba architectures.

As previously noted, recent works [, ] have studied Mamba’s ability to perform ICL by training Mamba models for specific tasks. Such tasks include logistic regression, decision trees, and learning other simple function classes, following the work of []. We emphasize that, in this set up, relatively small Mamba models–33 million and 90 million parameters for [] and [], respectively–are trained from scratch for every evaluated task. Indeed, [] notes that subsequent work is necessary to understand Mamba’s ICL capabilities for language modeling using standard natural language benchmarks, as well as for larger model sizes. Thus, our study of both the pretrained and instruction tuned ICL capabilities of Mamba/Mamba-2 LLMs for natural language tasks are complimentary to previous works.

## 5 Experiments

To demonstrate the implications of Theorem 2, we explore the performance difference between running inference with full-precision pretrained weights and using mixed-precision (FP16 and BF16) weights. Model performance is measured as percent accuracy using the MMLU dataset []. The difference in model performance is reported as the mean *divergence* (i.e., absolute difference) between the original full-precision and respective mixed-precision model, averaged over {0, 1, 3, 5}-shot percent accuracy. Thus, a divergence greater than one denotes an average difference greater than one entire percentage of accuracy.

Mamba pretrained checkpoints are compared to pretrained Transformer models of similar parameter counts and no more than $\sim$300B total pretraining tokens (Pythia [], OLMo [] 336B-token checkpoint, and Phi 1.5 []). We note that Pythia and Mamba models were both pretrained using the same corpus [], allowing the fairest comparison between SSMs and Transformers. To limit extraneous numerical effects within experiments (e.g., due to parameter aggregation across multiple GPUs), all models were run using a single GPU (Nvidia A10G, 24 GB total memory). All models were evaluated using the LM evaluation harness from Eleuther AI []. Further experimental details are available in Appendix D. The results are available in Table 1.

**Table 1: Mean full-precision (FP32) divergence in MMLU performance for mixed-precision inference. Divergence is averaged over {0, 1, 3, 5}-shot performance. Pretrained checkpoints are used for Mamba (M), Pythia (P), OLMo [], and Phi-1.5 [] (Phi) models.**
| Model | M | P | M | P | M | P | OLMo | M | P | Phi | M | P |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Size | 130M | 160M | 370M | 410M | 790M | 1B | 1.4B | 1.5B | 2.8B |  |  |  |
| FP16 $\mu$ | 0.03 | 0.35 | 0.05 | 0.06 | 0.21 | 0.05 | 0.04 | 0.04 | 0.07 | 0.03 | 0.15 | 0.12 |
| BF16 $\mu$ | 0.05 | 1.45 | 0.20 | 0.20 | 0.66 | 0.16 | 0.13 | 0.31 | 0.13 | 1.05 | 1.17 | 0.11 |

From Table 1, inferencing in Pythia using FP16 and BF16 result in an average 0.13 and 0.41 full-precision divergence, respectively. Mamba displays similar averages in comparison: inferencing in Mamba using FP16 and BF16 result in an average 0.10 and 0.48 divergence, respectively. Interestingly, both SSM and Transformer architectures exhibit *large divergence spikes*–i.e., mean divergence greater than a percentage point–when using BF16, which occurs once for Mamba and Phi 1.5 models and twice for Pythia models. Due to space constraints, Mamba-2 results for the same experiment are included in Appendix Table 3. We note that, for comparable model sizes and mixed-precision, Mamba-2 models follow identical divergence trends as respective Mamba models.

In the following, we show that the observed large divergence spikes may be mitigated for Mamba SSMs by combining mixed-precision with parameter-efficient adapters during fine-tuning.

### 5.1 Mamba SSMs are stable learners

We next explore the implications of Theorem 1 on fine-tuning, wherein mixed-precision is especially critical; MPFT combined with PEFT adapters have been shown to drastically reduce Transformer fine-tuning times []. We are thus interested in the divergence between Mamba models fully fine-tuned (i.e., no adapters, all model weights are trained) in full-precision and models fine-tuned using mixed-precision and/or PEFT adapters. We focus on utilizing LoRA [], which is arguably the most widely used PEFT framework for LLMs.

Figure: Figure 1: Mean full-precision (FP32) divergence in MMLU performance for Mamba, Pythia, and OpenELM models. Models are fine-tuned over the Alpaca dataset [] using different combinations of MPFT and PEFT. Full fine-tuning (i.e., no PEFT adapters) is denoted as Full.
Refer to caption: x1.png

Using the Alpaca dataset [], Mamba 160M, 410M, and 790M models are fine-tuned for three epochs with a maximum sequence length of 512. We denote the targeting of all linear layers (ALL) for LoRA as *ALL LoRA*, the targeting of a subset of linear layers (SLL) for LoRA as *SLL LoRA*, and no adapters as *Full* (i.e., full fine-tuning). Both ALL and SLL LoRA adapt the large memory buffer described in Theorem 3.

Each fine-tuning run occurred on a single A10G GPU. To further limit extraneous numerical effects, the same batch size is used for all FP32, FP16, and BF16 experiments for a given model size. While this leads to hardware underutilization (i.e., non-saturated GPU memory for mixed-precision and LoRA experiments), this is necessary to guarantee no divergence is due to differences in parameter update schedules. For comparison, two Transformer-based LLM families of similar parameter counts are fine-tuned using the same experimental setup: Pythia (sizes 160M, 410M, and 1B) and OpenELM [] (sizes 270M and 450M). The training recipe for all models was adapted from [], with the AdamW_torch optimizer and a cosine annealing schedule.
Further experimental details are available in Appendix D.

For each Mamba, Pythia, and OpenELM model, Figure 1 shows the mean divergence calculated between the respective FP32 Full and mixed-precision ALL/SLL LoRA fine-tuned models, averaged over {0, 1, 3, 5}-shot MMLU accuracy.

Across mixed-precisions and adapter settings, Mamba displays smaller divergences than both Pythia and OpenELM models. E.g., for FP16, Mamba demonstrates an average divergence of 0.1, compared to 0.14 for Pythia and 0.54 for OpenELM. Similarly, for BF16, Mamba demonstrates an average divergence of 0.18, compared to 0.28 for Pythia and 0.33 for OpenELM. Importantly, Mamba models do not exhibit large deviation spikes after fine-tuning, in contrast to both Pythia and OpenELM models.

Figure: (a) Average tokens-per-second $\uparrow$.
Refer to caption: x2.png

Hardware throughput and memory-utilization improvements. With stable dynamics and observed divergences smaller than comparable Transformers, we show that MPFT and PEFT may be used to significantly increase GPU-training throughput for Mamba SSMs. To demonstrate such improvements, we utilize the previous fine-tuning settings for the Alpaca dataset. However, we now adjust the batch size to maximize throughput per MPFT and PEFT configuration.

For each MPFT and PEFT configuration, the *average tokens-per-second* (ATPS) is calculated as the total tokens used for fine-tuning divided by total training time, and the *maximum memory-per-token* (MMPT) is calculated as the maximum GPU memory utilization incurred (over the entire fine-tuning run) divided by the total number of tokens in each mini-batch. Results are plotted in Figure 2(b).

Both throughput and memory utilization improve as the number of Mamba parameters increases in Figure 2(b). Compared to the full-precision full fine-tuning of Mamba 790M (the largest model supported by an A10G’s memory capacity), evaluated MPFT and PEFT combinations result in an average 2.15 times more training tokens-per-second while reducing per-token memory utilization by an average 62.7%. Across all model sizes, evaluated MPFT and PEFT combinations result in an average 1.74 times more training tokens-per-second while reducing per-token memory utilization by an average 47.2% compared to respective full-precision fine-tuned runs. Furthermore, while full fine-tuning is no longer possible on a single A10G for Mamba models greater than 790 million parameters, MPFT and PEFT allow training Mamba models up to 2.8 billion parameters on GPUs with as little as 24 GB onboard memory.

### 5.2 Instruction tuning impact on Mamba ICL for natural language tasks

Using both MPFT and PEFT, we next explore how instruction tuning affects Mamba and Mamba-2 ICL performance on natural language tasks.
All Mamba and Mamba-2 pretrained models are instruction fine-tuned using ALL LoRA and the OpenHermes dataset [] (which consists of 242,000 supervised samples). We use the training recipe of  [], which includes BF16 utilization.

Zero and few-shot performance is evaluated using five standard natural language benchmarks: HellaSwag [], PIQA [], Arc-E [], Arc-C [], and WinoGrande []. ICL performance is reported as the *average improvement percentage* of {1, 3, 5}-*shot* versus 0-*shot* (AIPSS). For comparison, Pythia pretrained models are instruction fine-tuned using the same training recipe and ALL LoRA (i.e., all Pythia linear layers are adapted).

Figure: (a) Mamba Pretrained
Refer to caption: x4.png

Figure 3 displays AIPSS for pretrained and instruction fine-tuned Mamba and Pythia models. As previously noted, pretrained Mamba models do not display similar ICL ability as comparable Pythia models on the evaluated standard NLP benchmarks. In particular, Mamba 2.8B, the largest pretrained Mamba model, displays inconsistent zero-shot improvements as the number of shots increase. While pretrained Mamba-2 models display significantly better ICL ability than Mamba models, Mamba-2 models smaller than 780 million parameters struggle.

However, after instruction tuning, all Mamba models larger than Mamba 130M consistently improve in ICL performance as the number of shots increase. Similarly, the majority of Mamba-2 models larger than Mamba 130M greatly improve in ICL performance. Thus, while pretrained Mamba and Mamba-2 models are only capable of 38% and 82% (respectively) of the AIPSS compared to similar pretrained Pythia models, instruction tuned Mamba and Mamba-2 models are capable of 81.5% and 133% of the AIPSS relative to similarly fine-tuned Pythia models. We note that a significant difference between Mamba and Mamba-2 models is the larger (by a factor of four) latent dimension.

### 5.3 ICL is an emergent ability of instruction tuned Mamba SSMs

We next study the emergent behavior (as a function of model size) of Mamba/Mamba-2 SSMs’ ICL abilities on natural language tasks by comparing to a larger number of Transformer-based LLMs of varying sizes. We compare to OpenELM [] (sizes 270M, 450M, and 1.1B), TinyLlama 1.1B [], and OLMo 1.2B []. To limit the emergent effects on both parameter size and pretraining token counts, we did not evaluate models greater than 2.8 billion parameters and chose open-source checkpoints as close as possible to the 300 billion total pretraining tokens used for Mamba, Mamba-2, and Pythia models. Thus, pretraining token counts for OpenELM, TinyLlama, and OLMo models were 429 billion, 503 billion, and 336 billion, respectively. We note this potentially biases ICL performance in favor of the newly evaluated Transformer-based LLMs, and that direct comparisons between Mamba, Mamba-2, and Pythia are the most fair (as these three classes of models were all pretrained on the same dataset for the same number of total pretraining tokens).

We repeat the experiments from Figure 3, where we evaluate the pretrained and instruction tuned ICL capabilities of all models. To understand the critical role of parameter counts, we group all models into two classes: LLMs containing 450 million parameters or less, and LLMs containing greater than 450 million parameters. ICL performance measured by AIPSS is displayed in Figure 4.

Figure: (a) $450\text{M}<\text{Parameter total}$, Pretrained
Refer to caption: x10.png

From Figure 4, it is clear that pretrained SSMs and Transformers of parameter counts 270 million and less display slight or detrimental ICL abilities (i.e., few-shot performance is worse than zero-shot). For models of greater than 450 million parameters, the majority of SSMs and Transformers display positive ICL abilities, with Mamba 1.4B being an outlier in terms of poor performance. With the exception of TinyLlama at 1-shot performance and Mamba-2 2.7B for 3- and 5-shot performance, the majority of other pretrained models cluster together.

Instruction tuning greatly smooths ICL performance across both parameter classes. While instruction tuned SSMs and Transformers of 160 million parameters or fewer continue to display slight or detrimental ICL abilities, all parameters of 270 million and greater show positive ICL abilities. The instruction tuned OpenELM 450M model displays particularly impressive ICL abilities, but it is difficult to determine whether it is strictly due to architecture and/or pretraining recipe, or partially due to $143\%$ more total pretraining tokens than Mamba/Mamba-2 and Pythia models. For instruction tuned models of greater than 450 million parameters, all SSMs and Transformers show positive ICL abilities, with Mamba-2 2.7B greatly outperforming all other models (both SSM and Transformer) in this class.

Thus, in terms of ICL as a function of SSM model size, while no clear trend presents itself for pretrained models, ICL appears to emerge for instruction tuned Mamba and Mamba-2 SSMs of size 370 million and greater.

## 6 Discussion and Future Directions

Using dynamical systems theory, we’ve shown that the recurrent dynamics of Mamba SSMs are robust to small input perturbations. We’ve extensively confirmed this result, showing that: a) Mamba inference differences due to mixed-precision align with Transformers, (b) Mamba fine-tuning is significantly more robust to changes due to mixed-precision and PEFT than Transformers, and (c) combining MPFT and PEFT can more than halve training time and nearly triple memory efficiency for Mamba models. Using both MPFT and PEFT, we’ve shown that instruction tuning Mamba and Mamba-2 SSMs greatly narrows the pretraining ICL gap on natural language tasks relative to comparable Transformer LLMs. In particular, this allows Mamba-2 SSMs to greatly outperform the ICL abilities of a large number of instruction tuned, attention-based LLMs. Furthermore, complimentary to recent studies, we’ve shown that ICL for natural language tasks can be characterized as an emergent ability of Mamba and Mamba-2 models of 370 millions parameters or greater.

There are several avenues for future work. In particular, adapting Mamba’s CUDA kernels to support more aggressive low-precision PEFT methods [] would further decrease the hardware needed to train Mamba models, while providing additional speedups and testing the limits of the derived stability results. Future studies could further explore what known emergent abilities Mamba SSMs are (and aren’t) capable of, as well as determining new Mamba-specific emergent abilities that are potentially not possible for Transformers to achieve. Furthermore, our theoretical contributions open the door for follow up studies, both in terms of extending our stability results to more general error (and adversarial) robustness results, as well as deriving new Mamba SSM-specific LoRA schemes which leverage the implicit weight tying achieved by targeting MambaBlock modules for either PEFT accuracy or efficiency improvements.

## 7 Acknowledgments

We thank Leidos for funding this research through the Office of Technology. Approved for public release 24-LEIDOS-0515-27826.

## Appendix A Proof of weight-tying using LoRA in the MambaBlock

Due to the low-level nature of Mamba’s prefix scan optimizations (discussed in Section 3), standard use of LoRA adapters is made difficult within Mamba’s SSM-layer. E.g., while $B_{t},C_{t}$ and $\Delta_{t}$ are conceptually PyTorch linear layers, their bundling in a contiguous memory block and careful manipulation makes appending a LoRA adapter on any of these individual matrices non-trivial (particularly, while respecting the highly specialized layout of each LoRA adapters targeted layer). However, we note that the overall design of the MambaBlock’s hardware optimizations may be leveraged to both efficiently learn the parameter-space for the majority of time-varying parameters (thus achieving PEFT) and regularize parameters during training (thus improving fine-tuning generalization).

###### Theorem 1 .

Consider the weight matrix $\mathbf{W}$ of a MambaBlock from Equation 4. Targeting $\mathbf{W}$ for LoRA during fine-tuning ties adaptation weights across $\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$.

###### Proof.

Let $r$ be the specified LoRA dimension. Targeting this matrix for LoRA results in the adapter

$$ $\displaystyle\tilde{\mathbf{W}}=$ $\displaystyle\mathbf{W}+\mathbf{W}^{\prime}$ $\displaystyle=$ $\displaystyle\mathbf{W}+\mathbf{U}\mathbf{V},$ $$

where $\mathbf{U}\in\mathbb{R}{}^{n\times r}$, $\mathbf{V}\in\mathbb{R}{}^{r\times 3d}$, and $\mathbf{W}$ is frozen during fine-tuning. Thus, for index $[i,j]$,

$$ $\displaystyle\mathbf{W}^{\prime}[i,j]=$ $\displaystyle\sum_{k=0}^{r-1}\mathbf{U}[i,k]\mathbf{V}[k,j].$ $$

Recall the form of $\mathbf{W}$:

$$ $\displaystyle\mathbf{W}[t-1,:d]=\texttt{diag}(\bm{\Delta}_{t}),\mathbf{W}[t-1, d:2d]=\texttt{diag}(\mathbf{B}_{t}),\mathbf{W}[t-1,2d:3d]=\texttt{diag}( \mathbf{C}_{t}),$ $$

where $\mathbf{W}[0,:d]=\texttt{diag}(\bm{\Delta}_{1}),\mathbf{W}[n-1,d:2d]=\texttt{
diag}(\mathbf{B}_{T})$, and so on.
For index $[t-1,j]$, we thus have

$$ $\displaystyle\tilde{\mathbf{W}}[t-1,j]=$ $\displaystyle\mathbf{W}[t-1,j]+\mathbf{W}^{\prime}[t-1,j]$ $\displaystyle=$ $\displaystyle\mathbf{W}[t-1,j]+\sum_{k=0}^{r-1}\mathbf{U}[t-1,k]\mathbf{V}[k,j].$ $$

Thus, the weights $\mathbf{U}[t-1,:]$ are tied for any parameter $\tilde{\mathbf{W}}[t-1,j],j\in\{1,\dots,3d\}$, which are used to adapt parameters $\bm{\Delta}_{1},\mathbf{B}_{t},$ and $\mathbf{C}_{t}$.

∎

###### Theorem 1 .

###### Proof.

## Appendix B Mamba stable dynamics proof

Recall the state-space parameters and equations for the MambaBlock; $\mathbf{A},\mathbf{B}_{t},\mathbf{C}_{t},\bm{\Delta}_{t}\in\mathbb{R}{}^{d
\times d}$ for $t\in\{1,\dots,T\}=[T]$. Given an input sequence $\mathbf{u}_{1},\dots,\mathbf{u}_{T}\in\mathbb{R}{}^{d}$, the following linear mapping through latent states $\bm{x}_{1},\dots,\bm{x}_{T}\in\mathbb{R}{}^{d}$ is used to produce the output $\mathbf{y}_{1},\dots,\mathbf{y}_{T}\in\mathbb{R}{}^{d}$:

$$ $\displaystyle\bm{x}_{t}$ $\displaystyle=\bar{\mathbf{A}}_{t}\bm{x}_{t-1}+\bar{\mathbf{B}}_{t}\mathbf{u}_ {t}$ (5) $\displaystyle\mathbf{y}_{t}$ $\displaystyle=\bar{\mathbf{C}}_{t}\bm{x}_{t},$ $$

where $\bar{\bm{\Delta}}_{t}=\texttt{softplus}(\texttt{Linear}(\bm{\Delta}_{t}))\in
\mathbb{R}_{\geq 0}{}^{d\times d}$, $\bar{\mathbf{A}}_{t}=\exp{(\bar{\bm{\Delta}}_{t}\mathbf{A})}$, $\bar{\mathbf{B}}_{t}=\mathbf{A}^{-1}(\bar{\mathbf{A}}-\mathbf{I})\mathbf{B}_{t}$, and $\mathbb{R}_{\geq 0}{}$ is the set of non-negative real numbers. In practice, $\mathbf{A},\mathbf{B}_{t},\mathbf{C}_{t}$ and $\bm{\Delta}_{t}$ are diagonal matrices.

Furthermore, recall the following definitions:

$$ $\displaystyle\bm{x}_{t}$ $\displaystyle=F_{\theta}(\bm{x}_{t-1},\mathbf{u}_{t})$ $$

where $\theta$ denotes the aforementioned time-varying parameters. For input sequence $\mathbf{u}_{t},\dots,\mathbf{u}_{T}$ and initial latent state value $\bm{x}_{0}$, we thus write

$$ $\displaystyle\bm{x}_{T}$ $\displaystyle=F_{\theta}(F_{\theta}(\dots F_{\theta}(\bm{x}_{0},\mathbf{u}_{1} )))\coloneq F_{\theta}^{T-1}(\bm{x}_{0},\mathbf{u}_{1}).$ $$

We first prove that, given two scalar $\varepsilon$-close inputs to a MambaBlock, their deviations do not grow exponentially as the number of recurrences increases (Lemma 1). The main result in the paper is subsequently proved.

###### Lemma 1 .

For input $(\bm{x}_{0},\mathbf{u}_{1})$ to a MambaBlock, small changes $(\bm{x}_{0}+\varepsilon,\mathbf{u}_{1}+\varepsilon)$ produce deviations which are exponentially non-increasing over discrete-time. That is, $\max|F_{\theta}^{N}(\bm{x}_{0},\mathbf{u}_{1})-F_{\theta}^{N}(\bm{x}_{0}+
\varepsilon,\mathbf{u}_{1}+\varepsilon)|\in\mathcal{O}(\varepsilon\exp{(N\zeta
)})$, for some scalar $\zeta\leq 0$.

###### Proof.

Firstly, we note that within the MambaBlock, $\mathbf{A}$ is stored in log-space followed by a negative exponentiation prior to use. Thus, $\mathbf{A}\in\mathbb{R}_{\leq 0}{}^{d\times d}$, where $\mathbb{R}_{\leq 0}{}$ is the set of non-positive real numbers.

Recall that for the maximum deviation, we have:

$$ $\displaystyle\max|F_{\theta}^{N}(\bm{x}_{0},\mathbf{u}_{1})-F_{\theta}^{N}(\bm {x}_{0}+\varepsilon,\mathbf{u}_{1}+\varepsilon)|\in\mathcal{O}(\varepsilon\exp {(N\lambda_{\mathtt{max}}{})}).$ $$

where the maximal Lyapunov exponent $\lambda_{\mathtt{max}}{}$ is defined as:

$$ $\displaystyle\lambda_{\texttt{max}}$ $\displaystyle\coloneq\lim_{T\to\infty}\frac{1}{T}\log\left\lVert\prod_{t=0}^{T }\frac{\partial\bm{x}_{t}}{\partial\bm{x}_{t-1}}\right\rVert_{2},$ $$

and $\left\lVert\right\rVert_{2}$ denotes the spectral norm for matrices.

Thus, to complete the proof, it suffices to show that $\lambda_{\mathtt{max}}{}\leq 0$. Recall that $\mathbf{A}$ and $\bar{\bm{\Delta}}_{t}$ are diagonal. From Equation 5, we thus have

$$ $\displaystyle\lambda_{\texttt{max}}$ $\displaystyle=\lim_{T\to\infty}\frac{1}{T}\log\left\lVert\prod_{t=0}^{T}\frac{ \partial\bm{x}_{t}}{\partial\bm{x}_{t-1}}\right\rVert_{2}$ $\displaystyle=\lim_{T\to\infty}\frac{1}{T}\log\left\lVert\prod_{t=0}^{T}\exp{( \bar{\bm{\Delta}}_{t}\mathbf{A})}\right\rVert_{2}$ $\displaystyle=\lim_{T\to\infty}\frac{1}{T}\log\left\lVert\exp{\sum_{t=0}^{T}( \bar{\bm{\Delta}}_{t}\mathbf{A})}\right\rVert_{2}$ $$

Let $i$ be the dimension which corresponds to the output of the spectral norm, i.e., $i=\mbox{argmax}_{j=1,\dots,d}\{\exp{\sum_{t=0}^{T}(\bar{\bm{\Delta}}_{t}[j,j]
\mathbf{A}[j,j])}\}$. We thus have

$$ $\displaystyle\lambda_{\texttt{max}}$ $\displaystyle=\lim_{T\to\infty}\frac{1}{T}\log\left\lVert\exp{\sum_{t=0}^{T}( \bar{\bm{\Delta}}_{t}\mathbf{A})}\right\rVert_{2}$ $\displaystyle=\lim_{T\to\infty}\frac{1}{T}\log\exp{\sum_{t=0}^{T}(\bar{\bm{ \Delta}}_{t}[i,i]\mathbf{A}[i,i])}$ $\displaystyle=\mathbf{A}[i,i]\lim_{T\to\infty}\frac{1}{T}\sum_{t=0}^{T}\bar{ \bm{\Delta}}_{t}[i,i]$ $$

$\mathbf{A}[i,i]$ is non-positive and $\lim_{T\to\infty}\frac{1}{T}\sum_{t=0}^{T}\bar{\bm{\Delta}}_{t}[i,i]\geq 0$, since $\bar{\bm{\Delta}}_{t}[i,i]\in\mathbb{R}_{\geq 0}{}\;\forall t$. Thus, $\lambda_{\mathtt{max}}\leq 0$.
∎

###### Theorem 2 .

Let $(\bm{x}_{t-1},\mathbf{u}_{t})$ be the latent state and input at an arbitrary time $t\in[1,T]$ within a MambaBlock. Then small changes $(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)$ produce deviations which are exponentially decreasing over discrete-time, i.e., $\max|F_{\theta}^{N}(\bm{x}_{0},\mathbf{u}_{1})-F_{\theta}^{N}(\bm{x}_{0}+
\varepsilon,\mathbf{u}_{1}+\varepsilon)|\in\mathcal{O}(\varepsilon\exp{(N\zeta
)})$, for some scalar $\zeta\leq 0$.

###### Proof.

Let $\tau(t)$ be a function that maps time values such that $\tau(t)\in[1,T-t]$ and $\tau(t)=1,\tau(t+1)=2,\dots,\tau(t+T)=T-t$. Then $\mathbf{B}_{\tau(t)},\mathbf{C}_{\tau(t)},\bm{\Delta}_{\tau(t)}$ define a new MambaBlock with inputs $\mathbf{u}_{\tau(t)},\dots,\mathbf{u}_{\tau(t+T)}$ and subsequent recurrent states $\bm{x}_{\tau(t)},\dots,\bm{x}_{\tau(t+T)}$. Applying Lemma 1 to this MambaBlock with $(\bm{x}_{\tau(t)-1},\mathbf{u}_{\tau(t)})$ completes the proof.
∎

###### Lemma 1 .

###### Proof.

###### Theorem 2 .

###### Proof.

## Appendix C Mamba stable outputs proof

###### Theorem 3 .

Assume $(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)$ produce deviations which are exponentially non-increasing over discrete-time. Then small changes to the output $\mathbf{y}_{t}$ are also exponentially non-increasing over discrete time.

###### Proof.

Recall that $\bm{x}_{T}=F_{\theta}^{T}(\bm{x}_{0},\mathbf{u}_{1})$. Furthermore, recall from Equations 1 and  2, $\mathbf{y}_{t}=\mathbf{C}_{t}\bm{x}_{t}$, where $\mathbf{C}_{t}$ is diagonal.

Let

$$ $\displaystyle\mathbf{y}_{T}$ $\displaystyle=G_{\theta}^{T}(\bm{x}_{0},\mathbf{u}_{1})=\mathbf{C}_{T}\bm{x}_{ T}=\mathbf{C}_{T}F_{\theta}^{T}(\bm{x}_{0},\mathbf{u}_{1}).$ $$

Consider $\varepsilon$-close inputs $(\bm{x}_{t-1},\mathbf{u}_{t})$ and $(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)$, and their respective outputs $\mathbf{y}_{t}$ and $\mathbf{y}_{t}^{\prime}$. Assume $(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)$ produce deviations which are exponentially non-increasing over discrete-time. That is, $\max|F_{\theta}^{N}(\bm{x}_{t-1},\mathbf{u}_{t})-F_{\theta}^{N}(\bm{x}_{t-1}+
\varepsilon,\mathbf{u}_{t}+\varepsilon)|\in\mathcal{O}(\varepsilon\exp{(N\zeta
)})$, for some scalar $\zeta\leq 0$.

We thus have

$$ $\displaystyle\max|\mathbf{y}_{t}-\mathbf{y}_{t}^{\prime}|$ $\displaystyle=\max|G_{\theta}^{N}(\bm{x}_{t-1},\mathbf{u}_{t})-G_{\theta}^{N}( \bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)|$ $\displaystyle=\max|\mathbf{C}_{N}F_{\theta}^{N}(\bm{x}_{t-1},\mathbf{u}_{t})- \mathbf{C}_{N}F_{\theta}^{N}(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+ \varepsilon)|$ $\displaystyle\propto\max|F_{\theta}^{N}(\bm{x}_{t-1},\mathbf{u}_{t})-F_{\theta }^{N}(\bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)|,$ $$

where proportionality follows due to the diagonality of $\mathbf{C}_{N}$ and the vector-absolute value. Thus,

$$ $\displaystyle\max|G_{\theta}^{N}(\bm{x}_{t-1},\mathbf{u}_{t})-G_{\theta}^{N}( \bm{x}_{t-1}+\varepsilon,\mathbf{u}_{t}+\varepsilon)|$ $\displaystyle\in\mathcal{O}(\varepsilon\exp{(N\zeta)})$ $$

∎

###### Theorem 3 .

###### Proof.

## Appendix D Experimental Details

All model checkpoints were evaluated on all benchmarks and few-shot settings using the LM evaluation harness from Eleuther AI [], version 0.4.2. Pythia and Mamba Huggingface checkpoints were used for all inference and fine-tuning experiments, e.g., EleutherAI/pythia-160m and state-spaces/mamba-130m-hf for the smallest respective models. All fine-tuning experiments were run using package versions Transformers 4.40.0.dev0, Accelerate 0.28.0, TRL 0.8.1, PyTorch 2.2.1+cu121, and PEFT 0.10.0. All Mamba-2 models were run using mamba-ssm v2.2.2 using Huggingface checkpoints, e.g., state-spaces/mamba-130m for the smallest model.

For MPFT, Flash Attention 2.0 [] via flash_attn 2.5.7 was used for Pythia models. For FP16 and BF16 inference results, Flash Attention 2.0 was used for both Pythia and OLMo models. For OLMo results, the 336B-token checkpoint was used by specifying revision=step80000-tokens336B.

All Alpaca and OpenHermes fine-tuning experiments used the following training recipe (adapted from []): AdamW_torch optimizer, cosine annealing schedule, no gradient accumulation, maximum norm of 1.0 for gradient clipping, and no warmup steps. Training epochs used for all Alpaca and OpenHermes experiments were three and one, respectively. For both Pythia and Mamba models, the learning rate and LoRA dimension $r$ were scaled to improve performance of smaller models (per-model values listed in Table 2).

For SLL LoRA, targeted Mamba layers were {x_proj, embeddings, in_proj, out_proj}; x_proj is the large MambaBlock memory buffer which, when targeted by LoRA, regularizes the majority of SSM parameters during fine-tuning through weight tying (Theorem 3). Pythia targeted SLL LoRA layers were {dense, embed_in, query_key_value, dense_h_to_4h,dense_4h_to_h}, chosen to balance performance across model sizes.

All experiments were run using a single-GPU Nvidia A10G (24 GB total memory). For Pythia, Mamba, and Mamba-2 ALL LoRA experiments in Figure 3, all models followed the same training and PEFT recipes, save for Mamba-2 2.7B which required a LoRA $r$ dimension of 64 to fit in A10G memory.

**Table 2: Learning rate and LoRA dimension $r$ values**
| Mamba size | Mamba-2 size | Pythia size | learning rate | Mamba/Pythia LoRA $r$ | Mamba-2 LoRA $r$ |
| --- | --- | --- | --- | --- | --- |
| 130M | 130M | 160M | 1.0e-5 | 8 | 8 |
| 370M | 370M | 410M | 5.0e-5 | 16 | 16 |
| 790M | 780M | 1B | 1.0e-6 | 32 | 32 |
| 1.4B | 1.3B | 1.4B | 5.0e-6 | 64 | 64 |
| 2.8B | 2.7B | 2.8B | 5.0e-7 | 128 | 64 |

The Alpaca dataset is freely available for download at [https://huggingface.co/datasets/tatsu-lab/alpaca](https://huggingface.co/datasets/tatsu-lab/alpaca) under open-source license CC-by-NC 4.0. The OpenHermes dataset is freely available for download at [https://huggingface.co/datasets/teknium/OpenHermes-2.5](https://huggingface.co/datasets/teknium/OpenHermes-2.5) under open-source license MIT, Apache 2.0, CC.

## Appendix E Mamba-2 mixed-precision inference pretrained LLM performance tables

**Table 3: Mean full-precision (FP32) divergence in MMLU performance for mixed-precision inference. Divergence is averaged over {0, 1, 3, 5}-shot performance. Pretrained checkpoints are used for Mamba (M), Mamba-2 (M2), Pythia (P), OLMo [] (O), and Phi-1.5 [] (Phi) models.**
| Model | M | M2 | P | M | M2 | P | M | M2 | P | O | M | M2 | P | Phi | M | M2 | P |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Size | 130m | 130m | 160m | 370m | 370m | 410m | 790m | 780m | 1b | 1.4b | 1.3b | 1.4b | 1.5b | 2.8b | 2.7b | 2.8b |  |
| FP16 $\mu$ | 0.03 | 0.07 | 0.35 | 0.05 | 0.05 | 0.06 | 0.21 | 0.12 | 0.05 | 0.04 | 0.04 | 0.04 | 0.07 | 0.03 | 0.15 | 0.26 | 0.12 |
| BF16 $\mu$ | 0.05 | 0.67 | 1.45 | 0.20 | 0.52 | 0.20 | 0.66 | 0.29 | 0.16 | 0.13 | 0.31 | 0.40 | 0.13 | 1.05 | 1.17 | 1.02 | 0.11 |

## Appendix F Adapted PEFT-layer effects on Mamba-2 zero-shot performance

As described in Section 3.2, both Mamba and Mamba-2 store the majority of time-varying SSM parameters in a large memory buffer (instantiated as a PyTorch linear layer’s weight matrix), denoted as $\mathbf{W}$. For PEFT via LoRA, we ablate the impact of targeting $\mathbf{W}$, as well as the impact of Theorem 3, where time-varying variables accessed through $\mathbf{W}$ were shown to be regularized through weight tying.

Firstly, we instruction tune Mamba-2 models using LoRA by both adapting $\mathbf{W}$ and adapting all linear layers other than $\mathbf{W}$. Mamba-2 MambaBlocks contain two linear layers, thus the former targets only the $\mathbf{W}$ linear layer whereas the latter targets the other linear layer in each block. As shown in Table 4, PEFT with only $\mathbf{W}$ targeted within the MambaBlock near uniformly results in better performance than only targeting other layers, with the former outperforming the latter on 32 out of 35 natural language tasks. This makes intuitive sense since $\mathbf{W}$ represents the majority of Mamba’s time-varying parameters (as previously mentioned). Thus, while previous works [, ] have displayed the importance of Mamba’s time-varying parameters for pretraining performance, this verifies the importance of Mamba’s time-varying parameters for instruction tuning performance.

**Table 4: Zero-shot performance for instruction tuned Mamba-2 models where: ✓ denotes the large memory buffer $\mathbf{W}$ containing the majority of temporal variables (described in Section 3.2) is targeted for LoRA adaptation, and ✗ denotes $\mathbf{W}$ is not adapted. The top-performance for each task per model is highlighted in bold .**
| Model | $\mathbf{W}$ targeted? | LAMBADA | LAMBADA | HellaSwag | PIQA | Arc-E | Arc-C | WinoGrande |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  |  | ppl $\downarrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ |
| Mamba-2<br>130M | ✓ | 15.37 | 45.16 | 35.41 | 65.02 | 47.94 | 24.91 | 52.17 |
| ✗ | 16.95 | 43.30 | 35.24 | 64.85 | 47.47 | 24.06 | 52.17 |  |
| Mamba-2<br>370M | ✓ | 8.03 | 54.16 | 46.87 | 69.53 | 53.49 | 27.73 | 57.14 |
| ✗ | 8.50 | 53.74 | 46.59 | 70.67 | 54.80 | 26.79 | 55.64 |  |
| Mamba-2<br>780M | ✓ | 5.79 | 61.61 | 55.14 | 71.98 | 61.11 | 29.18 | 60.09 |
| ✗ | 5.86 | 61.63 | 54.94 | 72.03 | 60.98 | 28.41 | 60.22 |  |
| Mamba-2<br>1.3B | ✓ | 4.54 | 65.73 | 60.88 | 73.67 | 66.16 | 34.56 | 61.80 |
| ✗ | 5.05 | 65.44 | 59.84 | 73.39 | 64.10 | 33.11 | 61.09 |  |
| Mamba-2<br>2.7B | ✓ | 4.05 | 69.63 | 66.73 | 76.50 | 69.95 | 36.77 | 64.56 |
| ✗ | 4.10 | 69.61 | 66.60 | 76.39 | 69.53 | 36.26 | 63.93 |  |

Next, we present a counterintuitive experiment to demonstrate the impact of Theorem 3. As before, we instruction tune Mamba-2 models using LoRA, focusing on the two largest model sizes. This time, however, we target *all linear layers* within Mamba-2’s MambaBlock and contrast this with targeting *only $\mathbf{W}$* within the MambaBlock. Displayed in Table 5, we can see that adapting more SSM parameters does not necessarily lead to improved performance across the board. Rather, adapting only $\mathbf{W}$ for Mamba-2 outperforms adapting all linear layers on eight of the 14 natural language tasks.

The results in Table 5 thus present two cases: (a) *regularization*: only adapting parameters which lead to weight tying (by Theorem 3) and (b) *increased learning capacity*: adapting more parameters, at the cost of learning unregularized parameters. Through regularization via weight tying [], the former leads to good generalization. In contrast, while adapting more parameters, (b) includes unregularized variables, leading to positive improvements on only a minority of tasks when compared to the fine-tuning of fewer, but regularized, parameters. We note that adapting all linear layers is often performed when fine-tuning attention-based LLMs using LoRA []. Thus, a similar regularization-vs-capacity tradeoff for Transformers LLMs may present itself by carefully studying LoRA’s affects when targeting specific linear layers in attention-based architectures.

**Table 5: Zero-shot performance for instruction tuned Mamba-2 models. ✓ denotes only $\mathbf{W}$ was targeted for LoRA adaptation within the MambaBlock, and ✗ thus denotes both linear layers within each MambaBlock were adapted. The top-performance for each task per model is highlighted in bold.**
| Model | Only $\mathbf{W}$ targeted? | LAMBADA | LAMBADA | HellaSwag | PIQA | Arc-E | Arc-C | WinoGrande |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|  |  | ppl $\downarrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ | acc $\uparrow$ |
| Mamba-2<br>1.3B | ✓ | 4.54 | 65.73 | 60.88 | 73.67 | 66.16 | 34.56 | 61.80 |
| ✗ | 4.94 | 62.95 | 60.06 | 73.78 | 64.02 | 34.81 | 61.33 |  |
| Mamba-2<br>2.7B | ✓ | 4.05 | 69.63 | 66.73 | 76.50 | 69.95 | 36.77 | 64.56 |
| ✗ | 3.77 | 68.39 | 67.51 | 75.95 | 69.53 | 38.31 | 65.35 |  |

## Peer Reviews

confidence: 3
contribution: 2
initial_rating: 5
presentation: 3
questions: 1. The introduction could be improved by adding a summary of contributions to provide clearer insight into the paper's impact and contribution.
2. Is it appropriate to set the same learning rate for different models (e.g. Mamba and Pythia) when comparing training stability? Whether it is possible that a better-tuned Transformer model could demonstrate enhanced stability and performance, suggesting that the comparison might benefit from adjustments in learning rate settings. Conducting an ablation study or sensitivity analysis on the learning rates for different models maybe can help.
soundness: 3
strengths: 1. The paper is well-written and easy to follow.
2. The paper provides a theoretical analysis to support experimental performance.
3. Comprehensive experiments compare the Mamba model with Transformer-based models across different scenarios.
summary: This paper aims to address a noticeable gap in research concerning the amenability of the Mamba model to popular fine-tuning frameworks such as PEFT and MPFT. Utilizing theoretical insights from dynamical systems, the paper demonstrates that minor input variations within the SSM layer of either model do not lead to outputs that deviate exponentially. This theoretical assertion is further validated by empirical experiments.
weaknesses: Though the theoretical analysis of this paper is really solid, since most researchers nowadays use MPFT and PEFT for Mamba, the contribution of this paper may be limited. It may be better if some weaknesses about MPFT and PEFT for Mamba are figured out and then optimized accordingly.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: Why did you choose to work with different sets of transformer models in the main results versus the other experiments? For instance, you give results for OLMo on the first experiment (Table 1) but not second, and results for OpenELM in all experiments but the first one.
soundness: 4
strengths: - The paper addresses a very important problem that, until now, has helped to prevent the wider use of SSMs: training resources for an SSM have been greater than a similarly-sized transformer, because the transformer has been known to be compatible with efficient fine-tuning techniques. Addressing this disparity will help more people to consider working with SSMs, as their computational requirements will suddenly be within reach
- The combination of both theory and empirical results is quite persuasive and is convincing that Mamba is indeed compatible with MPFT/PEFT
- Theoretical results are simple, elegant and important. The proofs in the appendix are easy to follow and look solid.
- Care has been put into the experimental setup, for instance everything being trained using the same batch size in the main results
summary: - The authors work to demonstrate that the Mamba SSM is robust to small input perturbations during training, meaning that Mamba is compatible with mixed-precision fine-tuning (MPFT) and parameter-efficient fine-tuning (PEFT). The authors include both theoretical and empirical evidence for this finding.
- Theory results are in section 3, using dynamical systems theory (Lyapunov exponents) to demonstrate that Mamba’s recurrent dynamics are robust to small input changes
- Section 5’s empirical results contain the following experiments (this list defines the numbers which I’ll use to refer to experiments later):
  1. Main results: divergence in accuracy between FP32 and FP16 or BF16 inference, showing that the accuracy divergence for Mamba is roughly similar to that for pythia and OLMo
  2. Non-divergent mamba fine-tuning: divergence in MMLU accuracy compared to full-precision for FP16 or BF16 models fine-tuned fully, or using LoRA on all or a subset of linear layers. Shows that divergence for Mamba is generally less than similar-size transformers.
  3. Hardware throughput and memory-utilization improvements: Average tokens-per-second and maximum memory-per-token for mamba of varying sizes, using FP32 full fine-tuning, or FP16/BF16 LoRA on all or a subset of linear layers. Shows that any form of PEFT is faster and less memory-intensive than the FP32 full fine-tuning
  4. Instruction tuning’s impact on Mamba ICL for natural language tasks: authors claim that instruction tuning narrows the ICL gap between Mamba and Pythia
  5. ICL as an emergent ability of Mamba SSMs: compares ICL performance for Mambas and several transformer models of varying sizes
weaknesses: - My most major critique is that there aren’t any error bars or sense of the spread/randomness in the empirical results, especially for experiment 2 / figure 1, experiment 4 / figure 3 for the fine-tuned models and experiment 5 / figure 4 for the fine-tuned models.
-  My second biggest critique is that each experiment is only performed with one dataset (MMLU, fine-tuning with Alpaca for fine-tuning experiments). Including more than one dataset or task would strengthen the claims you’re drawing from the empirical evaluations. Experiment 5 includes more datasets, but the results for all datasets are averaged together and readers can’t consider their performances separately
- The graphs are nice in figures 1-4, but it would also be helpful to include the actual numbers in tables in the appendix
- The paper seems to have a lot of extra contextualization in it, taking up room which could be devoted to more detailed empirical analysis. In particular, section 2 background and section 5 related work seem to just both be disjoint related work sections. Usually I would consider the “background” section to be merely preliminary information and definition of symbols that are necessary to understand the rest of the paper, like a statement of the SSM equations and formal definition of Lyapunov exponent. Then, related work would be a longer section detailing, well, related work. Just as an example for comparison, you can see this differentiation in roles between background and related work in this paper’s sections 2 and 3 here: https://arxiv.org/pdf/2409.00717 Contextualization/related work is important to include, but I would consider prioritizing and moving at least some of it to appendix to include more empirical results
- Some of the number references seem to be wrong:
  - Line 345, “Figure 5” seems to actually be referring to Figure 1
  - Line 379, “Figure 5” seems to refer to Figure 2 (did you maybe put your \label{} command for the figures in the wrong spot inside your figures’ code blocks?)
  - Appendix theorem 3 corresponds to main paper theorem 2.

Overall, I'm setting my rating to 6 due to the significance of the theoretical results. However, I would appreciate more detail to the empirical evaluations as I mention above.

---

confidence: 5
contribution: 2
initial_rating: 3
presentation: 2
questions: See weakness.
soundness: 2
strengths: This work provides promising evidence that fine-tuning Mamba on instruction-tuning data can improve its in-context learning abilities.
summary: This paper studies Mamba, a state-space model (SSM) that has previously been introduced as an efficient alternative to Transformers. The authors analyze Mamba's stability in mixed-precision and parameter-efficient fine-tuning by applying Lyapunov exponents, theoretically and empirically confirming its resilience against input perturbations. Experiments show that Mamba maintains stability better than comparable Transformers under mixed precision and achieves notable memory and computation efficiency. Additionally, instruction tuning enhances Mamba's in-context learning, suggesting that SSMs can approach or surpass Transformer models in certain few-shot tasks.
weaknesses: - Line 51:  For some training framework it does not keep master weight in fp32 which problematic for Mamba. But Mamba was still trained with mixed precision using AMP.

- Theory 1 seems shallow: Isn't Lemma 1 trivial to derive? \( dx_{t+1}/dx_t \) directly represents the decay rate, which must be \(\leq 1\) to prevent exponential growth in cumulative products. This insight is obvious for any recurrent model, making Theorem 1’s assertion about exponential decay rather redundant.

- Theory 2 seems unnecessary: It’s clear that concatenating multiple weight matrices with LoRA applied to the larger matrix creates dependencies. However, there's no practical advantage demonstrated here, nor is there an empirical basis for this approach.

- Line 274: Why use MMLU as a proxy metric? For models at this scale, MMLU scores are generally around random (i.e., ~25%), leading to limited interpretability. Additionally, only the differential score is provided, without the original MMLU results, which weakens MMLU’s reliability as a metric in this context.

- Instruction tuning experiments: Pythia feels like a weak baseline. And is it plausible to claim Mamba has an “emergent ability” (line 439) for in-context learning after instruction tuning, given SSMs' inherent limitations, as noted in [1,2]? Figure 3 also shows a performance drop for Mamba2 as shot count rises, likely due to state-space models’ well-known difficulties with long-sequence processing and in-context learning.

[1] https://arxiv.org/abs/2402.18510

[2] https://arxiv.org/abs/2402.18668

Meta-review: Reviewer find the paper to have some interesting hypothesis on stability of Mamba models but expressed strong concerns over the choice of datasets and strength of theoretical results. Authors addressed some of these concerns by adding more experimental results, however reviewers are not fully convinced about the strength of the results. Overall I think this paper requires another round of rewriting to clearly present the hypothesis and the evidence. Hence I recommend rejection.

Decision: Reject