本地部署 torchchat的详细过程
TorchChat 是一个小型代码库,展示了无缝运行大型语言模型 (LLMs) 的能力。使用 torchchat,您可以在自己的 (C/C++) 应用程序(桌面或服务器)以及 iOS 和 Android 上使用 Python 运行LLMs。
conda create -n torchchat python=3.12 -yconda activate torchchat
git clone https://github.com/pytorch/torchchat.git
./install_requirements.sh
(20240816时点)我的wls-ubuntu环境会报以下错误,
+ 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
登录 Hugging Face,完成此操作后,torchchat 将能够从 Hugging Face 下载模型工件。
huggingface-cli login
查看现在支持的模型,
# python3 torchchat.py listModel Aliases Downloaded--------------------------------------- ------------------------------------------- -----------meta-llama/llama-2-7b-hf llama2-base, llama2-7bmeta-llama/llama-2-7b-chat-hf llama2, llama2-chat, llama2-7b-chatmeta-llama/llama-2-13b-chat-hf llama2-13b-chatmeta-llama/llama-2-70b-chat-hf llama2-70b-chatmeta-llama/meta-llama-3-8b llama3-basemeta-llama/meta-llama-3-8b-instruct llama3, llama3-chat, llama3-instructmeta-llama/meta-llama-3-70b-instruct llama3-70bmeta-llama/meta-llama-3.1-8b llama3.1-basemeta-llama/meta-llama-3.1-8b-instruct llama3.1, llama3.1-chat, llama3.1-instruct Yesmeta-llama/meta-llama-3.1-70b-instruct llama3.1-70bmeta-llama/codellama-7b-python-hf codellama, codellama-7bmeta-llama/codellama-34b-python-hf codellama-34bmistralai/mistral-7b-v0.1 mistral-7b-v01-basemistralai/mistral-7b-instruct-v0.1 mistral-7b-v01-instructmistralai/mistral-7b-instruct-v0.2 mistral, mistral-7b, mistral-7b-instructopenlm-research/open_llama_7b open-llama, open-llama-7bstories15mstories42mstories110m
下载模型,
python torchchat.py download llama3.1
python3 torchchat.py chat llama3.1
此模式允许您使用浏览器中的 UI 与模型聊天:运行命令会自动在浏览器中打开一个选项卡。
streamlit run torchchat.py -- browser llama3.1
完结!
reference: https://github.com/pytorch/torchchat
本地部署 torchchat的详细过程