Function Call实践(三)——微调Llama3-8B-Instruct模型 #163
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: HswOAuth/llm_course#163
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
这次实验和之前的微调没有什么很大的区别,在这里把各行命令再熟悉一下,模糊的地方和词语也记录一下,把流程走一遍。
notebook配置
设置环境变量
由于我们在平台上进行实验,故每次都要执行如下操作:
下载模型
这里平台上用git给我们下好了。
但是一般我们还是用的huggingface网站上直接下载模型的,如之前下载qwen模型:
(这里模型不载在默认的huggingface目录下,而是指定路径为--local-dir /dataset/Qwen1.5-0.5B-Chat。)
下载数据集
(路径也指定了,为--local-dir /code/internlm_Agent-FLAN_data)
微调训练
这里使用4块DCU进行分布式训练。DCU是一种高性能的计算卡,广泛应用于需要大规模计算和高性能模拟的领域,如人工智能计算、科学计算等。
在分布式训练中,使用多块DCU可以显著提升训练速度和效率。通过调整上下文长度和使用DeepSpeed等优化技术,可以有效地训练大型模型。命令中的
NPROC_PER_NODE=4
表示每个节点使用4个进程,xtuner
可能是一个训练脚本或者工具,用于启动训练任务。--deepspeed deepspeed_zero3_offload
是DeepSpeed库的一个配置选项,用于优化分布式训练过程。这种训练方式特别适合于大规模的深度学习任务,尤其是在处理大型数据集和复杂模型时,可以有效减少训练时间和资源消耗。
训练过程如下就表示正常运行:
模型转换
平台上已经训练好模型,放在huggingface-cache数据下,挂载该数据后目录位于:/dataset/llama3-8b-functioncall-ft/agent-flan:
将用pytorch训练得到的pth格式模型转换为hf格式,并与原模型合并:
调用模型测试模型微调前后的区别:
结果对比如下:
微调前,没有准确给出function需要的json格式参数;
微调后,可以正确给出json格式function参数。