本地部署 torchchat的詳細(xì)過程
本地部署 torchchat
0. 引言
TorchChat 是一個小型代碼庫,展示了無縫運行大型語言模型 (LLMs) 的能力。使用 torchchat,您可以在自己的 (C/C++) 應(yīng)用程序(桌面或服務(wù)器)以及 iOS 和 Android 上使用 Python 運行LLMs。
1. 本地部署
1-1. 創(chuàng)建虛擬環(huán)境
conda create -n torchchat python=3.12 -y conda activate torchchat
1-2. 克隆代碼
git clone https://github.com/pytorch/torchchat.git
1-3. 安裝依賴模塊
./install_requirements.sh
(20240816時點)我的wls-ubuntu環(huán)境會報以下錯誤,
+ python scripts/patch_triton.py /mnt/e/workspace/torchchat/scripts/patch_triton.py:20: SyntaxWarning: invalid escape sequence '\s' new_match = 'self.src = self.src[re.search(r"^def\s+\w+\s*\(", self.src, re.MULTILINE).start():]'
臨時解決方法,
vi /mnt/e/workspace/torchchat/scripts/patch_triton.py --- # new_match = 'self.src = self.src[re.search(r"^def\s+\w+\s*\(", self.src, re.MULTILINE).start():]' new_match = r'self.src = self.src[re.search(r"^def\s+\w+\s*\(", self.src, re.MULTILINE).start():]' ---
重新運行,
./install_requirements.sh
1-4. 下載模型
登錄 Hugging Face,完成此操作后,torchchat 將能夠從 Hugging Face 下載模型工件。
huggingface-cli login
查看現(xiàn)在支持的模型,
# python3 torchchat.py list Model Aliases Downloaded --------------------------------------- ------------------------------------------- ----------- meta-llama/llama-2-7b-hf llama2-base, llama2-7b meta-llama/llama-2-7b-chat-hf llama2, llama2-chat, llama2-7b-chat meta-llama/llama-2-13b-chat-hf llama2-13b-chat meta-llama/llama-2-70b-chat-hf llama2-70b-chat meta-llama/meta-llama-3-8b llama3-base meta-llama/meta-llama-3-8b-instruct llama3, llama3-chat, llama3-instruct meta-llama/meta-llama-3-70b-instruct llama3-70b meta-llama/meta-llama-3.1-8b llama3.1-base meta-llama/meta-llama-3.1-8b-instruct llama3.1, llama3.1-chat, llama3.1-instruct Yes meta-llama/meta-llama-3.1-70b-instruct llama3.1-70b meta-llama/codellama-7b-python-hf codellama, codellama-7b meta-llama/codellama-34b-python-hf codellama-34b mistralai/mistral-7b-v0.1 mistral-7b-v01-base mistralai/mistral-7b-instruct-v0.1 mistral-7b-v01-instruct mistralai/mistral-7b-instruct-v0.2 mistral, mistral-7b, mistral-7b-instruct openlm-research/open_llama_7b open-llama, open-llama-7b stories15m stories42m stories110m
下載模型,
python torchchat.py download llama3.1
1-5. 運行模型
python3 torchchat.py chat llama3.1
1-6. 使用 UI
此模式允許您使用瀏覽器中的 UI 與模型聊天:運行命令會自動在瀏覽器中打開一個選項卡。
streamlit run torchchat.py -- browser llama3.1
完結(jié)!
reference: https://github.com/pytorch/torchchat
到此這篇關(guān)于本地部署 torchchat的文章就介紹到這了,更多相關(guān)本地部署 torchchat內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!