Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
sunyuan 94c30e9b27 | 4 months ago | |
---|---|---|
.. | ||
scripts | 4 months ago | |
README.md | 4 months ago | |
arguments.py | 5 months ago | |
finetune.py | 4 months ago | |
inference.py | 5 months ago | |
preprocess_utils.py | 4 months ago | |
requirements.txt | 4 months ago | |
trainer.py | 4 months ago |
本目录提供 ChatGLM3-6B-base 模型的微调示例,目前,仅包含了Lora微调。
如果将模型下载到了本地,本文和代码中的 THUDM/chatglm3-6b-base
字段均应替换为相应地址以从本地加载模型。
运行示例需要 python>=3.10
,除基础的 torch
依赖外,示例代码运行还需要依赖
pip install -r requirements.txt
base
模型不具备对话能力,仅能够生成单轮回复。如果你希望使用多轮对话模型,使用Chat
模型进行微调。
格式上,请使用alpaca
数据集。
{"context": "hello", "target": "hi,I am ChatGLM3"}
其中,context
是对话的上文,也就是模型的输入,target
是对话的下文,也就是模型的输出。
以下脚本提供了微调模型的参考方式。
./scripts/finetune_lora.sh # 使用Lora微调
如果你使用的是windows系统,请将脚本改为bat
文件执行。同时,如果你是单卡运行环境,也可以将脚本中中的这行代码
torchrun --standalone --nnodes=1 --nproc_per_node=$NUM_GPUS finetune.py
修改为
python finetune.py
请注意,这样修改后,你需要手动设置CUDA_VISIBLE_DEVICES
环境变量,以控制使用哪张显卡。
微调代码在开始训练前,会先打印首条训练数据的预处理信息,显示为
Sanity Check >>>>>>>>>>>>>
'[gMASK]': 64790 -> -100
'sop': 64792 -> -100
'<|system|>': 64794 -> -100
'': 30910 -> -100
'\n': 13 -> -100
'Answer': 20115 -> -100
'the': 267 -> -100
'following': 1762 -> -100
...
'know': 683 -> -100
'the': 267 -> -100
'response': 3010 -> -100
'details': 3296 -> -100
'.': 30930 -> -100
'<|assistant|>': 64796 -> -100
'': 30910 -> 30910
'\n': 13 -> 13
'I': 307 -> 307
'need': 720 -> 720
'to': 289 -> 289
'use': 792 -> 792
...
'': 0 -> -100
'': 0 -> -100 (有若干个)
<<<<<<<<<<<<< Sanity Check
字样,每行依次表示一个 detokenized string, token_id 和 target_id。可在日志中查看这部分的 loss_mask
是否符合预期。若不符合,可能需要调整代码或数据。
参考显存用量
23GB
。若尝试后发现显存不足,可以考虑
DEV_BATCH_SIZE
并提升 GRAD_ACCUMULARION_STEPS
MAX_SEQ_LEN
,但是这可能会影响模型的性能数据量和 loss 衰减
LEARNING_RATE
或者提升 WARMUP_STEPS
。0.5
以下时,就属于比较好的状态。训练数据和轮次
Max Steps
为训练执行的步骤,与数据集的数量无关,这个参数不等于Epoch
。Batch Size
为每个GPU的batch size,如果你使用了多卡训练,那么实际的batch size为 Batch Size * GPU数量
。训练精度
bf16
格式进行微调,并确认所有依赖和硬件满足微调硬件要求,否则可能出现 loss = 0 的情况。Chat
模型和对应的微调框架。No Description
Text Python Markdown Jupyter Notebook Shell
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》