search
HomeTechnology peripheralsAIChanging the initialization method of LoRA, Peking University's new method PiSSA significantly improves the fine-tuning effect

As the number of parameters of large models increases, the cost of fine-tuning the entire model gradually becomes unacceptable.

Therefore, the Peking University research team proposed an efficient parameter fine-tuning method called PiSSA, which exceeds the fine-tuning effect of the currently widely used LoRA on mainstream data sets.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

  • Paper: PiSSA: Principal Singular Values ​​and Singular Vectors Adaptation of Large Language Models

  • Paper link : https://arxiv.org/pdf/2404.02948.pdf

  • Code link: https://github.com/GraphPKU/PiSSA

Figure 1 shows that PiSSA (Figure 1c) is completely consistent with LoRA [1] in terms of model architecture (Figure 1b), but the way to initialize the Adapter is different. LoRA initializes A with Gaussian noise and B with 0s. PiSSA uses Principal Singular values ​​and Singular vectors to initialize the Adapter to initialize A and B.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

Figure 1 shows full parameter fine-tuning, LoRA and PiSSA from left to right. Blue represents frozen parameters, orange represents trainable parameters and other initialization methods. Compared with full-parameter fine-tuning, both LoRA and PiSSA significantly reduce the number of trainable parameters. For the same input, the initial outputs of these three methods are exactly equal. However, PiSSA freezes the secondary part of the model and directly fine-tunes the main part (the first r singular values ​​and singular vectors); while LoRA can be regarded as freezing the main part of the model and fine-tuning the noise part.

Compare the fine-tuning effects of PiSSA and LoRA on different tasks

The research team used llama 2-7B, Mistral-7B and Gemma- 7B serves as the base model, with fine-tuning to enhance their math, coding, and conversational capabilities. These include: training on MetaMathQA, verifying the mathematical ability of the model on the GSM8K and MATH data sets; training on CodeFeedBack, verifying the code ability of the model on the HumanEval and MBPP data sets; training on WizardLM-Evol-Instruct, and using MT -Verify the conversational capabilities of the model on Bench. As can be seen from the experimental results in the table below, using the same scale of trainable parameters, the fine-tuning effect of PiSSA significantly surpasses LoRA, and even surpasses full-parameter fine-tuning.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

Comparing the effects of PiSSA and LoRA fine-tuning under different amounts of trainable parameters

The research team tested the model on mathematical tasks Conduct ablation experiments on the relationship between the amount of trainable parameters and effects. From Figure 2.1, it can be found that in the early stage of training, the training loss of PiSSA decreases very quickly, while LoRA has a stage where it does not decrease or even increases slightly. In addition, PiSSA's training loss is lower than LoRA throughout, indicating that it fits the training set better. From Figures 2.2, 2.3, and 2.4, we can see that under each setting, PiSSA's loss is always lower than LoRA, and its accuracy is always higher than LoRA. High, PiSSA can catch up with the effect of full parameter fine-tuning using fewer trainable parameters.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

Figure 2.1) The loss of PiSSA and LoRA during the training process when the rank is 1. The upper right corner of each figure is the enlarged curve of the first 100 iterations. Among them, PiSSA is represented by the orange line, LoRA is represented by the blue line, and the full-parameter fine-tuning uses the green line to show the final loss as a reference. The phenomenon when the rank is [2,4,8,16,32,64,128] is consistent with this. See the appendix of the article for details.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

#                                                                                                                                                                                        ​and LoRA’s final training loss.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

#                                                                                                                                                                                                                                    and the accuracy of the LoRA fine-tuned model on GSM8K.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

#                                                                                                                                                                                                                                and the accuracy of the LoRA fine-tuned model on MATH.

Detailed explanation of PiSSA method

Inspired by Intrinsic SAID [2] "Pre-trained large model parameters have low rank", PiSSA performs singular value decomposition on the parameter matrix Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect of the pre-trained model, where the first r singular values ​​and singular vectors are used Initialize the two matrices Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect and Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect of the adapter, Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect; the remaining singular values ​​and singular vectors are used to construct the residual matrix Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect, such that Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect. Therefore, the parameters in the adapter contain the core parameters of the model, while the parameters in the residual matrix are correction parameters. By fine-tuning the core adapters A and B with smaller parameters and freezing the residual matrix Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect with larger parameters, the effect of approximating full-parameter fine-tuning with very few parameters is achieved.

Although similarly inspired by Intrinsic SAID [1], the principles behind PiSSA and LoRA are completely different.

LoRA believes that the change of the matrix △W before and after fine-tuning of the large model has a very low intrinsic rank r, so the low-rank matrix obtained by multiplying Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect and Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect is used to simulate the change of the model △W. In the initial stage, LoRA uses Gaussian noise to initialize A and 0 to initialize B, so Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect to ensure that the initial capability of the model does not change, and fine-tune A and B to update W. In contrast, PiSSA does not care about △W, but considers W to have a very low intrinsic rank r. Therefore, we directly perform singular value decomposition on W and decompose it into principal components A, B, and residual term Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect, so that Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect. Assume that the singular value decomposition of W is Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect, A and B are initialized using the r singular values ​​and singular vectors with the largest singular values ​​after SVD decomposition:

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

residual matrix Use the remaining singular values ​​and singular vectors for initialization:

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

PiSSA directly fine-tunes the low-rank principal components A and B of W and freezes the minor correction terms. Compared with LoRA, which uses Gaussian noise and 0 to initialize adapter parameters and freeze core model parameters, PiSSA converges faster and has better results.

PiSSA is pronounced like "pizza"---If the entire large model is compared to a complete pizza, PiSSA cuts off one corner, and it is the corner with the richest fillings (the main singular value, singular vectors), re-baked (fine-tuned on downstream tasks) into preferred flavors.

Since PiSSA adopts the exact same architecture as LoRA, it can be used as an optional initialization method for LoRA and can be easily modified and called in the peft package (as shown in the following code). The same architecture also allows PiSSA to inherit most of the advantages of LoRA, such as: using 4-bit quantization [3] for the residual model to reduce training overhead; after fine-tuning is completed, the adapter can be merged into the residual model without changing the model architecture of the inference process. ; There is no need to share complete model parameters, only the PiSSA module with a small number of parameters needs to be shared. Users can automatically perform singular value decomposition and assignment by directly loading the PiSSA module; a model can use multiple PiSSA modules at the same time, etc. Some improvements to the LoRA method can also be combined with PiSSA: for example, instead of fixing the rank of each layer, finding the best rank through learning [4]; using PiSSA-guided updates [5] to break through the rank limit, etc.

# 在 peft 包中 LoRA 的初始化方式后面增加了一种 PiSSA 初始化选项:if use_lora:nn.init.normal_(self.lora_A.weight, std=1 /self.r)nn.init.zeros_(self.lora_B.weight) elif use_pissa:Ur, Sr, Vr = svd_lowrank (self.base_layer.weight, self.r, niter=4) # 注意:由于 self.base_layer.weight 的维度是 (out_channel,in_channel, 所以 AB 的顺序相比图示颠倒了一下)self.lora_A.weight = torch.diag (torch.sqrt (Sr)) @ Vh.t ()self.lora_B.weight = Ur @ torch.diag (torch.sqrt (Sr))   self.base_layer.weight = self.base_layer.weight - self.lora_B.weight @ self.lora_A.weight

Comparative experiment on fine-tuning effects of high, medium and low singular values

In order to verify the impact of using different sizes of singular values ​​and singular vectors to initialize the adapter on the model, The researchers used high, medium, and low singular values ​​to initialize the adapters of LLaMA 2-7B, Mistral-7B-v0.1, and Gemma-7B respectively, and then fine-tuned them on the MetaMathQA data set. The experimental results are shown in Figure 3. As can be seen from the figure, the method using primary singular value initialization has the smallest training loss and has higher accuracy on the GSM8K and MATH validation sets. This phenomenon verifies the effectiveness of fine-tuning the main singular values ​​and singular vectors.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

Figure 3) From left to right are the training loss, the accuracy on GSM8K, and the accuracy on MATH. Blue represents the largest singular value, orange represents the medium singular value, and green represents the smallest singular value.

Fast Singular Value Decomposition

PiSSA inherits the advantages of LoRA, is easy to use, and has better effects than LoRA. The price is that during the initialization phase, the model needs to be singular value decomposed. Although it only needs to be decomposed once during initialization, it may still require several minutes or even tens of minutes of overhead. Therefore, the researchers used a fast singular value decomposition [6] method to replace the standard SVD decomposition. As can be seen from the experiments in the table below, it only takes a few seconds to approximate the training set fitting effect of the standard SVD decomposition. . Niter represents the number of iterations. The larger the Niter, the longer the time but the smaller the error. Niter = ∞ represents standard SVD. The average error in the table represents the average L_1 distance between A and B obtained by fast singular value decomposition and standard SVD.

Changing the initialization method of LoRA, Peking Universitys new method PiSSA significantly improves the fine-tuning effect

Summary and Outlook

This work performs singular value decomposition on the weights of the pre-trained model, by decomposing the most important parameters Used to initialize an adapter named PiSSA and fine-tune this adapter to approximate the effect of fine-tuning the complete model. Experiments show that PiSSA converges faster than LoRA and has better final results. The only cost is the SVD initialization process that takes several seconds.

So, for better training results, are you willing to spend a few more seconds and change the initialization of LoRA to PiSSA with one click?

References

[1] LoRA: Low-Rank Adaptation of Large Language Models

[2] Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning

##[3] QLoRA: Efficient Finetuning of Quantized LLMs

[4] AdaLoRA: Adaptive Budget Allocation for Parameter-Efficient Fine-Tuning

[5] Delta-LoRA: Fine-Tuning High-Rank Parameters with the Delta of Low-Rank Matrices

##[6] Finding structure with randomness: Probabilistic algorithms for constructing approximate matrix decompositions

The above is the detailed content of Changing the initialization method of LoRA, Peking University's new method PiSSA significantly improves the fine-tuning effect. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:机器之心. If there is any infringement, please contact admin@php.cn delete
4090生成器:与A100平台相比,token生成速度仅低于18%,上交推理引擎赢得热议4090生成器:与A100平台相比,token生成速度仅低于18%,上交推理引擎赢得热议Dec 21, 2023 pm 03:25 PM

PowerInfer提高了在消费级硬件上运行AI的效率上海交大团队最新推出了超强CPU/GPULLM高速推理引擎PowerInfer。PowerInfer和llama.cpp都在相同的硬件上运行,并充分利用了RTX4090上的VRAM。这个推理引擎速度有多快?在单个NVIDIARTX4090GPU上运行LLM,PowerInfer的平均token生成速率为13.20tokens/s,峰值为29.08tokens/s,仅比顶级服务器A100GPU低18%,可适用于各种LLM。PowerInfer与

思维链CoT进化成思维图GoT,比思维树更优秀的提示工程技术诞生了思维链CoT进化成思维图GoT,比思维树更优秀的提示工程技术诞生了Sep 05, 2023 pm 05:53 PM

要让大型语言模型(LLM)充分发挥其能力,有效的prompt设计方案是必不可少的,为此甚至出现了promptengineering(提示工程)这一新兴领域。在各种prompt设计方案中,思维链(CoT)凭借其强大的推理能力吸引了许多研究者和用户的眼球,基于其改进的CoT-SC以及更进一步的思维树(ToT)也收获了大量关注。近日,苏黎世联邦理工学院、Cledar和华沙理工大学的一个研究团队提出了更进一步的想法:思维图(GoT)。让思维从链到树到图,为LLM构建推理过程的能力不断得到提升,研究者也通

FATE 2.0发布:实现异构联邦学习系统互联FATE 2.0发布:实现异构联邦学习系统互联Jan 16, 2024 am 11:48 AM

FATE2.0全面升级,推动隐私计算联邦学习规模化应用FATE开源平台宣布发布FATE2.0版本,作为全球领先的联邦学习工业级开源框架。此次更新实现了联邦异构系统之间的互联互通,持续增强了隐私计算平台的互联互通能力。这一进展进一步推动了联邦学习与隐私计算规模化应用的发展。FATE2.0以全面互通为设计理念,采用开源方式对应用层、调度、通信、异构计算(算法)四个层面进行改造,实现了系统与系统、系统与算法、算法与算法之间异构互通的能力。FATE2.0的设计兼容了北京金融科技产业联盟的《金融业隐私计算

复旦NLP团队发布80页大模型Agent综述,一文纵览AI智能体的现状与未来复旦NLP团队发布80页大模型Agent综述,一文纵览AI智能体的现状与未来Sep 23, 2023 am 09:01 AM

近期,复旦大学自然语言处理团队(FudanNLP)推出LLM-basedAgents综述论文,全文长达86页,共有600余篇参考文献!作者们从AIAgent的历史出发,全面梳理了基于大型语言模型的智能代理现状,包括:LLM-basedAgent的背景、构成、应用场景、以及备受关注的代理社会。同时,作者们探讨了Agent相关的前瞻开放问题,对于相关领域的未来发展趋势具有重要价值。论文链接:https://arxiv.org/pdf/2309.07864.pdfLLM-basedAgent论文列表:

吞吐量提升5倍,联合设计后端系统和前端语言的LLM接口来了吞吐量提升5倍,联合设计后端系统和前端语言的LLM接口来了Mar 01, 2024 pm 10:55 PM

大型语言模型(LLM)被广泛应用于需要多个链式生成调用、高级提示技术、控制流以及与外部环境交互的复杂任务。尽管如此,目前用于编程和执行这些应用程序的高效系统却存在明显的不足之处。研究人员最近提出了一种新的结构化生成语言(StructuredGenerationLanguage),称为SGLang,旨在改进与LLM的交互性。通过整合后端运行时系统和前端语言的设计,SGLang使得LLM的性能更高、更易控制。这项研究也获得了机器学习领域的知名学者、CMU助理教授陈天奇的转发。总的来说,SGLang的

大模型也有小偷?为保护你的参数,上交大给大模型制作「人类可读指纹」大模型也有小偷?为保护你的参数,上交大给大模型制作「人类可读指纹」Feb 02, 2024 pm 09:33 PM

将不同的基模型象征为不同品种的狗,其中相同的「狗形指纹」表明它们源自同一个基模型。大模型的预训练需要耗费大量的计算资源和数据,因此预训练模型的参数成为各大机构重点保护的核心竞争力和资产。然而,与传统软件知识产权保护不同,对预训练模型参数盗用的判断存在以下两个新问题:1)预训练模型的参数,尤其是千亿级别模型的参数,通常不会开源。预训练模型的输出和参数会受到后续处理步骤(如SFT、RLHF、continuepretraining等)的影响,这使得判断一个模型是否基于另一个现有模型微调得来变得困难。无

220亿晶体管,IBM机器学习专用处理器NorthPole,能效25倍提升220亿晶体管,IBM机器学习专用处理器NorthPole,能效25倍提升Oct 23, 2023 pm 03:13 PM

IBM再度发力。随着AI系统的飞速发展,其能源需求也在不断增加。训练新系统需要大量的数据集和处理器时间,因此能耗极高。在某些情况下,执行一些训练好的系统,智能手机就能轻松胜任。但是,执行的次数太多,能耗也会增加。幸运的是,有很多方法可以降低后者的能耗。IBM和英特尔已经试验过模仿实际神经元行为设计的处理器。IBM还测试了在相变存储器中执行神经网络计算,以避免重复访问RAM。现在,IBM又推出了另一种方法。该公司的新型NorthPole处理器综合了上述方法的一些理念,并将其与一种非常精简的计算运行

14秒就能重建视频,还能变换角色,Meta让视频合成提速44倍14秒就能重建视频,还能变换角色,Meta让视频合成提速44倍Dec 27, 2023 pm 06:35 PM

Meta的视频合成新框架给我们带来了一些惊喜就今天的人工智能发展水平来说,文生图、图生视频、图像/视频风格迁移都已经不算什么难事。生成式AI天赋异禀,能够毫不费力地创建或修改内容。尤其是图像编辑,在以十亿规模数据集为基础预训练的文本到图像扩散模型的推动下,经历了重大发展。这股浪潮催生了大量图像编辑和内容创建应用。基于图像的生成模型所取得的成就基础上,下一个挑战的领域必然是为其增加「时间维度」,从而实现轻松而富有创意的视频编辑。一种直接策略是使用图像模型逐帧处理视频,然而,生成式图像编辑本身就具有

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool