diff --git a/chatglm/qlora_chatglm3.ipynb b/chatglm/qlora_chatglm3.ipynb index 6227e49..71a5ef9 100644 --- a/chatglm/qlora_chatglm3.ipynb +++ b/chatglm/qlora_chatglm3.ipynb @@ -8,6 +8,25 @@ "# 使用领域(私有)数据微调 ChatGLM3" ] }, + { + "cell_type": "markdown", + "id": "ff3a3927-59e9-4ea3-abcd-332147eac0ed", + "metadata": {}, + "source": [ + "
\n", + "注意:新版本的 chatglm3-6b 模型在微调过程中需要更多显存 (点击查看解决方法)\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
现象如果在微调 chatglm3-6b 模型时,执行 trainer.train() 后瞬间出现 “OutOfMemoryError: CUDA out of memory.”(显存不足)错误,请考虑指定一个旧版本进行微调。
原因从2024年2月6日后发布的 chatglm3-6b 模型开始,调用 torch.utils.checkpoint.checkpoint() 方法时,use_reentrant 参数的默认值由原来的 True 改为 False。这导致在训练时保存更多的梯度参数以加快反向传播计算速度,同时占用更多显存。此外,新代码覆盖了基类 PreTrainedModel 中的 gradient_checkpointing_enable() 方法,导致无法通过梯度检查点来减少显存占用。有关详细的代码更改,请查看 Commit 37fe000
方案在加载 Tokenizer 和 Model 时,通过添加 revision 参数指定一个旧版本。示例代码如下:
\n", + "tokenizer = AutoTokenizer.from_pretrained(......, revision='b098244')
\n", + "model = AutoModel.from_pretrained(......, revision='b098244')
\n", + "
" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -917,7 +936,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/chatglm/qlora_chatglm3_timestamp.ipynb b/chatglm/qlora_chatglm3_timestamp.ipynb index b788d94..39f0a71 100644 --- a/chatglm/qlora_chatglm3_timestamp.ipynb +++ b/chatglm/qlora_chatglm3_timestamp.ipynb @@ -10,6 +10,33 @@ "生成带有 epoch 和 timestamp 的模型文件" ] }, + { + "cell_type": "markdown", + "id": "e63fd22b-b00f-4643-bc8a-a7cac180e943", + "metadata": { + "execution": { + "iopub.execute_input": "2024-02-08T16:19:38.797312Z", + "iopub.status.busy": "2024-02-08T16:19:38.796865Z", + "iopub.status.idle": "2024-02-08T16:19:38.815322Z", + "shell.execute_reply": "2024-02-08T16:19:38.813949Z", + "shell.execute_reply.started": "2024-02-08T16:19:38.797267Z" + } + }, + "source": [ + "
\n", + "注意:新版本的 chatglm3-6b 模型在微调过程中需要更多显存 (点击查看解决方法)\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
现象如果在微调 chatglm3-6b 模型时,执行 trainer.train() 后瞬间出现 “OutOfMemoryError: CUDA out of memory.”(显存不足)错误,请考虑指定一个旧版本进行微调。
原因从2024年2月6日后发布的 chatglm3-6b 模型开始,调用 torch.utils.checkpoint.checkpoint() 方法时,use_reentrant 参数的默认值由原来的 True 改为 False。这导致在训练时保存更多的梯度参数以加快反向传播计算速度,同时占用更多显存。此外,新代码覆盖了基类 PreTrainedModel 中的 gradient_checkpointing_enable() 方法,导致无法通过梯度检查点来减少显存占用。有关详细的代码更改,请查看 Commit 37fe000
方案在加载 Tokenizer 和 Model 时,通过添加 revision 参数指定一个旧版本。示例代码如下:
\n", + "tokenizer = AutoTokenizer.from_pretrained(......, revision='b098244')
\n", + "model = AutoModel.from_pretrained(......, revision='b098244')
\n", + "
" + ] + }, { "cell_type": "code", "execution_count": 1, @@ -923,7 +950,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.7" } }, "nbformat": 4,