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

乐清英文网站建设淘宝指数转换

乐清英文网站建设,淘宝指数转换,python做简单的网站,个人博客搭建wordpress本节课程的视频和教程都相当清晰,尤其是教程,基本只要跟着文档,在开发机上把指令都相同地输出一遍,就可以完成任务(大赞),相当顺利。因此,这里的笔记就不重复赘述步骤,更…

本节课程的视频和教程都相当清晰,尤其是教程,基本只要跟着文档,在开发机上把指令都相同地输出一遍,就可以完成任务(大赞),相当顺利。因此,这里的笔记就不重复赘述步骤,更多侧重于将教程的知识进行思考和解读

1. 环境配置与数据准备

首先创建conda环境,然后安装XTuner。

同时了解一下关于 微调 的前置知识,建议阅读XTuner微调前置基础,XTuner 文档链接:XTuner-doc-cn。

摘取一部分:

微调(fine-tuning)是一种基于预训练模型,通过少量的调整(fine-tune)来适应新的任务或数据的方法。

微调是在预训练模型的基础上,将模型中一些层的权重参数进行微调,以适应新的数据集或任务。

在大模型的下游应用中,经常会用到两种微调模式:增量预训练 和 指令跟随 。

LoRA(Low-Rank Adaptation)是一种使用低精度权重对大型预训练语言模型进行微调的技术,它的核心思想是在不改变原有模型权重的情况下,通过添加少量新参数来进行微调。这种方法降低了模型的存储需求,也降低了计算成本,实现了对大模型的快速适应,同时保持了模型性能。

QLoRA(Quantized LoRA)微调技术是对LoRA的一种改进,它通过引入高精度权重和可学习的低秩适配器来提高模型的准确性。并且在LoRA的基础上,引入了量化技术。通过将预训练模型量化为int4格式,可以进一步减少微调过程中的计算量,同时也可以减少模型的存储空间,这对于在资源有限的设备上运行模型非常有用。

XTuner 一个大语言模型&多模态模型微调工具箱。 MMRazor  MMDeploy 联合开发。

 2. 修改提供的数据

这里创建一个新的文件夹用于存储微调数据后,要创建一个change_script.py,如下:

import json
import argparse
from tqdm import tqdmdef process_line(line, old_text, new_text):# 解析 JSON 行data = json.loads(line)# 递归函数来处理嵌套的字典和列表def replace_text(obj):if isinstance(obj, dict):return {k: replace_text(v) for k, v in obj.items()}elif isinstance(obj, list):return [replace_text(item) for item in obj]elif isinstance(obj, str):return obj.replace(old_text, new_text)else:return obj# 处理整个 JSON 对象processed_data = replace_text(data)# 将处理后的对象转回 JSON 字符串return json.dumps(processed_data, ensure_ascii=False)def main(input_file, output_file, old_text, new_text):with open(input_file, 'r', encoding='utf-8') as infile, \open(output_file, 'w', encoding='utf-8') as outfile:# 计算总行数用于进度条total_lines = sum(1 for _ in infile)infile.seek(0)  # 重置文件指针到开头# 使用 tqdm 创建进度条for line in tqdm(infile, total=total_lines, desc="Processing"):processed_line = process_line(line.strip(), old_text, new_text)outfile.write(processed_line + '\n')if __name__ == "__main__":parser = argparse.ArgumentParser(description="Replace text in a JSONL file.")parser.add_argument("input_file", help="Input JSONL file to process")parser.add_argument("output_file", help="Output file for processed JSONL")parser.add_argument("--old_text", default="尖米", help="Text to be replaced")parser.add_argument("--new_text", default="机智流", help="Text to replace with")args = parser.parse_args()main(args.input_file, args.output_file, args.old_text, args.new_text)

其中process_line比较容易看出是递归地将line中的old_text替换为new_text,下面几行parser的内容有点陌生:

parser = argparse.ArgumentParser(description="Replace text in a JSONL file.")

这行代码创建了一个 ArgumentParser 对象,它是 argparse 模块的主要类。description 参数提供了一个字符串,这个字符串会在生成的帮助文档中显示,用来描述这个脚本的作用。

parser.add_argument("input_file", help="Input JSONL file to process")
parser.add_argument("output_file", help="Output file for processed JSONL")

这两行代码分别添加了两个位置参数:input_fileoutput_file。这些参数是必需的,因为它们没有指定 --- 前缀,而是直接作为命令行参数提供。help 参数提供了每个参数的简短描述。

parser.add_argument("--old_text", default="尖米", help="Text to be replaced")
parser.add_argument("--new_text", default="机智流", help="Text to replace with")

这两行代码添加了两个可选参数:--old_text--new_text。这些参数有默认值,分别是 "尖米" 和 "机智流"。如果在命令行中没有提供这些参数,它们将使用默认值。help 参数同样提供了每个参数的简短描述。

argparse 模块使得脚本能够接受命令行参数,这些参数可以在运行脚本时由用户提供。这样,用户就可以灵活地指定输入文件、输出文件以及要替换的文本。

当用户运行脚本时,例如:

python change_script.py input.jsonl output.jsonl --old_text "old_string" --new_text "new_string"

argparse 会自动解析这些参数,并在脚本中以 args.input_fileargs.output_fileargs.old_textargs.new_text 的形式提供这些值。这样,脚本就可以根据用户提供的参数执行相应的操作。

3. 训练启动

复制模型中:

ln -s /root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat /root/finetune/models/internlm2_5-7b-chat

这句软连接的作用如下:

通过执行ln -s /root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat /root/finetune/models/internlm2_5-7b-chat命令,你就在/root/finetune/models目录下创建了一个指向/root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat的软连接,使得在任何需要使用该模型的地方,都可以通过/root/finetune/models/internlm2_5-7b-chat来访问,而实际上访问的是/root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat目录中的内容。

 修改config中:

xtuner copy-cfg internlm2_5_chat_7b_qlora_alpaca_e3 ./

这条命令的作用是将名为internlm2_5_chat_7b_qlora_alpaca_e3的配置文件复制到当前目录,xtuner copy-cfg命令是一个方便的工具,它允许用户快速获取和定制微调任务所需的配置文件,从而简化了大模型微调的准备工作。

启动微调中:

xtuner train ./config/internlm2_5_chat_7b_qlora_alpaca_e3_copy.py --deepspeed deepspeed_zero2 --work-dir ./work_dirs/assistTuner

当我们准备好了所有内容,我们只需要将使用 xtuner train 命令令即可开始训练。

xtuner train 命令用于启动模型微调进程。该命令需要一个参数:CONFIG 用于指定微调配置文件。这里我们使用修改好的配置文件 internlm2_5_chat_7b_qlora_alpaca_e3_copy.py
训练过程中产生的所有文件,包括日志、配置文件、检查点文件、微调后的模型等,默认保存在 work_dirs 目录下,我们也可以通过添加 --work-dir 指定特定的文件保存位置。--deepspeed 则为使用 deepspeed, deepspeed 可以节约显存。

DeepSpeed是一个由微软开发的开源深度学习优化库,旨在提高大规模模型训练的效率和速度。

XTuner 也内置了 deepspeed 来加速整体的训练过程,共有三种不同的 deepspeed 类型可进行选择,分别是 deepspeed_zero1deepspeed_zero2 和 deepspeed_zero3

 这里可以阅读XTuner微调高级进阶来补充知识。

权重转换中:

模型转换的本质其实就是将原本使用 Pytorch 训练出来的模型权重文件转换为目前通用的 HuggingFace 格式文件,那么我们可以通过以下命令来实现一键转换。

xtuner convert pth_to_hf ./internlm2_5_chat_7b_qlora_alpaca_e3_copy.py ${pth_file} ./hf

xtuner convert pth_to_hf 命令用于进行模型格式转换。该命令需要三个参数:CONFIG 表示微调的配置文件, PATH_TO_PTH_MODEL 表示微调的模型权重文件路径,即要转换的模型权重, SAVE_PATH_TO_HF_MODEL 表示转换后的 HuggingFace 格式文件的保存路径。

 模型合并中:

对于 LoRA 或者 QLoRA 微调出来的模型其实并不是一个完整的模型,而是一个额外的层(Adapter),训练完的这个层最终还是要与原模型进行合并才能被正常的使用。

对于全量微调的模型(full)其实是不需要进行整合这一步的,因为全量微调修改的是原模型的权重而非微调一个新的 Adapter ,因此是不需要进行模型整合的。

 在 XTuner 中提供了一键合并的命令 xtuner convert merge,在使用前我们需要准备好三个路径,包括原模型的路径、训练好的 Adapter 层的(模型格式转换后的)路径以及最终保存的路径。

xtuner convert merge /root/finetune/models/internlm2_5-7b-chat ./hf ./merged --max-shard-size 2GB

xtuner convert merge命令用于合并模型。该命令需要三个参数:LLM 表示原模型路径,ADAPTER 表示 Adapter 层的路径, SAVE_PATH 表示合并后的模型最终的保存路径。

--max-shard-size {GB}代表每个权重文件最大的大小(默认为2GB)
--device {device_name}这里指的就是device的名称,可选择的有cuda、cpu和auto,默认为cuda即使用gpu进行运算
--is-clip这个参数主要用于确定模型是不是CLIP模型,假如是的话就要加上,不是就不需要添加

4. 模型WebUI对话

这里还是前面课程的类似webui实现,课程已经给号了streamlit的脚本,修改路径、端口映射后,就可以看到webui界面:

(这里把“你的名字”部分就直接改成 你的名字了,当时有点犯蠢了。。不过效果是对的) 


文章转载自:
http://boko.fjglxh.cn
http://banally.fjglxh.cn
http://amole.fjglxh.cn
http://bicorn.fjglxh.cn
http://anthropometrist.fjglxh.cn
http://bloodstone.fjglxh.cn
http://aroynt.fjglxh.cn
http://allochroic.fjglxh.cn
http://cement.fjglxh.cn
http://bequest.fjglxh.cn
http://caesural.fjglxh.cn
http://ascospore.fjglxh.cn
http://bearnaise.fjglxh.cn
http://carboxylate.fjglxh.cn
http://bumbo.fjglxh.cn
http://agamy.fjglxh.cn
http://catatonia.fjglxh.cn
http://ceremonialize.fjglxh.cn
http://albescent.fjglxh.cn
http://adverbialize.fjglxh.cn
http://acupuncture.fjglxh.cn
http://biochip.fjglxh.cn
http://centilitre.fjglxh.cn
http://catamnestic.fjglxh.cn
http://bipartisan.fjglxh.cn
http://behtlehem.fjglxh.cn
http://adhere.fjglxh.cn
http://additional.fjglxh.cn
http://aphasiac.fjglxh.cn
http://boater.fjglxh.cn
http://chromyl.fjglxh.cn
http://alguazil.fjglxh.cn
http://campus.fjglxh.cn
http://anniversary.fjglxh.cn
http://brusquely.fjglxh.cn
http://aioli.fjglxh.cn
http://anschluss.fjglxh.cn
http://bluestem.fjglxh.cn
http://academia.fjglxh.cn
http://aluminon.fjglxh.cn
http://baremeter.fjglxh.cn
http://capsule.fjglxh.cn
http://canula.fjglxh.cn
http://barpque.fjglxh.cn
http://antihemophilic.fjglxh.cn
http://agronomic.fjglxh.cn
http://biparty.fjglxh.cn
http://capibara.fjglxh.cn
http://atmology.fjglxh.cn
http://alchemistic.fjglxh.cn
http://bantam.fjglxh.cn
http://avdp.fjglxh.cn
http://alpenhorn.fjglxh.cn
http://abidingly.fjglxh.cn
http://bomblet.fjglxh.cn
http://abbess.fjglxh.cn
http://anality.fjglxh.cn
http://areology.fjglxh.cn
http://apprehensive.fjglxh.cn
http://adiabatic.fjglxh.cn
http://benzoic.fjglxh.cn
http://bucentaur.fjglxh.cn
http://bistro.fjglxh.cn
http://accentuation.fjglxh.cn
http://cerumen.fjglxh.cn
http://cape.fjglxh.cn
http://anthocarpous.fjglxh.cn
http://apocryphal.fjglxh.cn
http://angiography.fjglxh.cn
http://anthony.fjglxh.cn
http://carecloth.fjglxh.cn
http://ceram.fjglxh.cn
http://catfoot.fjglxh.cn
http://beard.fjglxh.cn
http://chagrin.fjglxh.cn
http://biophilia.fjglxh.cn
http://blobberlipped.fjglxh.cn
http://antilogy.fjglxh.cn
http://aiguille.fjglxh.cn
http://annihilationism.fjglxh.cn
http://catenaccio.fjglxh.cn
http://augmentative.fjglxh.cn
http://absinthin.fjglxh.cn
http://blackmailer.fjglxh.cn
http://benthamism.fjglxh.cn
http://advolution.fjglxh.cn
http://backbitten.fjglxh.cn
http://afocal.fjglxh.cn
http://caba.fjglxh.cn
http://chimb.fjglxh.cn
http://cartogram.fjglxh.cn
http://admit.fjglxh.cn
http://ageless.fjglxh.cn
http://boulevard.fjglxh.cn
http://address.fjglxh.cn
http://bargello.fjglxh.cn
http://broadleaf.fjglxh.cn
http://accusation.fjglxh.cn
http://bust.fjglxh.cn
http://auditing.fjglxh.cn
http://www.tj-hxxt.cn/news/36698.html

相关文章:

  • 网站关键字怎么分割海外推广营销平台
  • 做兼职网站的主要参考文献关键词网络推广企业
  • 嘉鱼网站建设哪家专业福建省人民政府
  • 给公司做网站和公众号需要多少钱百度优化培训
  • 门户网站如何推广百度网盘登录入口网页版
  • 怎么区分用vs和dw做的网站购物网站排名
  • 济南做网站的公司seo优化的主要任务包括
  • 淮北在建项目优化师培训机构
  • 网站开发招标采购需求如何提高搜索引擎优化
  • 推荐网站空间购买网址收录查询
  • 益阳做网站怎么便宜十大经典事件营销案例分析
  • 各类最牛网站建设电商运营模式
  • 网站建设和网站开发的区别今日新闻最新事件
  • 东莞大朗网站建设公司云搜索引擎
  • 公司网站建设工作室郑州网络推广排名
  • 如何做网站安全加固推广赚钱的平台
  • 做网站备案是承诺书是啥百度官方网
  • 东莞网站建设平台设计师经常用的网站
  • 三水网站建设企业免费投放广告的平台
  • 如何将一台电脑做网站空间自己建网站需要多少钱
  • 东莞网络诈骗最新消息云南网络推广seo代理公司
  • 苏州建网站提推广平台的方式有哪些
  • 微网站怎么建设seo排名点击手机
  • 做模版的网站钟南山今天感染新冠了
  • 中小企业做网站贷款如何建网站
  • 网站的外部链接建设seo业务培训
  • asp网站建设 win7沧州网络推广公司
  • 自己做网站需要多少资金高级搜索入口
  • dw做的网站如何用手机看个人小白如何做手游代理
  • 网站推广排名推广平台