MambaByte: Token-free Selective State Space Model

Junxiong Wang, Tushaar Gangavarapu, Jing Nathan Yan, Alexander M Rush

TL;DR

This paper introduces MambaByte, a novel token-free language model that operates directly on raw bytes, leveraging the Mamba state space model (SSM) architecture. MambaByte achieves competitive language modeling performance, improved robustness to noise, and significantly faster inference compared to previous byte-level models, while also demonstrating strong long-context capabilities.

What Problem Does This Paper Address?

Traditional language models rely on subword tokenization (like BPE or WordPiece) to balance vocabulary size and sequence length. However, these tokenizers can be brittle, failing to handle typos, spelling variations, or morphological changes effectively. Token-free models, which process raw bytes, bypass this issue and offer greater robustness. The main challenge with byte-level modeling is the drastically increased sequence length, which makes standard autoregressive Transformers, with their quadratic attention complexity, computationally prohibitive. While recent advancements like Mamba have introduced efficient SSMs with fixed memory states, adapting them for token-free byte-level modeling and achieving efficient inference remained an open problem.

Methods

The core of MambaByte is the adaptation of the Mamba architecture, a state space model known for its linear time complexity and fixed-size memory state, to process byte sequences directly. Unlike Transformers, Mamba's state is independent of context length, making it well-suited for long byte sequences. The authors also introduce an innovative speculative decoding strategy tailored for MambaByte. This approach uses a smaller, faster subword Mamba model to "draft" potential token sequences, which are then verified and corrected by the larger, token-free MambaByte model. This hybrid approach aims to combine the robustness of token-free models with the generation speed of subword models.

Datasets

The paper evaluates MambaByte on several long-form language modeling datasets:

  • PG19: An extensive collection of full-length English books.
  • Stories: A subset of CommonCrawl used for commonsense reasoning.
  • Books: Another collection of English books.
  • ArXiv: Technical publications in LaTeX.
  • Code: Publicly available open-source code.

For training, they primarily use PG19, sampling 40M consecutive bytes for testing and the rest for training.

Key Insights and Ideas

  • Mamba's suitability for token-free modeling: The fixed-size memory state of Mamba SSMs naturally addresses the sequence length explosion inherent in byte-level processing, a key bottleneck for Transformers.
  • Speculative decoding for byte-level efficiency: Combining a subword "drafter" with a byte-level "verifier" is a clever way to accelerate inference for token-free models, bridging the gap between subword and byte-level generation speeds.
  • Robustness to noise: Token-free models, like MambaByte, inherently demonstrate superior resilience to text corruptions (typos, capitalization changes, etc.) compared to subword models, as they don't rely on discrete token boundaries.
  • Long-context extrapolation: MambaByte shows remarkable ability to generalize to sequences significantly longer than those seen during training, a capability often limited in Transformer models due to positional embeddings.

Key Results

  • Performance: MambaByte consistently outperforms other byte-level models (Transformers, MegaByte, Gated-S4D) across various datasets in terms of bits per byte (BPB). It also achieves competitive results with state-of-the-art subword Transformers.
  • Efficiency: MambaByte is significantly more compute-efficient than MegaByte, achieving similar or better performance with less compute and training data.
  • Inference Speed: The proposed speculative decoding strategy provides a $2.6\times$ speedup for MambaByte inference, bringing its generation speed close to that of subword Mamba models.
  • Robustness: MambaByte exhibits much better resilience to synthetic noise (e.g., character swaps, random case) compared to subword models, with degradation being significantly less pronounced.
  • Long Context: MambaByte can extrapolate to sequences up to $4\times$ longer than its training length without performance degradation, outperforming Transformer and other SSM baselines.

Limitations and Future Work

  • Inference speed gap: While speculative decoding significantly improves MambaByte's inference speed, it still doesn't fully match the speed of optimized subword models in all scenarios. The paper notes a $2.2\times$ speedup for Mamba over MambaByte in some settings.
  • Training data for perplexity: The paper notes that MambaByte-972M's perplexity doesn't improve significantly beyond 150B training bytes, suggesting potential diminishing returns with more data for this specific architecture.
  • Future Work: The authors establish the viability of token-free SSMs for language modeling and suggest that these findings pave the way for future large-scale token-free models. Further exploration into optimizing the speculative decoding strategy and scaling MambaByte to even larger contexts and model sizes are implied.

Summary updated

BibTeX
@inproceedings{wang2024mambabyte,
  author = {Junxiong Wang and Tushaar Gangavarapu and Jing Nathan Yan and Alexander M Rush},
  title = {{MambaByte: Token-free Selective State Space Model}},
  booktitle = {COLM},
  year = {2024},
  url = {https://openreview.net/forum?id=X1xNsuKssb},
}
Figure