TL;DR
This paper introduces Llamba, a family of efficient recurrent language models derived from Llama-3.x using a novel distillation technique. Llamba models achieve competitive performance with significantly less training data and offer much faster inference, making them ideal for resource-constrained environments.
What Problem Does This Paper Address?
Large language models (LLMs) based on the Transformer architecture, while powerful, are computationally expensive due to their quadratic attention mechanism. This limits their scalability and deployment on devices with limited resources like smartphones. While State Space Models (SSMs) like Mamba offer sub-quadratic complexity and better efficiency, they have historically lagged behind Transformers in performance, especially on certain tasks. The challenge is to bridge this gap, creating models that are both efficient and performant, and can be trained with less data.
Methods
The core innovation lies in the Llamba model family and the MOHAWK distillation framework.
- Llamba Architecture: Llamba models are based on the Mamba-2 architecture but are adapted to retain the structure of their Llama teacher models. Key modifications include:
- Alternating MLP blocks: Llamba interleaves Llama's Gated MLP components with Mamba-2 mixing layers, unlike pure Mamba models.
- Multi-head structure: Llamba uses a multi-head variant of Mamba-2, optimized for efficiency without relying on caching mechanisms common in Transformers.
- Non-linearities: Specific non-linear operations are removed to better align with the attention block's behavior.
- Discrete-Mamba-2: A variant that projects the A matrix directly from the input, simplifying the process and improving alignment.
- MOHAWK Distillation: This framework is used to distill knowledge from large Transformer models (Llama-3.x) into the Llamba (SSM-based) architecture. It involves:
- Matrix Orientation: Aligning the SSM mixer with the teacher's attention matrix.
- Hidden-State Alignment: Aligning SSM blocks independently.
- Weight Transfer & Knowledge Distillation: Transferring MLP weights and other components from the teacher, followed by cross-entropy loss distillation.
Datasets
- Training/Distillation:
fineweb-edu-4.0: A curated subset of thefineweb-edudataset, filtered for higher educational quality.
Open-Hermes-2.5: Used for additional distillation epochs.- Evaluation: The paper evaluates models on a suite of standard benchmarks for common sense and language understanding, including:
- ARC Challenge (ARC-C)
- ARC Easy (ARC-E)
- PIQA (Physical Interaction QA)
- Winogrande (WG)
- HellaSwag (HS)
- Lambada (LMB)
- Massive Multitask Language Understanding (MMLU)
- OpenBookQA (OBQA)
Key Insights and Ideas
- Distillation is Key for Efficiency: The MOHAWK framework proves highly effective for transferring knowledge from powerful Transformer models to more efficient SSM architectures, achieving state-of-the-art performance with drastically reduced data requirements.
- SSMs Can Compete with Transformers: Llamba demonstrates that SSM-based models, when properly distilled and architecturally adapted, can achieve performance comparable to their Transformer counterparts.
- On-Device Deployment is Feasible: The efficiency gains of Llamba make it a practical choice for deployment on resource-constrained devices like smartphones, opening up new possibilities for on-device AI.
- Data Curation Matters: While MOHAWK is data-efficient, the quality of the distillation data (e.g.,
fineweb-edu-4.0) significantly impacts performance, particularly on challenging benchmarks like MMLU.
Key Results
- Data Efficiency: Llamba models are distilled using less than 0.1% of the training data typically used for models of similar size. For example, Llamba-8B was distilled using 12 billion tokens, compared to the trillions used for Llama-3.1-8B.
- Performance: Llamba models achieve performance on par with their Transformer teachers across a wide range of benchmarks. For instance, Llamba-8B achieves 80.6% relative MMLU score compared to its teacher.
- Throughput: Llamba-8B demonstrates significantly higher inference throughput than Llama-3.1-8B, especially at larger batch sizes, where Transformers can slow down or run out of memory (OOM). On an NVIDIA H100, Llamba-8B achieved up to 18,508 tokens/sec with a batch size of 2048, while Llama-3.1-8B with a similar context length was OOM.
- On-Device Performance: On an Apple Silicon M3 Pro, Llamba-8B maintains constant high throughput and low memory consumption at 4-bit quantization, while Llama-3.1-8B's performance degrades with increasing context size.
Limitations and Future Work
- MMLU Gap: While Llamba significantly improves MMLU performance compared to prior distilled recurrent models, it still has a gap to close with its teacher model. The paper notes that MMLU takes longer to improve during distillation compared to other benchmarks.
- Future Directions:
- Improving the quality and diversity of distillation datasets.
- Optimizing the handling of long contexts.
- Expanding deployment to real-time, low-power applications (IoT, wearables).
- Further refining the distillation process to unlock new capabilities.
Summary updated