本次学习了模型demo的部署
在这几个demo前学习的必备技能就是模型的下载,其余都是linux的使用了,当然还有配置本地端口
模型下载
教程中模型下载分为两个途径:从huggingface跟从魔搭平台进行下载
我们可以使用git命令,当然也可以使用两个平台都有的下载工具包
huggingface
使用 Hugging Face 官方提供的 huggingface-cli 命令行工具。安装依赖:
pip install -U huggingface_hub
然后新建 python 文件,填入以下代码,运行即可。
resume-download:断点续下
local-dir:本地存储路径。(linux 环境下需要填写绝对路径)
import os
os.system('huggingface-cli download --resume-download internlm/internlm-chat-7b --local-dir your_path')
以下内容将展示使用 huggingface_hub 下载模型中的部分文件
import os
from huggingface_hub import hf_hub_download # Load model directly
hf_hub_download(repo_id="internlm/internlm-7b", filename="config.json")
ModelScope
使用 modelscope 中的 snapshot_download 函数下载模型,第一个参数为模型名称,参数 cache_dir 为模型的下载路径。
注意:cache_dir 最好为绝对路径。
安装依赖:
pip install modelscope==1.9.5
pip install transformers==4.35.2
在当前目录下新建 python 文件,填入以下代码,运行即可。
import torch
from modelscope import snapshot_download, AutoModel, AutoTokenizer
import os
model_dir = snapshot_download('Shanghai_AI_Laboratory/internlm-chat-7b', cache_dir='your path', revision='master')
我们使用huggingface的下载工具在本地下载了一个文件
本地端口配置
我们在服务器上部署的web都不能直接使用,所以我们想要让端口映射到本地端口
首先我们打开自己电脑上的powershell,输入此命令
ssh-keygen -t rsa
然后公钥就被存储到指定的位置,如果不指定位置就连续点击回车
然后我们
cat ~\.ssh\id_rsa.pub
就查看到了我们想要的公钥
直接填写到我们的书生浦语首页ssh配置界面就可以了
InternLM-Chat-7B 智能对话 Demo
这段配置按照教程没有出现任何问题
Lagent 智能体工具调用 Demo
浦语·灵笔图文理解创作 Demo
出现了一些小问题,发现并没有映射到本地端口,应该是gradio的问题?
然后就是路径的问题导致图片加载不成功