利用阿里云PAI平台微调ChatGLM3-6B

2024-06-10 23:28

本文主要是介绍利用阿里云PAI平台微调ChatGLM3-6B,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.介绍ChatGLM3-6B

ChatGLM3-6B大模型是智谱AI和清华大学 KEG 实验室联合发布的对话预训练模型。

1.1 模型规模

模型规模通常用参数数量(parameters)来衡量。参数数量越多,模型理论上越强大,但也更耗费资源。以下是一些典型模型的参数数量对比:

ChatTGLM3-6b:6 billion (60亿) 参数
GPT-3:175 billion (1750亿) 参数
BERT Large:340 million (3.4亿) 参数
GPT-2:1.5 billion (15亿) 参数
从参数数量上看,ChatTGLM3-6b比BERT和GPT-2大,但远小于GPT-3。

1.2 性能对比

性能可以通过在各种基准测试(benchmarks)上的表现来衡量,例如自然语言理解、问答、翻译等任务。以下是一些假设数据(具体的数值可能会有所不同,但用于说明差异):

性能对比

1.3 资源消耗对比表

资源消耗对比表
这些数据表明,ChatTGLM3-6b在资源消耗上比GPT-3低,但比BERT和GPT-2高一些。

2. 部署ChatGLM3-6B大模型

适用于本地交互和测试,适合个人用户和开发者进行快速迭代和调试,命令行模式。
1. 下载大模型

mkdir models
cd modelsapt update
# 能够拉长文本形式的文件
apt install git-lfs# 克隆chatGLM3-6b大模型
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git

chatglm3-6b目录如图

2.下载项目

我们通过下面的 命令行 和 网页版 调用我们部署的本地大模型

mkdir webcodes
cd webcodes# 下载chatglm3-6b web_demo项目
git clone https://github.com/THUDM/ChatGLM3.git# 安装依赖
pip install -r requirements.txt

下载的ChatGLM项目

启动(启动之前需要修改大模型路径,如果没有修改默认从Hugging Face下载【需要魔法】),以下为小黑窗启动为例:
修改模型路径

# 小黑窗启动命令
python cli_demo.py# 网页端启动
streamlit run web_demo_streamlit.py

效果如图所示

3. OpenAPI的部署

适用于需要将ChatGLM3-6B模型作为服务提供的场景,提供了丰富的API接口和灵活的部署选项【处理了文本的嵌入】。

1.下载向量,这里我以m3e为例子

cd models
# 克隆m3e向量模型
git clone https://www.modelscope.cn/xrunda/m3e-base.git

2.修改大模型路径
修改大模型路径

3,运行启动

cd openai_api_demo
python api_server.py

4. 测试

curl -X POST "http://127.0.0.1:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-d "{\"model\": \"chatglm3-6b\", \"messages\": [{\"role\": \"system\", \"content\": \"You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.\"}, {\"role\": \"user\", \"content\": \"你好,你是谁?\"}], \"stream\": false, \"max_tokens\": 100, \"temperature\": 0.8, \"top_p\": 0.8}"

调用OpenAPI接口

4. ChatGLM3-6B大模型loar微调

借助LLaMA-Factory实现快速微调(官方推荐)LLaMA Factory的官网图片
1. 安装LLaMA-Factory
克隆LLaMA-Factory 以及install所需依赖

# 克隆项目
git clone https://github.com/hiyouga/LLaMA-Factory.git# 安装项目依赖
cd LLaMA-Factory
pip install -r requirements.txt
pip install transformers_stream_generator bitsandbytes tiktoken auto-gptq optimum autoawq
pip install --upgrade tensorflow
pip uninstall flash-attn -y# 运行
CUDA_VISIBLE_DEVICES=0 USE_MODELSCOPE_HUB=1 python src/train_web.py

使用GPU和对ModelScope Hub的支持
2.自定义训练集并上传
self_cognition文件

 
# 自定义数据集
[{"instruction": "用户指令(必填)","input": "用户输入(选填)","output": "模型回答(必填)","system": "系统提示词(选填)","history": [["第一轮指令(选填)", "第一轮回答(选填)"],["第二轮指令(选填)", "第二轮回答(选填)"]]}
]

打开LLaMA-Factory项目data文件夹下的dataset_info.json,进行上传

{"alpaca_en": {"file_name": "alpaca_data_en_52k.json","file_sha1": "607f94a7f581341e59685aef32f531095232cf23"},"alpaca_zh": {"file_name": "alpaca_data_zh_51k.json","file_sha1": "0016a4df88f523aad8dc004ada7575896824a0dc"},"alpaca_gpt4_en": {"file_name": "alpaca_gpt4_data_en.json","file_sha1": "647f4ad447bd993e4b6b6223d1be15208bab694a"},"alpaca_gpt4_zh": {"file_name": "alpaca_gpt4_data_zh.json","file_sha1": "3eaa3bda364ccdd59925d7448a698256c31ef845"},"identity": {"file_name": "identity.json","file_sha1": "ffe3ecb58ab642da33fbb514d5e6188f1469ad40"},"oaast_sft": {"file_name": "oaast_sft.json","file_sha1": "7baf5d43e67a91f9bbdf4e400dbe033b87e9757e","columns": {"prompt": "instruction","query": "input","response": "output","history": "history"}},"oaast_sft_zh": {"file_name": "oaast_sft_zh.json","file_sha1": "a6a91f18f80f37b10ded9cf633fb50c033bf7b9f","columns": {"prompt": "instruction","query": "input","response": "output","history": "history"}},"lima": {"file_name": "lima.json","file_sha1": "9db59f6b7007dc4b17529fc63379b9cd61640f37","columns": {"prompt": "instruction","query": "input","response": "output","history": "history"}},"glaive_toolcall": {"file_name": "glaive_toolcall_10k.json","file_sha1": "a6917b85d209df98d31fdecb253c79ebc440f6f3","formatting": "sharegpt","columns": {"messages": "conversations","tools": "tools"}},"example": {"script_url": "example_dataset","columns": {"prompt": "instruction","query": "input","response": "output","history": "history"}},"guanaco": {"hf_hub_url": "JosephusCheung/GuanacoDataset","ms_hub_url": "AI-ModelScope/GuanacoDataset"},"belle_2m": {"hf_hub_url": "BelleGroup/train_2M_CN","ms_hub_url": "AI-ModelScope/train_2M_CN"},"belle_1m": {"hf_hub_url": "BelleGroup/train_1M_CN","ms_hub_url": "AI-ModelScope/train_1M_CN"},"belle_0.5m": {"hf_hub_url": "BelleGroup/train_0.5M_CN","ms_hub_url": "AI-ModelScope/train_0.5M_CN"},"belle_dialog": {"hf_hub_url": "BelleGroup/generated_chat_0.4M","ms_hub_url": "AI-ModelScope/generated_chat_0.4M"},"belle_math": {"hf_hub_url": "BelleGroup/school_math_0.25M","ms_hub_url": "AI-ModelScope/school_math_0.25M"},"belle_multiturn": {"script_url": "belle_multiturn","formatting": "sharegpt"},"ultra_chat": {"script_url": "ultra_chat","formatting": "sharegpt"},"open_platypus": {"hf_hub_url": "garage-bAInd/Open-Platypus","ms_hub_url": "AI-ModelScope/Open-Platypus"},"codealpaca": {"hf_hub_url": "sahil2801/CodeAlpaca-20k","ms_hub_url": "AI-ModelScope/CodeAlpaca-20k"},"alpaca_cot": {"hf_hub_url": "QingyiSi/Alpaca-CoT","ms_hub_url": "AI-ModelScope/Alpaca-CoT"},"openorca": {"hf_hub_url": "Open-Orca/OpenOrca","ms_hub_url": "AI-ModelScope/OpenOrca","columns": {"prompt": "question","response": "response","system": "system_prompt"}},"slimorca": {"hf_hub_url": "Open-Orca/SlimOrca","formatting": "sharegpt"},"mathinstruct": {"hf_hub_url": "TIGER-Lab/MathInstruct","ms_hub_url": "AI-ModelScope/MathInstruct","columns": {"prompt": "instruction","response": "output"}},"firefly": {"hf_hub_url": "YeungNLP/firefly-train-1.1M","columns": {"prompt": "input","response": "target"}},"wikiqa": {"hf_hub_url": "wiki_qa","columns": {"prompt": "question","response": "answer"}},"webqa": {"hf_hub_url": "suolyer/webqa","ms_hub_url": "AI-ModelScope/webqa","columns": {"prompt": "input","response": "output"}},"webnovel": {"hf_hub_url": "zxbsmk/webnovel_cn","ms_hub_url": "AI-ModelScope/webnovel_cn"},"nectar_sft": {"hf_hub_url": "mlinmg/SFT-Nectar","ms_hub_url": "AI-ModelScope/SFT-Nectar"},"deepctrl": {"ms_hub_url": "deepctrl/deepctrl-sft-data"},"adgen": {"hf_hub_url": "HasturOfficial/adgen","ms_hub_url": "AI-ModelScope/adgen","columns": {"prompt": "content","response": "summary"}},"sharegpt_hyper": {"hf_hub_url": "totally-not-an-llm/sharegpt-hyperfiltered-3k","formatting": "sharegpt"},"sharegpt4": {"hf_hub_url": "shibing624/sharegpt_gpt4","ms_hub_url": "AI-ModelScope/sharegpt_gpt4","formatting": "sharegpt"},"ultrachat_200k": {"hf_hub_url": "HuggingFaceH4/ultrachat_200k","ms_hub_url": "AI-ModelScope/ultrachat_200k","columns": {"messages": "messages"},"tags": {"role_tag": "role","content_tag": "content","user_tag": "user","assistant_tag": "assistant"},"formatting": "sharegpt"},"agent_instruct": {"hf_hub_url": "THUDM/AgentInstruct","ms_hub_url": "ZhipuAI/AgentInstruct","formatting": "sharegpt"},"lmsys_chat": {"hf_hub_url": "lmsys/lmsys-chat-1m","ms_hub_url": "AI-ModelScope/lmsys-chat-1m","columns": {"messages": "conversation"},"tags": {"role_tag": "role","content_tag": "content","user_tag": "human","assistant_tag": "assistant"},"formatting": "sharegpt"},"evol_instruct": {"hf_hub_url": "WizardLM/WizardLM_evol_instruct_V2_196k","ms_hub_url": "AI-ModelScope/WizardLM_evol_instruct_V2_196k","formatting": "sharegpt"},"glaive_toolcall_100k": {"hf_hub_url": "hiyouga/glaive-function-calling-v2-sharegpt","formatting": "sharegpt","columns": {"messages": "conversations","tools": "tools"}},"cosmopedia": {"hf_hub_url": "HuggingFaceTB/cosmopedia","columns": {"prompt": "prompt","response": "text"}},"oasst_de": {"hf_hub_url": "mayflowergmbh/oasst_de"},"dolly_15k_de": {"hf_hub_url": "mayflowergmbh/dolly-15k_de"},"alpaca-gpt4_de": {"hf_hub_url": "mayflowergmbh/alpaca-gpt4_de"},"openschnabeltier_de": {"hf_hub_url": "mayflowergmbh/openschnabeltier_de"},"evol_instruct_de": {"hf_hub_url": "mayflowergmbh/evol-instruct_de"},"dolphin_de": {"hf_hub_url": "mayflowergmbh/dolphin_de"},"booksum_de": {"hf_hub_url": "mayflowergmbh/booksum_de"},"airoboros_de": {"hf_hub_url": "mayflowergmbh/airoboros-3.0_de"},"ultrachat_de": {"hf_hub_url": "mayflowergmbh/ultra-chat_de"},"hh_rlhf_en": {"script_url": "hh_rlhf_en","columns": {"prompt": "instruction","response": "output","history": "history"},"ranking": true},"oaast_rm": {"file_name": "oaast_rm.json","file_sha1": "622d420e9b70003b210618253bd3d9d2891d86cb","columns": {"prompt": "instruction","query": "input","response": "output","history": "history"},"ranking": true},"oaast_rm_zh": {"file_name": "oaast_rm_zh.json","file_sha1": "1065af1f3784dd61be5e79713a35f427b713a232","columns": {"prompt": "instruction","query": "input","response": "output","history": "history"},"ranking": true},"comparison_gpt4_en": {"file_name": "comparison_gpt4_data_en.json","file_sha1": "96fa18313544e22444fe20eead7754b17da452ae","ranking": true},"comparison_gpt4_zh": {"file_name": "comparison_gpt4_data_zh.json","file_sha1": "515b18ed497199131ddcc1af950345c11dc5c7fd","ranking": true},"orca_rlhf": {"file_name": "orca_rlhf.json","file_sha1": "acc8f74d16fd1fc4f68e7d86eaa781c2c3f5ba8e","ranking": true,"columns": {"prompt": "question","response": "answer","system": "system"}},"nectar_rm": {"hf_hub_url": "mlinmg/RLAIF-Nectar","ms_hub_url": "AI-ModelScope/RLAIF-Nectar","ranking": true},"orca_dpo_de" : {"hf_hub_url": "mayflowergmbh/intel_orca_dpo_pairs_de","ranking": true},"wiki_demo": {"file_name": "wiki_demo.txt","file_sha1": "e70375e28eda542a90c68213640cc371898ce181","columns": {"prompt": "text"}},"c4_demo": {"file_name": "c4_demo.json","file_sha1": "a5a0c86759732f9a5238e447fecd74f28a66cca8","columns": {"prompt": "text"}},"refinedweb": {"hf_hub_url": "tiiuae/falcon-refinedweb","columns": {"prompt": "content"}},"redpajama_v2": {"hf_hub_url": "togethercomputer/RedPajama-Data-V2","columns": {"prompt": "raw_content"},"subset": "default"},"wikipedia_en": {"hf_hub_url": "olm/olm-wikipedia-20221220","ms_hub_url": "AI-ModelScope/olm-wikipedia-20221220","columns": {"prompt": "text"}},"wikipedia_zh": {"hf_hub_url": "pleisto/wikipedia-cn-20230720-filtered","ms_hub_url": "AI-ModelScope/wikipedia-cn-20230720-filtered","columns": {"prompt": "completion"}},"pile": {"hf_hub_url": "EleutherAI/pile","ms_hub_url": "AI-ModelScope/pile","columns": {"prompt": "text"},"subset": "all"},"skypile": {"hf_hub_url": "Skywork/SkyPile-150B","ms_hub_url": "AI-ModelScope/SkyPile-150B","columns": {"prompt": "text"}},"the_stack": {"hf_hub_url": "bigcode/the-stack","ms_hub_url": "AI-ModelScope/the-stack","columns": {"prompt": "content"}},"starcoder_python": {"hf_hub_url": "bigcode/starcoderdata","ms_hub_url": "AI-ModelScope/starcoderdata","columns": {"prompt": "content"},"folder": "python"},"self_cognition": {"file_name": "self_cognition.json","file_sha1": "eca3d89fa38b35460d6627cefdc101feef507eb5"}
}

data目录
3. 进行微调

# 运行
CUDA_VISIBLE_DEVICES=0 USE_MODELSCOPE_HUB=1 python src/train_web.py

微调Web页面

我们需要注意一下:设置正确的断点:

当报错output已经存在的时候,很有可能是因为当前断点已经设置过了,所以我们需要设置一个新的断点

微调过程图
结果如下所示:
结果图

这篇关于利用阿里云PAI平台微调ChatGLM3-6B的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1049565

相关文章

流媒体平台/视频监控/安防视频汇聚EasyCVR播放暂停后视频画面黑屏是什么原因?

视频智能分析/视频监控/安防监控综合管理系统EasyCVR视频汇聚融合平台,是TSINGSEE青犀视频垂直深耕音视频流媒体技术、AI智能技术领域的杰出成果。该平台以其强大的视频处理、汇聚与融合能力,在构建全栈视频监控系统中展现出了独特的优势。视频监控管理系统EasyCVR平台内置了强大的视频解码、转码、压缩等技术,能够处理多种视频流格式,并以多种格式(RTMP、RTSP、HTTP-FLV、WebS

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟 开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚 第一站:海量资源,应有尽有 走进“智听

阿里开源语音识别SenseVoiceWindows环境部署

SenseVoice介绍 SenseVoice 专注于高精度多语言语音识别、情感辨识和音频事件检测多语言识别: 采用超过 40 万小时数据训练,支持超过 50 种语言,识别效果上优于 Whisper 模型。富文本识别:具备优秀的情感识别,能够在测试数据上达到和超过目前最佳情感识别模型的效果。支持声音事件检测能力,支持音乐、掌声、笑声、哭声、咳嗽、喷嚏等多种常见人机交互事件进行检测。高效推

如何解决线上平台抽佣高 线下门店客流少的痛点!

目前,许多传统零售店铺正遭遇客源下降的难题。尽管广告推广能带来一定的客流,但其费用昂贵。鉴于此,众多零售商纷纷选择加入像美团、饿了么和抖音这样的大型在线平台,但这些平台的高佣金率导致了利润的大幅缩水。在这样的市场环境下,商家之间的合作网络逐渐成为一种有效的解决方案,通过资源和客户基础的共享,实现共同的利益增长。 以最近在上海兴起的一个跨行业合作平台为例,该平台融合了环保消费积分系统,在短

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

AI Toolkit + H100 GPU,一小时内微调最新热门文生图模型 FLUX

上个月,FLUX 席卷了互联网,这并非没有原因。他们声称优于 DALLE 3、Ideogram 和 Stable Diffusion 3 等模型,而这一点已被证明是有依据的。随着越来越多的流行图像生成工具(如 Stable Diffusion Web UI Forge 和 ComyUI)开始支持这些模型,FLUX 在 Stable Diffusion 领域的扩展将会持续下去。 自 FLU

【区块链 + 人才服务】区块链集成开发平台 | FISCO BCOS应用案例

随着区块链技术的快速发展,越来越多的企业开始将其应用于实际业务中。然而,区块链技术的专业性使得其集成开发成为一项挑战。针对此,广东中创智慧科技有限公司基于国产开源联盟链 FISCO BCOS 推出了区块链集成开发平台。该平台基于区块链技术,提供一套全面的区块链开发工具和开发环境,支持开发者快速开发和部署区块链应用。此外,该平台还可以提供一套全面的区块链开发教程和文档,帮助开发者快速上手区块链开发。

K8S(Kubernetes)开源的容器编排平台安装步骤详解

K8S(Kubernetes)是一个开源的容器编排平台,用于自动化部署、扩展和管理容器化应用程序。以下是K8S容器编排平台的安装步骤、使用方式及特点的概述: 安装步骤: 安装Docker:K8S需要基于Docker来运行容器化应用程序。首先要在所有节点上安装Docker引擎。 安装Kubernetes Master:在集群中选择一台主机作为Master节点,安装K8S的控制平面组件,如AP

衡石分析平台使用手册-单机安装及启动

单机安装及启动​ 本文讲述如何在单机环境下进行 HENGSHI SENSE 安装的操作过程。 在安装前请确认网络环境,如果是隔离环境,无法连接互联网时,请先按照 离线环境安装依赖的指导进行依赖包的安装,然后按照本文的指导继续操作。如果网络环境可以连接互联网,请直接按照本文的指导进行安装。 准备工作​ 请参考安装环境文档准备安装环境。 配置用户与安装目录。 在操作前请检查您是否有 sud