8G显存玩转书生大模型Demo
github链接:https://github.com/InternLM/Tutorial
第一步创建一个环境
conda create -n demo python=3.10 -y
第二步激活环境且安装其他依赖
conda activate demo
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia -y
pip install transformers==4.38
pip install sentencepiece==0.1.99
pip install einops==0.8.0
pip install protobuf==5.27.2
pip install accelerate==0.33.0
pip install streamlit==1.37.0
第三步cli_demo来部署 InternLM2-Chat-1.8B 模型
mkdir -p /root/demo
touch /root/demo/cli_demo.py
复制github中的cli_demo的代码并运行
第四步在web_demo中部署 InternLM2-Chat-1.8B 模型
首先将教程仓库 clone 到本地
git clone https://github.com/InternLM/Tutorial.git
之后执行如下代码来在web上来部署模型
cd /root/demo
streamlit run /root/demo/Tutorial/tools/streamlit_demo.py --server.address 127.0.0.1 --server.port 6006
在开发机上运行好上面代码之后,就要在本机的PowerShell来设置我们的端口对接上
ssh -CNg -L 6006:127.0.0.1:6006 root@ssh.intern-ai.org.cn -p 你的 ssh 端口号
效果如图所示
第五步利用LMDeploy来部署 InternLM-XComposer2-VL-1.8B 模型
首先激活环境和安装依赖
conda activate demo
pip install lmdeploy[all]==0.5.1
pip install timm==1.0.7
安装好之后,我们运行如下代码使用 LMDeploy 启动一个与 InternLM-XComposer2-VL-1.8B 模型交互的 Gradio 服务。
lmdeploy serve gradio /share/new_models/Shanghai_AI_Laboratory/internlm-xcomposer2-vl-1_8b --cache-max-entry-count 0.1
第六步LMDeploy 部署 InternVL2-2B 模型
我们运行如下代码来启动 InternVL2-2B 模型的 Gradio 服务。
lmdeploy serve gradio /share/new_models/OpenGVLab/InternVL2-2B --cache-max-entry-count 0.1