Demystify Mamba in Vision: A Linear Attention Perspective

Mamba is an effective state space model with linear computation complexity. It has recently shown impressive efficiency in dealing with high-resolution inputs across various vision tasks. In this paper, we reveal that the powerful Mamba model shares surprising similarities with linear attention Transformer, which typically underperform conventional Transformer in practice. By exploring the similarities and disparities between the effective Mamba and subpar linear attention Transformer, we provide comprehensive analyses to demystify the key factors behind Mamba's success. Specifically, we reformulate the selective state space model and linear attention within a unified formulation, rephrasing Mamba as a variant of linear attention Transformer with six major distinctions: input gate, forget gate, shortcut, no attention normalization, single-head, and modified block design. For each design, we meticulously analyze its pros and cons, and empirically evaluate its impact on model performance in vision tasks. Interestingly, the results highlight the forget gate and block design as the core contributors to Mamba's success, while the other four designs are less crucial. Based on these findings, we propose a Mamba-Inspired Linear Attention (MILA) model by incorporating the merits of these two key designs into linear attention. The resulting model outperforms various vision Mamba models in both image classification and high-resolution dense prediction tasks, while enjoying parallelizable computation and fast inference speed. Code is available at https://github.com/LeapLabTHU/MLLA.

Paper

References (58)

Scroll for more · 38 remaining

Similar papers

Peer review

Reviewer XBcf7/10 · confidence 5/52024-07-08

Summary

This paper presents a thorough analysis of the key factors contributing to the success of the S6 module in Mamba model, and introduces a new linear attention vision network, MLLA, inspired by the S6’s design. Extensive experimental results show outstanding performance, validating the effectiveness of the proposed model.

Strengths

The motivation and analysis underlying this work are fascinating and perceptive, offering a profound examination of the mathematical relationships between Mamba and Linear Attention. A thorough investigation of the performance contributions of each component from S6 is conducted, with corresponding refinements made to linear attention, ultimately leading to the development of MLLA. The proposed MLLA serves as a generic vision backbone network, which outperforms recent Mamba-based models, demonstrating its superior capabilities

Weaknesses

I appreciate the paper's insightful analyses, but several key concerns regarding methodology and experiments need to be addressed. If the authors fully resolve these issues, I would be willing to reconsider my evaluation. **Possible inaccurate analysis of single-head attention** The analysis of single-head attention appears to be inaccurate and unclear. Generally, multi-head attention in Transformer generates H dynamic matrices during attention computation, where H represents the number of heads. However, the paper seems to interpret S6 as a single-head module without providing sufficient evidence. The authors should explain this point from the perspective of the number of attention matrices generated. Moreover, according to Reference 1, S6 can actually produce multiple dynamic matrices instead of just one. **Unfair comparison on ImageNet-1K dataset** The paper uses MESA as its optimizer, improving accuracy compared to AdamW. In contrast, the methods in Table 3 do not use MESA and may also be prone to overfitting. For fairness, authors should ensure that training strategies are consistent with competitors. Moreover, the authors should not hide this apparent difference in the appendix. **Questionable motivation for using Swin as the baseline** The motivation for using Swin as a baseline is questionable. One important aspect of linear attention is its ability to efficiently establish global dependencies, so it is unclear why window-based linear attention is used. Additionally, the specific configuration of the baseline model, such as channels and depth, is not provided. **Unclear setting of d_state in SSM block design** In the block design, it is unclear what value d_state of SSM is set to. **Insufficient experiments on downstream tasks** (1) Semantic segmentation should include tiny, small, and base models. (2) Mask R-CNN 3x should include the base model. (3) The performance comparison of MLLA-T and VMamba-T on object detection is lacking. **Unfair comparison in Table 6** The comparison in Table 6 is unfair. The authors aim to compare the performance of different linear attention methods, but different block settings have a significant impact. The authors should use the same architecture, replacing only token mixer module. **Typo** In line 294, 'SMM' should be 'SSM'.

Questions

Please see the main weaknesses.

Rating

7

Confidence

5

Soundness

3

Presentation

2

Contribution

3

Limitations

Please see the main weaknesses.

Reviewer dwbt7/10 · confidence 3/52024-07-11

Summary

The paper takes a deep dive into the workings of Mamba in vision related tasks and compares it to Linear Attention. They conclude that Mamba is a special form of Linear Attention and describe the role that certain parts in the architecture and give them a name that better represent their actual use. They come up with input and forget gate that control the flow of information while shortcuts are closely related to the residual connections. The authors take those learnings and apply them to linear attention and show that those concepts do improve the linear attention mechanism up to the point where it beats mamba.

Strengths

The authors draw clear connections between Linear Attention and Mamba which is showcased in terms of raw similarity (eq. 11 and 12). Furthermore, they underline this by showing the input gate values on two example images which helps general understanding. They demonstrate the usefulness of the explained modules in Mamba apply them to Linear Attention and show that they do improve performance. In total a sound paper. The overall gist can be followed very nicely.

Weaknesses

No apparent weaknesses

Questions

- Why did you choose to use Swin Transformer? - The forget gate creates local bias and position information but also decays the previous hidden state if I understood correctly. When replaced by RoPE or similar the performance increases as shown in Table2. Does this mean that the local bias and the decay can hinder performance?

Rating

7

Confidence

3

Soundness

4

Presentation

4

Contribution

3

Limitations

The authors mention the limitations of their work, especially that is it no exhaustive.

Reviewer ii6x6/10 · confidence 4/52024-07-12

Summary

This paper explores the similarities and differences between the Mamba and linear attention Transformer models. It redefines Mamba as a variant of linear attention Transformer with six key distinctions. The paper also studies each design's impact, identifying the forget gate and block design as key to Mamba's success. Based on these findings, the paper introduces a Mamba-like linear Attention (MLLA) model, which outperforms other vision Mamba models on various tasks while maintaining fast computation and inference speed.

Strengths

* The paper is well-written and well-motivated from the perspective of linear attention. * The findings are interesting to me.

Weaknesses

* Several works using Mamba for image synthesis should be discussed [1][2][3]. In Line 68, I wonder whether the exploration in this paper is orthogonal to previous explorations on Mamba. For example, Zigma considers layerwise scanpaths with 8 directions. Can the proposed method still yield some improvements on that result? * Another consideration is that the authors should discuss something with this paper: https://arxiv.org/abs/2406.06484. Check Table 4; it provides a much more general framework that includes most of the linear attention models. * My third concern is whether the exploration in this work can extend to other linear attention-based models, such as RWKV and xLSTM.

Questions

I have some concerns (see weaknesses) about this paper. I am inclined to raise my score if my concerns are fully resolved. **Reference:** [1],Diffusion Models Without Attention.CVPR24. [2],ZIGMA: A DiT-style Zigzag Mamba Diffusion Model,ECCV24. [3],Scalable Diffusion Models with State Space Backbone,Arxiv.

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

2

Limitations

Yes, they are addressed and discussed.

Reviewer QFdu7/10 · confidence 5/52024-07-13

Summary

This paper primarily discusses the similarities and differences between the Mamba model and the Linear Attention Transformer, and conducts an in-depth analysis of the key factors contributing to Mamba's success in visual tasks. The paper elaborates on six major design differences of Mamba compared to the Linear Attention Transformer: input gate, forget gate, shortcut connection, attention-free normalization, single-head attention, and modified block design. For each of these designs, the author meticulously analyzes their advantages and disadvantages, and evaluates their applicability in visual tasks. Through experimental research, the paper emphasizes that the forget gate and block design are the core contributors to Mamba's success. Based on these findings, the author proposes a model called Mamba-Like Linear Attention (MLLA), which integrates the advantages of the forget gate and block design into the linear attention framework. Experimental results show that MLLA outperforms various visual Mamba models in image classification and high-resolution dense prediction tasks, while maintaining parallel computing capabilities and fast inference speed.

Strengths

1. The paper provides a new perspective for understanding Mamba's success by thoroughly analyzing the similarities and differences between the Mamba model and the Linear Attention Transformer. By rephrasing formulas, the paper considers Mamba as a variant of the Linear Attention Transformer and clearly points out Mamba's six design features, including input gate, forget gate, shortcut connection, attention-free normalization, single-head attention, and modified block design. 2. Each design aspect is meticulously analyzed, and its advantages and disadvantages in visual tasks are evaluated. Experimental results verify that the forget gate and block design significantly contribute to Mamba's performance improvement, while other designs either have minimal marginal contributions or may potentially harm model performance. 3. The Mamba-Like Linear Attention (MLLA) model is proposed, combining the advantages of the forget gate and block design in linear attention. The MLLA model outperforms existing Mamba models in image classification and high-resolution dense prediction tasks while maintaining computational parallelization and high-speed inference capabilities.

Weaknesses

There are some minor issues: 1. In the final MLLA model, there is no SSM but a forget gate. The forget gate was originally proposed in RNN and LSTM. Thus calling it a Mamba-like model seems to be improper. 2. Previous "Demystify" papers are not cited in the paper, e.g., [a, b, c]. The final architecture MLLA follows the macro structure of Swin and [a,b,c] all show that the macro structure is very important but the local blocks are not so important. The paper should build a connection with the previous "Demystify" papers and tell us what are the most effective parts? [a] On the Connection between Local Attention and Dynamic Depth-wise Convolution, ICLR 2022 [b] What Makes for Hierarchical Vision Transformer? DOI: 10.1109/TPAMI.2023.3282019 [c] Demystify Transformers & Convolutions in Modern Image Deep Networks, arXiv:2211.05781

Questions

1. How many GPUs are used to perform this research, including the training cost and ablation experiments cost? 2. Why Fig. 1 is placed on page 2 but cited on page 4? 3. What are the results of Mamba + Swin?

Rating

7

Confidence

5

Soundness

3

Presentation

3

Contribution

3

Limitations

Nope.

Reviewer XBcf2024-08-09

I appreciate the authors' response, which has addressed some of my concerns. Although I understand that the purpose of this paper is to establish connections between various mechanisms in Mamba and Linear Attention, the main issue remains the unfair experimental implementation. The authors should provide results without MESA in Table 3 for tiny, small, and base models, as MESA can boost performance like token labeling, and this should be explicitly indicated. The current presentation may mislead follow-up works due to the unfair training conditions. The authors' claim that other models do not benefit from MESA lacks any supporting evidence. Regarding downstream tasks, while the authors clarify that they did not use MESA, it’s important to note that the pre-trained models have incorporated MESA. This introduces an inherent unfairness in weight initialization, which may affect the fairness of the final performance comparisons. The authors mention that other Mamba-based models have not been tested on 3x schedule-based detection tasks, which raises a question: are Mamba-based models unable to train successfully on 3x schedule-based detection tasks? If so, the potential applications of Mamba-based models would be significantly limited. Additionally, please note that the proposed method belongs to the vision transformer family, not Mamba-based models, and it is crucial to conduct related experiments as listed in many previous works. Reporting results with the 3x schedule is more meaningful, as this allows the models to converge to a more consistent outcome, providing a more reliable comparison. The author should be aware that one of the most crucial aspects of a vision backbone paper is the experimental section, which must adhere to highly consistent training conditions with other competitors to ensure a fair comparison. Implicitly introducing additional tricks to improve performance is misleading and unfair to follow-up works. I must reiterate that the unfair experimental design remains a significant concern.

Authorsrebuttal2024-08-09

We would like to express our appreciation for your comments. However, we believe there are some misunderstandings and we offer clarifications below. --- **1. MESA does not affect the three main contributions and findings of this work.** We would like to emphasize that the three main contributions of our paper remain unaffected by the use of MESA: - We reveal Mamba’s close relationship to linear attention Transformer. - We provide detailed analyses of each special design and validate that the forget gate and block design largely lead to Mamba’s superiority. - We present MLLA, a novel linear attention model that outperforms vision Mamba models. The first finding is thoroughly analyzed in Section 4 of our paper. The second one is validated by the results in Table 1 and Table 2, ***where MESA is not employed.*** The last contribution of our work, MLLA, uses MESA in its training. However, as we already mentioned in our previous response, without MESA, MLLA-T can also achieve 83.3 accuracy and still significantly surpasses various vision Mamba models. Notably, the MLLA model is built to validate our last finding, i.e. whether linear attention can match or surpass Mamba in vision, rather than to compete against SOTA vision Transformers. ***In conclusion, MESA does not influence the core contributions of our work, but rather serves as an additional strategy to help MLLA performs optimally.*** We further clarify our intent and the reason for using MESA in the following. --- **2. The reason for using MESA.** We would first like to clarify that MESA is just a strategy to prevent overfitting, and it cannot boost performance like token labeling. Token labeling benefits from ***a pre-trained model***, functioning similarly to distillation, whereas MESA only enhances the model's generalization ability and ***doesn't use any pre-trained models.*** Just like in the early stages of studies on visual Transformer, currently vision Mamba research does not have a well-established and universally accepted training protocol. The conventional training setting for vision Transformer may not be optimal for vision Mamba and our Mamba-Like Linear Attention. Therefore, we additionally employ the overfitting prevention strategy MESA to alleviate the overfitting problem of MLLA model and fully demonstrate its potential. Our goal is to provide the community with more robust models. We believe that excessive pursuit of strictly unchanged training setting could actually restrict the exploration of new architectures. --- **3. Results without MESA.** - To better address your request, we further provide the results without MESA. - Actually, we already provided the result for ***MLLA-T trained without MESA*** in our previous response. Here, we offer a comparison with vision Mamba models based on this result. | Model | #Params | FLOPs | Acc. | | :---------------: | :-----: | :---: | :--: | | Vim-S | 26M | 5.1G | 80.3 | | VMamba-T | 31M | 4.9G | 82.5 | | LocalVMamba-T | 26M | 5.7G | 82.7 | | MLLA-T (w/o MESA) | 25M | 4.2G | 83.3 | ***As you can see, without MESA, MLLA-T can also achieve comparable result and still significantly surpass various SOTA vision Mamba models.*** - We are currently in the process of training ***MLLA-S/B under the no MESA setting*** and will provide those results ***in a few days.*** - Furthermore, we will utilize the backbone trained without MESA to conduct downstream tasks. - All these results will be included in the revised manuscript. We will provide more experimental results within our capabilities and try our best to benefit the community and follow-up works. --- **3. Downstream tasks.** - There seems to be a misunderstanding. In our previous response, we stated that Mask R-CNN 3x results for ***base level model, e.g. VMamba-B,*** is hardly reported by vision Mamba works. However, we did not claim that Mamba-based models have not been tested on 3x schedule. Indeed, we already provided comparison of ***tiny and small level models under 3x schedule in Table 9. of our paper.*** - The primary focus of our paper is on comparisons with vision Mamba models, rather than achieving SOTA results. Given that the works we compared with do not present 3x detection results for base level model, we also omit this experiment previously. Currently, we are working on this experiment to better address your request.

Reviewer XBcf2024-08-13

I appreciate your clarification. The use of MESA or not does not impact the paper's main contribution. However, I believe it's unfair to directly compare other methods with this work, as it employs additional training techniques. Given the approaching rebuttal deadline, conducting further experiments on small and base models may be difficult. Nevertheless, based on the authors' provided results of MLLA-T (without MESA), I find it acceptable. As a result, I have increased my score. I hope the authors will include comprehensive experimental results in the revised paper.

Authorsrebuttal2024-08-13

Dear Reviewer XBcf, we sincerely appreciate your rigorous research attitude and valuable comments. Here, we provide some additional results we obtained these days to fully resolve your concern. --- **1. Results without MESA.** - ***MLLA models trained without MESA.*** | Model | #Params | FLOPs | Acc. | | :-------------------: | :-----: | :---: | :------: | | Vim-S | 26M | 5.1G | 80.3 | | VMamba-T | 31M | 4.9G | 82.5 | | LocalVMamba-T | 26M | 5.7G | 82.7 | | **MLLA-T (w/o MESA)** | 25M | 4.2G | **83.3** | | **MLLA-T (w/ MESA)** | 25M | 4.2G | **83.5** | | | | | | | VMamba-S | 50M | 8.7G | 83.6 | | LocalVMamba-S | 50M | 11.4G | 83.7 | | **MLLA-S (w/o MESA)** | 43M | 7.3G | **84.2** | | **MLLA-S (w/ MESA)** | 43M | 7.3G | **84.3** | | | | | | | Mamba2D-B | 94M | - | 82.3 | | VMamba-B | 89M | 15.4G | 83.9 | | **MLLA-B (w/o MESA)** | 96M | 16.2G | **85.0** | | **MLLA-B (w/ MESA)** | 96M | 16.2G | **85.3** | From these results, we observe: - The overfitting prevention strategy MESA only provides ***a modest accuracy gain of 0.1-0.3.*** - Without MESA, MLLA models still ***significantly surpass various SOTA vision Mamba models.*** - ***Downstream tasks using the backbone trained without MESA.*** | Method | Pre-trained Backbone | #Params | FLOPs | $AP^b$ | $AP^m$ | | :------------------: | :------------------: | :-----: | :---: | :----: | :----: | | MLLA-T Mask R-CNN 1x | w/o MESA | 44M | 255G | 46.8 | 42.0 | | MLLA-T Mask R-CNN 1x | w/ MESA | 44M | 255G | 46.8 | 42.1 | | MLLA-T Mask R-CNN 3x | w/o MESA | 44M | 255G | 48.7 | 43.7 | | MLLA-T Mask R-CNN 3x | w/ MESA | 44M | 255G | 48.8 | 43.8 | The results show that ***the inclusion of MESA during pre-training has a negligible effect on downstream task performance.*** - ***We fully appreciate your rigorous research attitude.*** We will include these results and detailed discussions in the revised version. --- **2. Conclusions of the discussion on MESA.** Based on the additional results and our previous discussions, we believe the following conclusions can be made: - ***MESA serves as a strategy to prevent overfitting.*** - ***Without MESA, MLLA models can also achieve comparable results in both classification and downstream tasks.*** This is validated by the additional results. - ***MESA does not affect the three main contributions and findings of this work.*** Our work has three main contributions: revealing the relationship between Mamba and linear attention, analyzing and validating the key difference, and presenting MLLA. The first two contributions do not involve MESA. While the last contribution of our work, MLLA, originally used MESA in its training, additional results verify that MLLA models still significantly surpass various SOTA vision Mamba models without it. This further supports our findings. Therefore, MESA does not influence the three core contributions of our work. - ***We employ MESA to provide the community with more robust models.*** Just like in the early stages of studies on visual Transformer, currently vision Mamba research does not have a well-established and universally accepted training protocol. We additionally employ the overfitting prevention strategy MESA to fully demonstrate MLLA's potential. Our goal is to benefit the community and follow-up works. We will include detailed discussions in the revised version.

Reviewer XBcf2024-08-13

Thank you for providing additional results. The paper now offers both insightful methods and solid experimental results, which have contributed to my improved score.

Reviewer ii6x2024-08-09

Thank you for your response. After reading the response and other reviewers' comments, I believe that my concerns are mostly resolved and I will increase my rating from 4 to 6.

Reviewer dwbt2024-08-12

Thanks to the authors for their clarifications. I will keep my score unchanged.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC