ChatGLM2 大模型微调过程中遇到的一些坑及解决方法(更新中)

1. 模型下载问题

复制代码
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like bert-base-uncased is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.

模型默认是从huggingface上下载的,需要科学上网。挂上梯子后即可下载,注意模型都帮你较大,会消耗很多流量。

2. 模型保存地址

下载后,会占用C盘大量空间,对于重复下载的模型文件,可以进行删除。以下是其存储路径。

Windows系统
复制代码
C:\Users\你的用户名\.cache\huggingface
Linux系统
复制代码
       ~/.cache/huggingface/
3. 模型无法量化

默认情况下,模型以 FP16 精度加载,运行上述代码需要大概 13GB 显存。如果你的 GPU 显存有限,可以尝试以量化方式加载模型,使用方法如下:

python 复制代码
model = AutoModel.from_pretrained("THUDM/chatglm2-6b-int4",trust_remote_code=True).cuda()
peft_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM, inference_mode=False,
    r=8,
    lora_alpha=32, lora_dropout=0.1,
)

model = get_peft_model(model, peft_config)

出现以下错误:

复制代码
ValueError: Target module QuantizedLinear() is not supported. Currently, only `torch.nn.Linear` and `Conv1D` are supported.

原因:以int4量化加载的模型是不支持进行微调的。

4. 分词器

以chatglm为例,有"chatglm2-6b" "chatglm2-6b-int8" "chatglm2-6b-int4" 三个版本,但是分词器tokenizer是共用的,不受模型量化加载方式改变。所以我们在加载tokenizer的时候,只需设置就可以了:

python 复制代码
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True)
5. int-8量化的模型无法下载

在chatglm第一版里面,是提供int4 int8和fp16,三个版本的文件的,但是在chatglm2里,可以看到只给了fp16和int4两个版本的文件。

相关推荐
Lei活在当下5 小时前
【AI手记系列-2026/6/18】iSparto & Harness,Caveman 以及AI时代的生存指南
人工智能·llm·openai
冬奇Lab7 小时前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
冬奇Lab7 小时前
Agent 系列(22):Context Engineering 深度——三种上下文管理策略的量化对比
人工智能·agent
hboot7 小时前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
程序员cxuan7 小时前
DeepSeek 杀入多模态,识图功能正式上线!
人工智能·后端·程序员
米小虾9 小时前
告别单打独斗:2026年多Agent协作架构实战指南
人工智能·agent
IT_陈寒10 小时前
SpringBoot这个自动配置坑我跳了三次
前端·人工智能·后端
Larcher10 小时前
AI Loop:让AI像人一样自主完成任务的核心机制
javascript·人工智能·设计模式
牧艺10 小时前
从零到协同:构建类飞书在线文档系统的五个技术重难点
前端·人工智能