<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[使用 chatGLM 官方示例做微调]]></title><description><![CDATA[<ol>
<li>环境<br />
Linux 云平台 autodl 花费 10元左右<br />
<img src="/assets/uploads/files/1688189122161-8d52ace9-8ac7-46b9-b8d0-c0cf8624aebe-image.png" alt="8d52ace9-8ac7-46b9-b8d0-c0cf8624aebe-image.png" class=" img-responsive img-markdown" /><br />
配置是24G的显存，3090显卡。</li>
</ol>
<p dir="auto">为什么选择这款配置？因为我在本机6G 显卡折腾好久没有成功。 用的 6b-int4 版本，网上都说可以成功。折腾我好久。所以干脆用云24G的实验了。</p>
<ol start="2">
<li>下载源代码</li>
</ol>
<pre><code>git clone https://github.com/THUDM/ChatGLM-6B
cd ChatGLM-6B
pip3 install -r requirements.txt
</code></pre>
<ol start="3">
<li>进入微调</li>
</ol>
<pre><code>cd  ptuning
pip3 install rouge_chinese nltk jieba datasets
</code></pre>
<ol start="4">
<li>下载 需要例子数据</li>
</ol>
<pre><code>wget -O AdvertiseGen.tar.gz https://cloud.tsinghua.edu.cn/f/b3f119a008264b1cabd1/?dl=1
tar xvf AdvertiseGen.tar.gz
</code></pre>
<p dir="auto">下载后需要展开。</p>
<ol start="5">
<li>修改 源文件<br />
为什么要修改，如果不修改 总是 按照多gpu处理，我没有多gpu，并且即使是多GPU，也需要修改代码<br />
这里有讨论<br />
<a href="https://github.com/THUDM/ChatGLM-6B/issues/1169" rel="nofollow ugc">https://github.com/THUDM/ChatGLM-6B/issues/1169</a></li>
</ol>
<p dir="auto">我的方法如下：</p>
<pre><code>ptuning/main.py
59
60 training_args.local_rank = -1
61
增加上面这句
</code></pre>
<ol start="6">
<li>开始 工作<br />
P-Tuning v2</li>
</ol>
<pre><code>bash train.sh
</code></pre>
<ol start="7">
<li>如果你需要 微调<br />
24G 显存不够<br />
需要再修改<br />
增加 Lora</li>
</ol>
<pre><code>pip3 install deepspeed
vim ds_train_finetune.sh
    --per_device_train_batch_size 4 \ 修改为1
 --num_gpus=4 修改为1 
</code></pre>
<p dir="auto">vim <a href="http://main.py" rel="nofollow ugc">main.py</a></p>
<pre><code>头部 增加 ：
from peft import get_peft_model, LoraConfig, TaskType

第 136行 增加 下面的代码：

    peft_config = LoraConfig(
        task_type=TaskType.CAUSAL_LM,
        inference_mode=False,
        r=finetune_args.lora_rank,
        lora_alpha=32,
        lora_dropout=0.1,
        target_modules=["query_key_value"],
    )
    model = get_peft_model(model, peft_config)

</code></pre>
<p dir="auto">以上可以 在24G显存测试通过。</p>
]]></description><link>http://localhost:4567/topic/178/使用-chatglm-官方示例做微调</link><generator>RSS for Node</generator><lastBuildDate>Mon, 18 May 2026 11:16:33 GMT</lastBuildDate><atom:link href="http://localhost:4567/topic/178.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Jul 2023 05:37:38 GMT</pubDate><ttl>60</ttl></channel></rss>