Papers › The Mamba in the Llama: Distilling and Accelerating Hybrid Models

The Mamba in the Llama: Distilling and Accelerating Hybrid Models

27 Aug 2024arXiv:2408.15237archive 2025-07-28

Junxiong Wang, Daniele Paliotta, Avner May, Alexander M. Rush, Tri Dao

Linear RNN architectures, like Mamba, can be competitive with Transformer models in language modeling while having advantageous deployment characteristics. Given the focus on training large-scale Transformer models, we consider the challenge of converting these pretrained models for deployment. We demonstrate that it is feasible to distill large Transformers into linear RNNs by reusing the linear projection weights from attention layers with academic GPU resources. The resulting hybrid model, which incorporates a quarter of the attention layers, achieves performance comparable to the original Transformer in chat benchmarks and outperforms open-source hybrid Mamba models trained from scratch with trillions of tokens in both chat benchmarks and general benchmarks. Moreover, we introduce a hardware-aware speculative decoding algorithm that accelerates the inference speed of Mamba and hybrid models. Overall we show how, with limited computation resources, we can remove many of the original attention layers and generate from the resulting model more efficiently. Our top-performing model, distilled from Llama3-8B-Instruct, achieves a 29.61 length-controlled win rate on AlpacaEval 2 against GPT-4 and 7.35 on MT-Bench, surpassing the best 8B scale instruction-tuned linear RNN model. We also find that the distilled model has natural length extrapolation, showing almost perfect accuracy in the needle-in-a-haystack test at 20x the distillation length. Code and pre-trained checkpoints are open-sourced at https://github.com/jxiw/MambaInLlama and https://github.com/itsdaniele/speculative_mamba.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2408.15237")

Code

Syntology Ran 5 of 14 code samples harvested from 2 repositories linked to this paper; 9 have no recorded run. Of those that ran: 1 ran · our draft was wrong; 1 ran · fixture could not drive it; 3 ran with no contract checked.

By repository: official repository: 14 samples from 2 repositories, 5 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

itsdaniele/speculative_mamba officialmentioned in papermentioned on GitHubpytorchApache-2.0 report
jxiw/mambainllama officialmentioned in paperpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

14 samples harvested; 5 ran; 0 honoured the contract we drafted; 9 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · our draft was wrong
1ran · fixture could not drive it
3ran
9unverified

Licence: 0 of the 14 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

repeat_kv jxiw/mambainllama/mamba/hybrid_mamba_layer.py official repository ran · fixture could not drive it fingerprinted Apache-2.0 (permissive) · 3c76e52815c5401d · report
construct_layer_dict jxiw/mambainllama/util.py official repository ran Apache-2.0 (permissive) · e845d6cad3dda7eb · report
load_safetensors_to_dict jxiw/mambainllama/util.py official repository ran Apache-2.0 (permissive) · 72afeaae843bd353 · report
sample itsdaniele/speculative_mamba/specmamba/utils/generation.py official repository ran Apache-2.0 (permissive) · 6629f11cee862c38 · report
selective_scan_ref itsdaniele/speculative_mamba/specmamba/ops/selective_scan_interface.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · ba7b868fec181b57 · report
decode itsdaniele/speculative_mamba/specmamba/utils/generation.py official repository unverified Apache-2.0 (permissive) · 57563881caa239a8 · report
initialize_inference_params itsdaniele/speculative_mamba/speculative_mamba/decode_speculative.py official repository unverified Apache-2.0 (permissive) · 3c9b265c08fe3b25 · report
layer_norm_ref itsdaniele/speculative_mamba/specmamba/ops/triton/layernorm.py official repository unverified Apache-2.0 (permissive) · 2ce8fcf5bedd19ec · report
load_config_hf itsdaniele/speculative_mamba/specmamba/utils/hf.py official repository unverified Apache-2.0 (permissive) · 7a8ab4bf37f8fa41 · report
load_state_dict_hf itsdaniele/speculative_mamba/specmamba/utils/hf.py official repository unverified Apache-2.0 (permissive) · 7eb0983c186cde2e · report
modify_logit_for_repetition_penalty itsdaniele/speculative_mamba/specmamba/utils/generation.py official repository unverified Apache-2.0 (permissive) · da95e9a7906f3d52 · report
rms_norm_ref itsdaniele/speculative_mamba/specmamba/ops/triton/layernorm.py official repository unverified Apache-2.0 (permissive) · ab802ae3195c6316 · report
selective_state_update_multi_cached_ref itsdaniele/speculative_mamba/specmamba/ops/triton/selective_state_update_multi_cached_fused.py official repository unverified Apache-2.0 (permissive) · e2788fa7d179ea77 · report
selective_state_update_ref itsdaniele/speculative_mamba/specmamba/ops/triton/selective_state_update.py official repository unverified Apache-2.0 (permissive) · c720b3f33d90d4f4 · report

Tasks

Language ModelingLanguage ModellingMamba

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutFocusGPT-4Label SmoothingLayer NormalizationLinear LayerMambaMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSPEEDSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections