Mamba4Rec: Towards Efficient Sequential Recommendation with Selective State Space Models

Chengkai Liu, Jianghao Lin, Jianling Wang, Hanzhou Liu, James CaverleearXiv 2024

Abstract

Sequential recommendation aims to estimate dynamic user preferences and sequential dependencies among historical user behaviors. Although Transformer-based models have proven effective, they suffer from inference inefficiency due to the quadratic computational complexity of attention operators, particularly for long behavior sequences. Inspired by the recent success of state space models (SSMs), we propose Mamba4Rec, the first work to explore selective SSMs for efficient sequential recommendation. Built upon the basic Mamba block, we design a series of sequential modeling techniques to promote performance while maintaining linear efficiency. Experiments on public datasets demonstrate that Mamba4Rec effectively tackles the effectiveness-efficiency dilemma, outperforming both RNN- and attention-based baselines.

Introduction

Sequential recommendation is a core task in modern information systems, predicting a user's next interaction based on their historical behavior. Currently, Transformer-based models like SASRec and BERT4Rec dominate the field due to their ability to capture complex dependencies via self-attention. However, these models face a significant bottleneck: quadratic computational complexity ($O(L^2)$) relative to sequence length $L$. As user histories grow longer, these models become prohibitively slow and memory-intensive.

In contrast, recurrent models (RNNs) offer linear complexity ($O(L)$) but often struggle with "catastrophic forgetting" in long sequences. Mamba4Rec addresses this gap by leveraging Selective State Space Models (SSMs) to achieve Transformer-level performance with linear-time efficiency.

Mamba4Rec Architecture

The core of Mamba4Rec is the Mamba Block, a selective SSM that introduces a data-dependent mechanism to propagate or forget information. Unlike traditional SSMs that apply static transformations, the selective mechanism allows the model to filter out "noise" in user history and focus on relevant items, matching the qualitative strengths of attention.

Architecture of the Mamba4Rec model, detailing the Mamba Layer and the internal Mamba Block structure.

Key architectural components include:

  • Mamba Layer: The Mamba block is wrapped with a Position-wise Feed-Forward Network (PFFN), Layer Normalization, and Dropout. This structure mimics the proven Transformer architecture while swapping the core attention operator for a more efficient one.
  • Hardware-Aware Design: Mamba utilizes a specialized parallel algorithm that optimizes GPU memory hierarchy (SRAM vs. HBM), making it significantly faster than standard recurrent implementations.
  • Sequential Inductive Bias: Because SSMs process data step-by-step (recurrently), they have an innate sense of time. Ablation studies showed that explicit positional embeddings are largely unnecessary and can even degrade performance, suggesting that the recurrent nature of SSMs is a more natural fit for sequential data.

Experiments and Results

Mamba4Rec was evaluated against state-of-the-art baselines on three public benchmarks: MovieLens-1M (dense, long sequences), Amazon-Beauty (sparse), and Amazon-Video-Games (sparse).

Effectiveness

Mamba4Rec consistently outperformed both RNN-based and attention-based models across all datasets. As shown in the performance table below, on the MovieLens-1M dataset, Mamba4Rec achieved an HR@10 of 0.3121, surpassing SASRec (0.2977) and the linear-recurrent baseline LRURec (0.3057).

Performance comparison of Mamba4Rec against various baselines across three public datasets.

Efficiency

The model successfully breaks the efficiency-effectiveness trade-off. On the MovieLens-1M dataset:

  • Memory Usage: Mamba4Rec used only 5.01GB of GPU memory, a ~3x reduction compared to SASRec (14.98GB).
  • Speed: Training was ~2.3x faster than SASRec (56.13s vs 131.24s), and inference was ~2.5x faster (0.11s vs 0.27s). Compared to BERT4Rec, inference speed improved by approximately 8x.

Conclusion

Mamba4Rec demonstrates that selective State Space Models are a powerful alternative to Transformers for sequential recommendation. By achieving linear scaling without sacrificing the ability to capture complex dependencies, Mamba4Rec provides a scalable solution for processing long user behavior sequences. The code is available at https://github.com/chengkai-liu/Mamba4Rec.

Summary updated

BibTeX
@misc{liu2024mamba,
  author = {Chengkai Liu and Jianghao Lin and Jianling Wang and Hanzhou Liu and James Caverlee},
  title = {{Mamba4Rec: Towards Efficient Sequential Recommendation with Selective State Space Models}},
  year = {2024},
  eprint = {2403.03900},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.03900},
}
Figure