Home Technology peripherals AI New work from the author of Mamba: Distilling Llama3 into a hybrid linear RNN

New work from the author of Mamba: Distilling Llama3 into a hybrid linear RNN

Sep 02, 2024 pm 01:41 PM
project

The key to Transformer’s great success in the field of deep learning is the attention mechanism. The attention mechanism allows Transformer-based models to focus on parts relevant to the input sequence, achieving better context understanding. However, the disadvantage of the attention mechanism is that the computational overhead is high, which increases quadratically with the input size, making it difficult for the Transformer to handle very long texts.

Some time ago, the emergence of Mamba broke this situation, which can achieve linear expansion as the context length increases. With the release of Mamba, these state space models (SSMs) can already match or even surpass Transformer at small to medium scale, while maintaining linear scalability with sequence length, which gives Mamba favorable deployment characteristics.

Simply put, Mamba first introduces a simple but effective selection mechanism, which can re-parameterize SSM according to the input, allowing the model to retain necessary information indefinitely while filtering out irrelevant information. and related data.

Recently, a paper titled "The Mamba in the Llama: Distilling and Accelerating Hybrid Models" proves that by reusing the weights of the attention layer, large transformers can be distilled into large hybrid linear RNNs, just Minimal extra computation while retaining most of its build quality.

The resulting hybrid model, which contains a quarter of the attention layer, achieves comparable performance to the original Transformer in the chat benchmark, and outperforms using data in the chat benchmark and general benchmarks. An open source hybrid Mamba model trained from scratch by trillion tokens. Additionally, the study proposes a hardware-aware speculative decoding algorithm that speeds up inference for Mamba and hybrid models.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Paper address: https://arxiv.org/pdf/2408.15237

The best performing model of this study is from Llama3-8B-Instruct Distilled, it achieved a length-controlled winning rate of 29.61 on AlpacaEval 2 relative to GPT-4, and a winning rate of 7.35 on MT-Bench, surpassing the best instruction-adjusted linear RNN model.

Methods

Knowledge Distillation (KD) is a model compression technique used to transfer knowledge from a large model (teacher model) to a smaller model (student model) model), which aims to train the student network to imitate the behavior of the teacher network. The research aims to distill the Transformer so that its performance is comparable to the original language model.

This study proposes a multi-stage distillation method that combines progressive distillation, supervised fine-tuning and directional preference optimization. Compared with ordinary distillation, this method can achieve better perplexity and downstream evaluation results.

The study assumes that most of the knowledge from the Transformer is retained in the MLP layer transferred from the original model, and focuses on the fine-tuning and alignment steps of the distilled LLM. During this phase, the MLP layer remains frozen and the Mamba layer is trained.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

This study believes that there are some natural connections between linear RNN and attention mechanism. The attention formula can be linearized by removing softmax:

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

But linearizing attention will lead to degradation of model capabilities. To design an efficient distilled linear RNN, this study approaches the original Transformer parameterization as closely as possible while extending the capacity of the linear RNN in an efficient manner. This study does not attempt to have the new model capture the precise original attention function, but instead uses a linearized form as a starting point for distillation.

As shown in Algorithm 1, this study feeds the standard Q, K, V heads from the attention mechanism directly into the Mamba discretization and then applies the resulting linear RNN. This can be thought of as using linear attention for coarse initialization and allows the model to learn richer interactions through extended hidden states.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

This study directly replaces the Transformer attention head with a fine-tuned linear RNN layer, keeping the Transformer MLP layer unchanged and not training them. This approach also needs to handle other components, such as grouped query attention that shares keys and values ​​across heads. The research team noted that this architecture, unlike those used in many Mamba systems, allows this initialization to replace any attention blocks with linear RNN blocks.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

The research also proposes a new algorithm for linear RNN speculative decoding using hardware-aware multi-step generation.

Algorithm 2 and Figure 2 show the complete algorithm. This approach only keeps an RNN hidden state in the cache for verification and lazily advances it based on the success of the multi-step kernel. Since the distillation model contains transformer layers, this study also extends speculative decoding to an Attention/RNN hybrid architecture. In this setup, the RNN layer performs verification according to Algorithm 2, while the Transformer layer only performs parallel verification.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

To verify the effectiveness of this method, the study used Mamba 7B and Mamba 2.8B as target models for speculation. The results are shown in Table 1.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Figure 3 shows the performance characteristics of the multi-step kernel itself.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Acceleration on H100 GPU. The algorithm proposed in this study shows strong performance on Ampere GPU, as shown in Table 1 above. But there are huge challenges on the H100 GPU. This is mainly because GEMM operations are too fast, which makes the overhead caused by caching and recomputing operations more noticeable. Indeed, a simple implementation of the studied algorithm (using multiple different kernel calls) achieved considerable speedup on the 3090 GPU, but no speedup at all on the H100.

Experiments and results

This study uses two LLM chat models for experiments: Zephyr-7B is fine-tuned based on the Mistral 7B model, and Llama- 3 Instruct 8B. For the linear RNN model, this study uses a hybrid version of Mamba and Mamba2 with attention layers of 50%, 25%, 12.5%, and 0% respectively, and calls 0% a pure Mamba model. Mamba2 is an architecture variant of Mamba designed primarily for recent GPU architectures.

Evaluation on the Chat Benchmark

Table 2 shows the performance of the model on the Chat Benchmark. The main model compared is the large Transformer model. The results show:

The distilled hybrid Mamba model (50%) achieves similar scores to the teacher model in the MT benchmark, and is slightly better than the teacher model in the AlpacaEval benchmark in terms of LC win rate and overall win rate. .

The performance of the distilled hybrid Mamba (25% and 12.5%) is slightly worse than the teacher model on the MT benchmark, but even with more parameters in AlpcaaEval it still outperforms some large Transformers.

The accuracy of the distilled pure (0%) Mamba model does drop significantly.

It is worth noting that the distilled hybrid model performs better than Falcon Mamba, which is trained from scratch using more than 5T tokens.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

General benchmark evaluation

Zero-sample evaluation. Table 3 shows the zero-shot performance of Mamba and Mamba2 distilled from different teacher models on the LM Eval benchmark. The hybrid Mamba-Llama3 and Mamba2-Llama3 models distilled from Llama-3 Instruct 8B performed better compared to the open source TRI Mamba and Nvidia Mamba models trained from scratch.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Benchmark evaluation. Table 4 shows that the performance of the distilled hybrid model matches the best open source linear RNN model on Open LLM Leaderboard, while outperforming the corresponding open source instruction model in GSM8K and CRUX.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Hybrid Speculative Decoding

For the 50% and 25% distillation models, compared to the non-speculative baseline, this study Achieved over 1.8x speedup on Zephyr-Hybrid.

Experiments also show that the 4-layer draft model trained in this study achieves a higher reception rate, but due to the increase in the size of the draft model, the additional overhead also becomes larger. In subsequent work, this research will focus on scaling down these draft models.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Comparison with other distillation methods: Table 6 (left) compares the perplexity of different model variants. The study performed distillation within an epoch using Ultrachat as a seed prompt and compared perplexity. It turns out that removing more layers makes the situation worse. The study also compared the distillation method to previous baselines and found that the new method showed smaller degradation, while the Distill Hyena model was trained on the WikiText dataset using a much smaller model and showed larger confusion degree of degradation.

Table 6 (right) shows that using SFT or DPO alone does not yield much improvement, while using SFT + DPO yields the best score.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Table 7 compares ablation studies for several different models. Table 7 (left) shows the distillation results using various initializations, and Table 7 (right) shows the smaller gains from progressive distillation and interleaving attention layers with Mamba.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Table 8 compares the performance of hybrid models using two different initialization methods: the results confirm that the initialization of attention weights is crucial.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Table 9 compares the performance of models with and without Mamba blocks. Models with Mamba blocks perform significantly better than models without Mamba blocks. This confirms that adding the Mamba layer is crucial and that the performance improvement is not solely due to the remaining attention mechanism.

Mamba作者新作:将Llama3蒸馏成混合线性 RNN

Interested readers can read the original text of the paper to learn more about the research content.

The above is the detailed content of New work from the author of Mamba: Distilling Llama3 into a hybrid linear RNN. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The author of ControlNet has another hit! The whole process of generating a painting from a picture, earning 1.4k stars in two days The author of ControlNet has another hit! The whole process of generating a painting from a picture, earning 1.4k stars in two days Jul 17, 2024 am 01:56 AM

It is also a Tusheng video, but PaintsUndo has taken a different route. ControlNet author LvminZhang started to live again! This time I aim at the field of painting. The new project PaintsUndo has received 1.4kstar (still rising crazily) not long after it was launched. Project address: https://github.com/lllyasviel/Paints-UNDO Through this project, the user inputs a static image, and PaintsUndo can automatically help you generate a video of the entire painting process, from line draft to finished product. follow. During the drawing process, the line changes are amazing. The final video result is very similar to the original image: Let’s take a look at a complete drawing.

Topping the list of open source AI software engineers, UIUC's agent-less solution easily solves SWE-bench real programming problems Topping the list of open source AI software engineers, UIUC's agent-less solution easily solves SWE-bench real programming problems Jul 17, 2024 pm 10:02 PM

The AIxiv column is a column where this site publishes academic and technical content. In the past few years, the AIxiv column of this site has received more than 2,000 reports, covering top laboratories from major universities and companies around the world, effectively promoting academic exchanges and dissemination. If you have excellent work that you want to share, please feel free to contribute or contact us for reporting. Submission email: liyazhou@jiqizhixin.com; zhaoyunfeng@jiqizhixin.com The authors of this paper are all from the team of teacher Zhang Lingming at the University of Illinois at Urbana-Champaign (UIUC), including: Steven Code repair; Deng Yinlin, fourth-year doctoral student, researcher

From RLHF to DPO to TDPO, large model alignment algorithms are already 'token-level' From RLHF to DPO to TDPO, large model alignment algorithms are already 'token-level' Jun 24, 2024 pm 03:04 PM

The AIxiv column is a column where this site publishes academic and technical content. In the past few years, the AIxiv column of this site has received more than 2,000 reports, covering top laboratories from major universities and companies around the world, effectively promoting academic exchanges and dissemination. If you have excellent work that you want to share, please feel free to contribute or contact us for reporting. Submission email: liyazhou@jiqizhixin.com; zhaoyunfeng@jiqizhixin.com In the development process of artificial intelligence, the control and guidance of large language models (LLM) has always been one of the core challenges, aiming to ensure that these models are both powerful and safe serve human society. Early efforts focused on reinforcement learning methods through human feedback (RL

Posthumous work of the OpenAI Super Alignment Team: Two large models play a game, and the output becomes more understandable Posthumous work of the OpenAI Super Alignment Team: Two large models play a game, and the output becomes more understandable Jul 19, 2024 am 01:29 AM

If the answer given by the AI ​​model is incomprehensible at all, would you dare to use it? As machine learning systems are used in more important areas, it becomes increasingly important to demonstrate why we can trust their output, and when not to trust them. One possible way to gain trust in the output of a complex system is to require the system to produce an interpretation of its output that is readable to a human or another trusted system, that is, fully understandable to the point that any possible errors can be found. For example, to build trust in the judicial system, we require courts to provide clear and readable written opinions that explain and support their decisions. For large language models, we can also adopt a similar approach. However, when taking this approach, ensure that the language model generates

A significant breakthrough in the Riemann Hypothesis! Tao Zhexuan strongly recommends new papers from MIT and Oxford, and the 37-year-old Fields Medal winner participated A significant breakthrough in the Riemann Hypothesis! Tao Zhexuan strongly recommends new papers from MIT and Oxford, and the 37-year-old Fields Medal winner participated Aug 05, 2024 pm 03:32 PM

Recently, the Riemann Hypothesis, known as one of the seven major problems of the millennium, has achieved a new breakthrough. The Riemann Hypothesis is a very important unsolved problem in mathematics, related to the precise properties of the distribution of prime numbers (primes are those numbers that are only divisible by 1 and themselves, and they play a fundamental role in number theory). In today's mathematical literature, there are more than a thousand mathematical propositions based on the establishment of the Riemann Hypothesis (or its generalized form). In other words, once the Riemann Hypothesis and its generalized form are proven, these more than a thousand propositions will be established as theorems, which will have a profound impact on the field of mathematics; and if the Riemann Hypothesis is proven wrong, then among these propositions part of it will also lose its effectiveness. New breakthrough comes from MIT mathematics professor Larry Guth and Oxford University

arXiv papers can be posted as 'barrage', Stanford alphaXiv discussion platform is online, LeCun likes it arXiv papers can be posted as 'barrage', Stanford alphaXiv discussion platform is online, LeCun likes it Aug 01, 2024 pm 05:18 PM

cheers! What is it like when a paper discussion is down to words? Recently, students at Stanford University created alphaXiv, an open discussion forum for arXiv papers that allows questions and comments to be posted directly on any arXiv paper. Website link: https://alphaxiv.org/ In fact, there is no need to visit this website specifically. Just change arXiv in any URL to alphaXiv to directly open the corresponding paper on the alphaXiv forum: you can accurately locate the paragraphs in the paper, Sentence: In the discussion area on the right, users can post questions to ask the author about the ideas and details of the paper. For example, they can also comment on the content of the paper, such as: "Given to

The first Mamba-based MLLM is here! Model weights, training code, etc. have all been open source The first Mamba-based MLLM is here! Model weights, training code, etc. have all been open source Jul 17, 2024 am 02:46 AM

The AIxiv column is a column where this site publishes academic and technical content. In the past few years, the AIxiv column of this site has received more than 2,000 reports, covering top laboratories from major universities and companies around the world, effectively promoting academic exchanges and dissemination. If you have excellent work that you want to share, please feel free to contribute or contact us for reporting. Submission email: liyazhou@jiqizhixin.com; zhaoyunfeng@jiqizhixin.com. Introduction In recent years, the application of multimodal large language models (MLLM) in various fields has achieved remarkable success. However, as the basic model for many downstream tasks, current MLLM consists of the well-known Transformer network, which

Axiomatic training allows LLM to learn causal reasoning: the 67 million parameter model is comparable to the trillion parameter level GPT-4 Axiomatic training allows LLM to learn causal reasoning: the 67 million parameter model is comparable to the trillion parameter level GPT-4 Jul 17, 2024 am 10:14 AM

Show the causal chain to LLM and it learns the axioms. AI is already helping mathematicians and scientists conduct research. For example, the famous mathematician Terence Tao has repeatedly shared his research and exploration experience with the help of AI tools such as GPT. For AI to compete in these fields, strong and reliable causal reasoning capabilities are essential. The research to be introduced in this article found that a Transformer model trained on the demonstration of the causal transitivity axiom on small graphs can generalize to the transitive axiom on large graphs. In other words, if the Transformer learns to perform simple causal reasoning, it may be used for more complex causal reasoning. The axiomatic training framework proposed by the team is a new paradigm for learning causal reasoning based on passive data, with only demonstrations

See all articles