? ? ? ? 本文目的是讓大家先熟悉模型的部署,簡單入門;所以只需要很小的算力,單臺服務器 單GPU顯卡(顯存不低于12GB),操作系統(tǒng)需要安裝 Ubuntu 18.04。
1 服務器&操作系統(tǒng)?
? ? ? ? 1.1服務器的準備
? ? ? ? 準備一臺服務器 單張英偉達GPU顯卡(顯存不低于12GB),操作系統(tǒng)需要安裝 Ubuntu 18.04 (具體安裝過程忽略)。 重裝系統(tǒng)前注意備份現(xiàn)有存儲上的相關重要數(shù)據(jù)。?GPU顯卡驅(qū)動先不安裝; 后續(xù)介紹驅(qū)動和CUDA的安裝步驟。
????????如果手上沒有相應的服務器硬件設備、可以購買帶GPU的云服務器, 以下可供選擇參考。
?上云精選_云服務器秒殺_開發(fā)者上云推薦-騰訊云騰訊云推出云產(chǎn)品限時特惠搶購活動:2C2G云服務器9元/月起;還有短信、CDN、COS等熱門云產(chǎn)品限時特惠...https://cloud.tencent.com/act/pro/seckill_season?from=20210
地域選擇國內(nèi)適合的城市;? ?預裝鏡像為 Ubuntu 18.04
????????購買后一般云廠商會自動安裝顯卡的驅(qū)動和CUDA , 因為目前大部分的項目對 cuda 11.7 和 11.8 版本兼容的比較好,后續(xù)我們要指定安裝特定的版本; 所以如果云主機已經(jīng)預裝了GPU驅(qū)動,我們需要卸載。 如果不了解卸載的指令,可以在控制臺 點擊“重裝系統(tǒng)”;?
????????然后 注意 不要勾選后臺自動安裝 GPU 驅(qū)動; 這樣重置后就是一臺干凈的 Ubuntu18.04的系統(tǒng),且沒有安裝GPU的驅(qū)動。
1.2系統(tǒng)工具和環(huán)境?
???安裝一些基礎的相關軟件工具
sudo apt update
sudo apt install -y vim git wget curl net-tools language-pack-zh-hans language-pack-en
中文環(huán)境
echo '
LANG="en_US.utf8"; export LANG
LANGUAGE="en_US.utf8"; export LANGUAGE
LC_ALL="en_US.utf8"; export LC_ALL
LC_CTYPE="en_US.utf8"; export LC_CTYPE
SUPPORTED=en_US.UTF8:en_US:en; export SUPPORTED
TZ="Asia/Shanghai"; export TZ
' >> ~/.profile
source ~/.profile
locale
#確認當前是UTF8
2 安裝? 顯卡驅(qū)動? 和? CUDA
2.1 確認操作系統(tǒng)當前沒有安裝驅(qū)動?
????????確認當前系統(tǒng)沒有安裝GPU顯卡驅(qū)動, 且沒有加載nvidia相關模塊
lsmod | grep nvidia
sudo lsof /dev/nvidia*
#以上命令 應該沒有輸出 nvidia 等字樣的信息
?????????????????
?2.2?如何安裝指定版本的顯卡驅(qū)動(可選)
? ? ? ? 后續(xù) 2.3 中 cuda 安裝包中含有配合的顯卡驅(qū)動,可以一步安裝; 如果需要指定安裝和 cuda 包中不同版本的驅(qū)動,可參考本節(jié), 否則建議直接跳至 2.3 節(jié)。?
根據(jù)顯卡型號下載適合的驅(qū)動
Official Drivers | NVIDIADownload latest drivers for NVIDIA products including GeForce, TITAN, NVIDIA RTX, Data Center, GRID and more.https://www.nvidia.com/download/index.aspxUnix Drivers | NVIDIA
Linux AMD64 Display Driver Archive | NVIDIA
?
?下載并安裝顯卡驅(qū)動 (需要 root 權限)
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/535.98/NVIDIA-Linux-x86_64-535.98.run
sudo sh ./NVIDIA-Linux-x86_64-535.98.run
tail /var/log/nvidia-installer.log
2.3?安裝 cuda (可一并安裝顯卡驅(qū)動)?
CUDA Toolkit Archive | NVIDIA DeveloperPrevious releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production drivers appropriate for your hardware configuration.https://developer.nvidia.com/cuda-toolkit-archive下載 cuda 11.8?版本安裝包 (內(nèi)含 顯卡驅(qū)動)
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
CUDA Toolkit 11.8 Downloads | NVIDIA DeveloperResources CUDA Documentation/Release NotesMacOS Tools Training Sample Code Forums Archive of Previous CUDA Releases FAQ Open Source PackagesSubmit a BugTarball and Zip Archive Deliverableshttps://developer.nvidia.com/cuda-11-8-0-download-archive
安裝 cuda 需要 root 權限;?
如跳過上節(jié)沒有安裝顯卡驅(qū)動則:要勾選安裝驅(qū)動項;?否則 , 要去掉安裝驅(qū)動的勾選項
sudo sh cuda_11.8.0_520.61.05_linux.run
最后運行?nvidia-smi 確認 驅(qū)動 和 cuda 安裝成功
tail /var/log/cuda-installer.log
nvidia-smi
注意 : 使用 nvidia-smi? 查看??CUDA 版本必須是 11.8
3 準備? Python 環(huán)境? (安裝conda & 配置國內(nèi)鏡像源)
????????3.1安裝 conda
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh
sh Miniconda3-py39_4.12.0-Linux-x86_64.sh
#都回答 yes
source ~/.bashrc
????????3.2?為 pip 配置國內(nèi)鏡像源
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/simple
pip config set install.trusted-host mirrors.tuna.tsinghua.edu.cn
????????3.3?為 conda 配置國內(nèi)鏡像源
????????編輯當前用戶下的 .condarc 文件? ?
conda config --set show_channel_urls yes
vim ~/.condarc
????????替換成如下內(nèi)容:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
?????????清除索引緩存
conda clean --all --yes
conda clean -i
????????3.4 以下國內(nèi)常用的 pip 鏡像源 僅供參考
清華:https://mirrors.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中國科技大學: https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣:http://pypi.douban.com/simple/
????????3.5 常用conda命令 僅供參考
創(chuàng)建虛擬環(huán)境:conda create -n 環(huán)境名稱?python=版本號
查看已有虛擬環(huán)境:conda env list
激活虛擬環(huán)境:conda activate?環(huán)境名稱
刪除虛擬環(huán)境:conda remove -n 環(huán)境名稱 --all
查看當前環(huán)境下已安裝的包:conda list
導出當前環(huán)境下的包:conda env export > environment.yml
根據(jù)導出的包安裝環(huán)境:conda env create -f environment.yml
安裝包:conda install 包名
安裝下載到本地的包:conda install --use-local??包路徑
卸載當前環(huán)境下包:conda uninstall 包名
卸載指定虛擬環(huán)境中的包:conda remove --name 環(huán)境名稱 包名
?
4 創(chuàng)建環(huán)境 安裝相關包
????????4.1 Conda創(chuàng)建一個新的環(huán)境
conda create -n llm python=3.10.9
conda activate llm
? ? ? ? ?4.2安裝 Web 交互 UI 工程?text-generation-webui
GitHub - oobabooga/text-generation-webui: A Gradio web UI for Large Language Models. Supports transformers, GPTQ, llama.cpp (ggml), Llama models.A Gradio web UI for Large Language Models. Supports transformers, GPTQ, llama.cpp (ggml), Llama models. - GitHub - oobabooga/text-generation-webui: A Gradio web UI for Large Language Models. Supports transformers, GPTQ, llama.cpp (ggml), Llama models.https://github.com/oobabooga/text-generation-webui
wget https://github.com/oobabooga/text-generation-webui/releases/download/installers/oobabooga_linux.zip
unzip oobabooga_linux.zip
cd oobabooga_linux/
conda activate llm
bash ./start_linux.sh
?bash ./start_linux.sh 首次運行會下載大量數(shù)據(jù), 時間較長。
成功后會 默認監(jiān)聽 7860 端口 開啟web服務,如下所示:
? ? ? ????????
?5 語言?交互 UI?
? ? ? ? 5.1進入 web 交互頁面
conda activate llm
HF_TOKEN="hf_XXXXXXXXXXXXXXXXXXXXXX" # HuggingFace? 的?Access Tokens
export HF_TOKEN
./start_linux.sh
./start_linux.sh 開啟web服務,成功后會顯示:
使用 SSH Tunnel 建立隧道 將 服務器的 7860 端口 映射到本地, 然后使用瀏覽器打開 。
?????????5.2 使用交互頁面自動下載模型
? ? ? ??首先需要在 Model 模型頁簽中下載一個Llama2模型 。
????????輸入模型名稱路徑:“FlagAlpha/Llama2-Chinese-7b-Chat”
? ? ? ? 然后點擊下載按鈕
注意:如果下載某些模型 出現(xiàn) Http 401 錯誤,則需要設置? HuggingFace? 的?Access Tokens
需要登錄?Hugging Face – The AI community building the future.
在設置頁面的??Access Tokens 中創(chuàng)建? Tokens?并復制。然后在 ./start_linux.sh 啟動前 設置“HF_TOKEN” 環(huán)境變量 。
????????另外,可以在 HuggingFace 上尋找其它開放的大預言模型, 如果使用 13B 或者 更大的模型推理,依據(jù)參數(shù)規(guī)??赡苄枰叩腉PU顯存,甚至多張GPU來加載運行。?Hugging Face – The AI community building the future.We’re on a journey to advance and democratize artificial intelligence through open source and open science.https://huggingface.co/??
? ????????5.3手動下載 Llama2 模型 (可選)
模型文件建議去官網(wǎng)下載,? 國內(nèi)Llama2 下載地址 僅供參考
-
Llama2-7B官網(wǎng)版本:迅雷云盤
-
Llama2-7B-Chat官網(wǎng)版本:迅雷云盤
-
Llama2-13B官網(wǎng)版本:迅雷云盤
-
Llama2-13B-Chat官網(wǎng)版本:迅雷云盤
-
Llama2-7B Hugging Face版本:迅雷云盤
-
Llama2-7B-Chat Hugging Face版本:迅雷云盤
-
Llama2-13B Hugging Face版本:迅雷云盤
-
Llama2-13B-Chat Hugging Face版本:迅雷云盤
-
Llama2-70B-Chat Hugging Face版本:迅雷云盤
另外 Llama2 中文模型 供參考選擇? , 通過訪問Llama2中文社區(qū)鏈接 僅供參考:
GitHub - FlagAlpha/Llama2-Chinese: Llama中文社區(qū),最好的中文Llama大模型,完全開源可商用Llama中文社區(qū),最好的中文Llama大模型,完全開源可商用. Contribute to FlagAlpha/Llama2-Chinese development by creating an account on GitHub.https://github.com/FlagAlpha/Llama2-Chinese??將下載好的模型文件目錄放到?/data/ai/oobabooga_linux/text-generation-webui/models中
????????5.4加載模型
????????在 Model 模型頁簽中 加載模型 。?
? ? ? ? 如下圖: 刷新現(xiàn)有模型、 下拉菜單選中模型,點擊 Load 加載 模型 , 成功加載后會顯示:? “Successfully loaded?FlagAlpha_Llama2-Chinese-7b-Chat
.”
文章來源:http://www.zghlxwxcb.cn/news/detail-712890.html
????????5.3使用 Chat 頁簽 Web 交互 UI
文章來源地址http://www.zghlxwxcb.cn/news/detail-712890.html
到了這里,關于中文大語言模型 Llama-2 7B(或13B) 本地化部署 (國內(nèi)云服務器、GPU單卡16GB、中文模型、WEB頁面TextUI、簡單入門)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!