本地部署 torchchat
0. 引言
torchchat 是一个小型代码库,展示了无缝运行大型语言模型 (llms) 的能力。使用 torchchat,您可以在自己的 (c/c++) 应用程序(桌面或服务器)以及 ios 和 android 上使用 python 运行llms。
1. 本地部署
1-1. 创建虚拟环境
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环境会报以下错误,
+ 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
查看现在支持的模型,
# 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
完结!
reference: https://github.com/pytorch/torchchat
到此这篇关于本地部署 torchchat的文章就介绍到这了,更多相关本地部署 torchchat内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论