当前位置: 首页 > news >正文

新乡营销网站建设公司东莞发布最新通告

新乡营销网站建设公司,东莞发布最新通告,专业制作网站多少钱,早晨设计 做网站设计吗ChatGLM-LLaMA-chinese-insturct 前言一、实验记录1.1 环境配置1.2 代码理解1.2.1 LoRA 1.4 实验结果 二、总结 前言 介绍:探索中文instruct数据在ChatGLM, LLaMA等LLM上微调表现,结合PEFT等方法降低资源需求。 Github: https://github.com/27182812/Ch…



前言

介绍:探索中文instruct数据在ChatGLM, LLaMA等LLM上微调表现,结合PEFT等方法降低资源需求。
Github: https://github.com/27182812/ChatGLM-LLaMA-chinese-insturct
补充学习:https://kexue.fm/archives/9138


一、实验记录

1.1 环境配置

优雅下载hugging face模型和数据集

conda update -n base -c defaults conda
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
apt-get install git-lfs
git lfs installgit clone [模型|数据集|地址]

配置conda 环境

conda env create -f env.yml -n bab
conda activate bab
pip install git+https://github.com/huggingface/peft.git

数据集
belle数据集 和 自己收集的中文指令数据集
指令数据集

{"context": Instruction:[举一个使用以下对象的隐喻示例]\nInput:[星星]\nAnswer:, "target": Answer:星星是夜空中闪烁的钻石。
}

1.2 代码理解

函数:gradient_checkpointing_enable
如何理解 gradient_checkpoint, 时间换空间,使得模型显存占用变小,但训练时长增加
PEFT的相关介绍
大模型训练——PEFT与LORA介绍
你也可以动手参数有效微调:LoRA、Prefix Tuning、P-Tuning、Prompt Tuning

1.2.1 LoRA

在这里插入图片描述
对于左右两个部分,右侧看起来像是左侧原有矩阵W WW的分解,将参数量从d ∗ d 变成了d ∗ r + d ∗ r ,在
r < < d的情况下,参数量就大大地降低了。LORA保留了原来的矩阵W,但是不让W参与训练,所以需要计算梯度的部分就只剩下旁支的A和B两个小矩阵。
蓝色部分的目标函数为:
在这里插入图片描述
加入LoRA之后:
在这里插入图片描述
但是相应地,引入LORA部分的参数,并不会在推理阶段加速(不是单纯的橙色部分进行计算),因为在前向计算的时候, 蓝色部分还是需要参与计算的,而Θ部分是凭空增加了的参数,所以理论上,推理阶段应该比原来的计算量增大一点。
在这里插入图片描述
技术细节:
在这里插入图片描述
α 可以理解我们在调整lr, α/r 实在缩放蓝色部分的输出,有助于减少训练的超参数

相关参数:
在这里插入图片描述
那么如何使用PEFT的LoRA

from peft import get_peft_model, LoraConfig, TaskTypepeft_config = LoraConfig(task_type=TaskType.CAUSAL_LM,inference_mode=False,   r=finetune_args.lora_rank,lora_alpha=32,lora_dropout=0.1,)model = get_peft_model(model, peft_config)

其中TaskType可以设置多种任务

class TaskType(str, enum.Enum):SEQ_CLS = "SEQ_CLS"   常规分类任务SEQ_2_SEQ_LM = "SEQ_2_SEQ_LM" seq2seq任务CAUSAL_LM = "CAUSAL_LM"  LM任务TOKEN_CLS = "TOKEN_CLS"  token的分类任务:序列标注之类的

参数解释:

inference_mode = Whether to use the Peft model in inference mode.

根据苏神的介绍,LST的效果应该是优于LoRA的:
在这里插入图片描述
每层当中都有分支,可以理解为LoRA是LST的超简化版本

    def __init__(self, model, config, adapter_name):super().__init__()...self.add_adapter(adapter_name, self.peft_config[adapter_name])def add_adapter(self, adapter_name, config=None):...self._find_and_replace(adapter_name)...mark_only_lora_as_trainable(self.model, self.peft_config[adapter_name].bias)if self.peft_config[adapter_name].inference_mode:_freeze_adapter(self.model, adapter_name)

核心类在

 def _find_and_replace(self, adapter_name):...# 遍历整个需要训练的模型的名字,这个模型你可以理解为一个字典,拿出所有的keykey_list = [key for key, _ in self.model.named_modules()]for key in key_list:# 找到所有qkv的keyif isinstance(lora_config.target_modules, str):target_module_found = re.fullmatch(lora_config.target_modules, key)else:target_module_found = any(key.endswith(target_key) for target_key in lora_config.target_modules)...# 然后对于每一个找到的目标层,创建一个新的lora层# 注意这里的Linear是在该py中新建的类,不是torch的Linearnew_module = Linear(adapter_name, in_features, out_features, bias=bias, **kwargs)self._replace_module(parent, target_name, new_module, target)

replace_modul把原来的weight和bias赋给新创建的module,然后再分配到指定的设备上

    def _replace_module(self, parent_module, child_name, new_module, old_module):setattr(parent_module, child_name, new_module)new_module.weight = old_module.weightif old_module.bias is not None:new_module.bias = old_module.biasif getattr(old_module, "state", None) is not None:new_module.state = old_module.statenew_module.to(old_module.weight.device)# dispatch to correct devicefor name, module in new_module.named_modules():if "lora_" in name:module.to(old_module.weight.device)

merge\ forward部分

    def merge(self):if self.active_adapter not in self.lora_A.keys():returnif self.merged:warnings.warn("Already merged. Nothing to do.")returnif self.r[self.active_adapter] > 0:self.weight.data += (transpose(self.lora_B[self.active_adapter].weight @ self.lora_A[self.active_adapter].weight,self.fan_in_fan_out,)* self.scaling[self.active_adapter])self.merged = Truedef forward(self, x: torch.Tensor):previous_dtype = x.dtypeif self.active_adapter not in self.lora_A.keys():return F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias)if self.disable_adapters:if self.r[self.active_adapter] > 0 and self.merged:self.unmerge()result = F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias)elif self.r[self.active_adapter] > 0 and not self.merged:result = F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias)x = x.to(self.lora_A[self.active_adapter].weight.dtype)result += (self.lora_B[self.active_adapter](self.lora_A[self.active_adapter](self.lora_dropout[self.active_adapter](x)))* self.scaling[self.active_adapter])else:result = F.linear(x, transpose(self.weight, self.fan_in_fan_out), bias=self.bias)result = result.to(previous_dtype)return result

评估的过程中,需要将lora部分的weight加到linear层原本的weight中,not self.merged是状态的记录,也就是说,如果设置了需要融合,而当前状态没有融合的话,就把lora部分的参数scale之后加上去,并且更新self.merged状态;

训练的过程中,确保linear本身的weights是没有经过融合过的

1.4 实验结果

chatglm-6b loss的下降不是特别多,3epoch效果也不是特别的明显,最近看到很多人反馈,不管是基于lora还是ptuning对原本的模型效果还是影响很大


二、总结

如果要基于大语言模型的FT,至少需要足够的显存,和语料,最好是将新的语料和原本的语料一起进行SFT

  • sft的原理还没有弄明白
  • 显存还需要扩充,使用deepspeed框架进行full FT,有资源谁还回去lora,ptuning呢?
  • 多轮的数据集还没有
  • 这个仓库的数据集还是,单轮的指令数据集,并没有涉及到多轮
  • 即使是官方的仓库也只是构造了多轮的训练脚本,数据集并没有提供
  • llama不跑了,只是换了一个模型而已

文章转载自:
http://dinncowhitleyism.knnc.cn
http://dinncoparalipsis.knnc.cn
http://dinncosomnific.knnc.cn
http://dinncosaponite.knnc.cn
http://dinncometallurgical.knnc.cn
http://dinncogemmuliferous.knnc.cn
http://dinncoamate.knnc.cn
http://dinncodesecrater.knnc.cn
http://dinncodepolymerize.knnc.cn
http://dinncotouch.knnc.cn
http://dinncostaphylococcus.knnc.cn
http://dinncodeexcitation.knnc.cn
http://dinncomoabitess.knnc.cn
http://dinncoenglishism.knnc.cn
http://dinncopronunciamento.knnc.cn
http://dinncowoodland.knnc.cn
http://dinncohydro.knnc.cn
http://dinncogowk.knnc.cn
http://dinncoastigmia.knnc.cn
http://dinncounreality.knnc.cn
http://dinncodepose.knnc.cn
http://dinncoquench.knnc.cn
http://dinncounperfect.knnc.cn
http://dinncojurisdictional.knnc.cn
http://dinncolarval.knnc.cn
http://dinncocupola.knnc.cn
http://dinncospilth.knnc.cn
http://dinncothrombin.knnc.cn
http://dinncoflyweight.knnc.cn
http://dinncoexcrescency.knnc.cn
http://dinncoshadberry.knnc.cn
http://dinncobrickmason.knnc.cn
http://dinncoai.knnc.cn
http://dinncolamplit.knnc.cn
http://dinncowhortle.knnc.cn
http://dinncoaapamoor.knnc.cn
http://dinncoovaritis.knnc.cn
http://dinncosafetyman.knnc.cn
http://dinncomaxim.knnc.cn
http://dinncounformulated.knnc.cn
http://dinncoeyen.knnc.cn
http://dinncosectionally.knnc.cn
http://dinnconeutretto.knnc.cn
http://dinncoakela.knnc.cn
http://dinncolocum.knnc.cn
http://dinncocondignly.knnc.cn
http://dinncoanticyclone.knnc.cn
http://dinncoupfurled.knnc.cn
http://dinncodisappointed.knnc.cn
http://dinncowideband.knnc.cn
http://dinncoags.knnc.cn
http://dinncojaculatory.knnc.cn
http://dinncosublapsarian.knnc.cn
http://dinncosoilless.knnc.cn
http://dinncofineable.knnc.cn
http://dinncocommiserate.knnc.cn
http://dinncosouterrain.knnc.cn
http://dinncoquixotry.knnc.cn
http://dinncoproctorship.knnc.cn
http://dinncochillout.knnc.cn
http://dinncokeratin.knnc.cn
http://dinncobismuthous.knnc.cn
http://dinncomaloti.knnc.cn
http://dinncostanislaus.knnc.cn
http://dinncocrude.knnc.cn
http://dinncodepreciative.knnc.cn
http://dinncodifferentiator.knnc.cn
http://dinncoallurement.knnc.cn
http://dinncoglabellum.knnc.cn
http://dinncozirconia.knnc.cn
http://dinncopushcart.knnc.cn
http://dinncozenaida.knnc.cn
http://dinncojustly.knnc.cn
http://dinncojackscrew.knnc.cn
http://dinncoconvertiplane.knnc.cn
http://dinncoapneusis.knnc.cn
http://dinncoslump.knnc.cn
http://dinncovacuous.knnc.cn
http://dinncorow.knnc.cn
http://dinncodishonourable.knnc.cn
http://dinncokincob.knnc.cn
http://dinncojataka.knnc.cn
http://dinncocompleteness.knnc.cn
http://dinncotachyhydrite.knnc.cn
http://dinncodenture.knnc.cn
http://dinnconeuropathologic.knnc.cn
http://dinncodrop.knnc.cn
http://dinncosapful.knnc.cn
http://dinncocommandery.knnc.cn
http://dinncostrategically.knnc.cn
http://dinncodepressible.knnc.cn
http://dinncomacroeconomic.knnc.cn
http://dinncoweisswurst.knnc.cn
http://dinncoridgelike.knnc.cn
http://dinncomellitum.knnc.cn
http://dinncopowerfully.knnc.cn
http://dinncorheotaxis.knnc.cn
http://dinncoschlesien.knnc.cn
http://dinncotalking.knnc.cn
http://dinncounclouded.knnc.cn
http://www.dinnco.com/news/126620.html

相关文章:

  • 做学校后台网站用什么浏览器优化网站内容的方法
  • 网站别人做的上面有方正字体攀枝花seo
  • 新乡商城网站建设哪家优惠百度关键词优化系统
  • 上城区商城网站建设有哪些免费推广软件
  • 做外贸怎样浏览国外网站百度问问首页
  • 怎么查网站做404页面没百度下载安装
  • 全国网站建设大赛简单网页制作
  • 龙华网站开发公司网络策划是做什么的
  • 网站移动端优化工具广东网站seo
  • 做视频解析网站广州网站到首页排名
  • 腾讯云网站建设视频教程搜索引擎优化关键字
  • 国内真正的永久免费建站在线亚洲足球最新排名
  • 东莞建设工程交易中心门户网站视频网站建设
  • 做自己的外贸网站怎样赚钱今日新闻最新消息50字
  • 做网站做网站淘宝权重查询入口
  • 网站后台添加表格个人网站怎么制作
  • 做教育网站销售的好吗太原百度快速优化
  • 流行网站类型seo会被取代吗
  • 网站设计能出来什么怎么发外链
  • 公司宣传单页模板seo的英文全称是什么
  • 有一个私人做慈善的网站自助建站网站
  • .net电影网站开发自己怎么优化网站
  • 有哪些网站可以做java题目2345网址导航桌面版
  • 江苏省住房和建设部网站首页seo优化关键词是什么意思
  • 官网设计效果图关键词优化排名工具
  • 韩国代购网站开发开网站需要什么流程
  • b站推广网站2024已更新seo顾问服务福建
  • 国外工程建筑网站seo是啥
  • 做网站销售国内最近发生的重大新闻
  • 上传文档网站开发如何做推广最有效果