<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>船长日志 &#187; llama.cpp</title>
	<atom:link href="http://www.cslog.cn/tag/llama-cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cslog.cn</link>
	<description>最让我激动的是不知道下一个星球上能发现什么...</description>
	<lastBuildDate>Wed, 30 Jul 2025 16:06:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>中文LLaMA Alpaca大语言模型在text-generation-webui和llama.cpp上的部署</title>
		<link>http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/</link>
		<comments>http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/#comments</comments>
		<pubDate>Fri, 05 May 2023 17:19:25 +0000</pubDate>
		<dc:creator>船长</dc:creator>
				<category><![CDATA[人工智能]]></category>
		<category><![CDATA[alpaca]]></category>
		<category><![CDATA[llama]]></category>
		<category><![CDATA[llama.cpp]]></category>
		<category><![CDATA[大语言模型]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1344</guid>
		<description><![CDATA[中文LLaMA模型和指令精调的Alpaca大模型在text-generation &#8230; <a href="http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>
<p>中文LLaMA模型和指令精调的Alpaca大模型在text-generation-webui和llama.cpp上的部署<br />
LLaMA是facebook的meta公司放出来的大语言模型，这个模型的中文能力非常差。<a href="https://github.com/ymcui/Chinese-LLaMA-Alpaca" rel="noopener" target="_blank">Chinese-LLaMA-Alpaca</a>在原版LLaMA的基础上扩充了中文词表并使用了中文数据进行二次预训练，进一步提升了中文基础语义理解能力。目前已开源的模型版本：7B（标准版、Plus版）、13B（标准版）。这些版本可以在16G，甚至可以在8G内存的个人电脑上部署。似乎不用显卡。今天我在16G内存的个人笔记上部署了。这是记录。</p>
</div>
<div>
<p>由于笔记本电脑只有16G，所以我选择是LLaMA/Alpaca Plus版本（7B）版本。7B的模型占内存13GB，8bit量化后是7.8GB。</p>
</div>
<div>
<div></div>
<h2 data-heading="模型下载与合并">模型下载与合并</h2>
</div>
<div>
<p>部署需要<a href="https://github.com/facebookresearch/llama" rel="noopener" target="_blank">原版LLaMA模型</a>和中文LLaMA模型Chinese-LLaMA-Plus-7B与中文Alpaca模型Chinese-Alpaca-Plus-7B。三个模型要合并成一个模型。<br />
页面也提供了Colab在线合并的方式，在线合并的话就不用下载上面的三个模型，只要下载合并好的模型就可以了。</p>
<p><span id="more-1344"></span><br />
我的Colab免费账号内存比较低，所以我选择了下载模型后<a href="https://github.com/ymcui/Chinese-LLaMA-Alpaca/wiki/%E6%89%8B%E5%8A%A8%E6%A8%A1%E5%9E%8B%E5%90%88%E5%B9%B6%E4%B8%8E%E8%BD%AC%E6%8D%A2" rel="noopener" target="_blank">本地合并</a>。</p>
</div>
<div>
<p>注意，本地合并过程中要用到一个protobuf 3.20.0库。网页没有提及。</p>
</div>
<div>
<p>说是合并要用到13G内存，但在我的16G内存笔记上合并过程没有遇到问题。</p>
</div>
<div>
<div></div>
<h2 data-heading="text-generation-webui部署">text-generation-webui部署</h2>
</div>
<div>
<p><a href="https://github.com/oobabooga/text-generation-webui" rel="noopener" target="_blank">text-generation-webui</a>是一个网页界面的大语言模型工具。部署<a href="https://github.com/ymcui/Chinese-LLaMA-Alpaca/wiki/%E4%BD%BF%E7%94%A8text-generation-webui%E6%90%AD%E5%BB%BA%E7%95%8C%E9%9D%A2" rel="noopener" target="_blank">参看教程</a>。<br />
注意这个教程是针对没有合并模型的。如果模型合并了，只要加载合并好的一个模型就可以运行了。<br />
<code>python server.py --model llama-7b-hf --cpu</code></p>
<p><code></code><img class="aligncenter size-medium wp-image-1345" title="2023-05-05_181823" src="http://www.cslog.cn/wp-content/uploads/2023/05/2023-05-05_181823-502x600.png" alt="" width="502" height="600" /><br />
不知道是什么原因，我测试发现text generation webui的反应非常慢。发个你好要几分钟才回复。让它写个诗，几小时只写了几行。几乎没有可用性。不知道是不是我没有开启GPU模式的原因。</p>
</div>
<div>
<div></div>
<h2 data-heading="llama.cpp部署">llama.cpp部署</h2>
</div>
<div>
<p>text generation webui太卡了，我转向<a href="https://github.com/ggerganov/llama.cp" rel="noopener" target="_blank">llama.cpp</a>。<a href="https://github.com/ymcui/Chinese-LLaMA-Alpaca/wiki/llama.cpp%E9%87%8F%E5%8C%96%E9%83%A8%E7%BD%B2" rel="noopener" target="_blank">参考教程</a>。<br />
我是在windows 11下部署，所以要先安装<a href="https://github.com/skeeto/w64devkit/releases" rel="noopener" target="_blank">w64devkit</a>。在它里面运行make。然后参考上面的教程就可以了。<br />
我先对模型进行了8bit的量化。<br />
<code>quantize.exe ./zh-models/chinese_alpaca_plus_7B_pth/ggml-model-f16.bin ./zh-models/chinese_alpaca_plus_7B_pth/ggml-model-q8_0.bin 7</code></p>
</div>
<div>
<p>然后启动<br />
<code>main.exe -m zh-models/chinese_alpaca_plus_7B_pth/ggml-model-q8_0.bin --color -f prompts/alpaca.txt -ins -c 2048 --temp 0.2 -n 256 --repeat_penalty 1.3</code></p>
<p><img class="aligncenter size-medium wp-image-1346" title="中文LLaMA Alpaca在llama.cpp的表现" src="http://www.cslog.cn/wp-content/uploads/2023/05/2023-05-05_191558-720x525.png" alt="" width="720" height="525" /></p>
<p>llama.cpp的响应速度非常快。差不多几秒就回复了。但似乎回复的结果不是非常好，很多错误。看来这个模型的可用性还不是很高。而且回复经常中断。</p>
</div>
<div style="margin-top: 15px; font-style: italic">
<p>转载请注明: 转自<a href="http://www.cslog.cn/">船长日志</a>, 本文链接地址: <a href="http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/">http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
