<?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</title>
	<atom:link href="http://www.cslog.cn/tag/llama/feed/zh-hant/" 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/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/zh-hant/#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/zh-hant/">繼續閱讀 <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/zh-hant/">http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/chinese-llama-alpaca-text-generation-webui-llama-cpp/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- WP Chinese Conversion Full Page Converted -->