这里我使用InternStudio中的 A100(1/4) * 2 机器和internlm-xcomposer-7b
模型部署一个图文理解创作 Demo 。
一、环境准备
选择 A100(1/4)*2 的配置:
我的开发机列表:
打开刚刚租用服务器的进入开发机
,并在终端输入 bash
命令,进入 conda
环境,接下来就是安装依赖。
进入 conda
环境之后,使用以下命令从本地克隆一个已有的pytorch 2.0.1
的环境:
conda create --name xcomposer-demo --clnotallow=/root/share/conda_envs/internlm-base
然后使用以下命令激活环境:
conda activate xcomposer-demo
接下来运行以下命令,安装 transformers
、gradio
等依赖包。请严格安装以下版本安装!
pip install transformers==4.33.1 timm==0.4.12 sentencepiece==0.1.99 gradio==3.44.4 markdown2==2.4.10 xlsxwriter==3.1.2 einops accelerate
二、模型下载
InternStudio平台的 share
目录下已经为我们准备了全系列的 InternLM
模型,所以我们可以直接复制即可。使用如下命令复制:
mkdir -p /root/model/Shanghai_AI_Laboratory
cp -r /root/share/temp/model_repos/internlm-xcomposer-7b /root/model/Shanghai_AI_Laboratory
三、代码准备
在 /root/code
git clone InternLM-XComposer
仓库的代码:
cd /root/code
git clone https://gitee.com/internlm/InternLM-XComposer.git
cd /root/code/InternLM-XComposer
git checkout 3e8c79051a1356b9c388a6447867355c0634932d # 最好保证和教程的 commit 版本一致
四、Demo运行
在终端运行以下代码:
cd /root/code/InternLM-XComposer
python examples/web_demo.py \
--folder /root/model/Shanghai_AI_Laboratory/internlm-xcomposer-7b \
--num_gpus 1 \
--port 6006
注意前面的环境问题,使用的另外一个环境而不是base,这里便会出现问题:
输入命令正确执行:
将端口映射到本地。(注意:需要在本地终端输入以下指令 .6006
是在服务器中打开的端口,而 33090
是根据开发机的端口进行更改。
ssh -CNg -L 6006:127.0.0.1:6006 [email protected] -p 33090
)
在本地浏览器输入 http://127.0.0.1:6006
可看见加载界面:
进入该界面:
以提示词“又见敦煌”来输入:
然后它是会下载图像加载出来:
最下面还会有保存功能:
再以“星链新闻稿”来输入:
英文输入“Shanghai Travel Guide in English”来生成:
选取一小部分来感受:
Shanghai is the largest city in China and one of the most populous cities in the world, with a population of over 24 million people. The city is known for its modern skyscrapers, bustling financial district, and vibrant nightlife. Shanghai is also home to some of the country's top tourist attractions, including the Bund, Yuyuan Garden, and the Oriental Pearl Tower. In this guide, we'll provide you with all the information you need to plan your trip to Shanghai, including tips on where to stay, what to do, and how to get around.
Where to Stay in Shanghai
When it comes to finding a place to stay in Shanghai, there are plenty of options to choose from. If you're looking for a luxury experience, consider staying at one of the city's five-star hotels, such as the Fairmont Peace Hotel or the Waldorf Astoria Shanghai on the Bund. These hotels offer stunning views of the city skyline, luxurious amenities, and impeccable service.
If you're looking for something more budget-friendly, there are plenty of hostels and guesthouses throughout the city that offer affordable accommodations. Some popular areas to stay include the Xintiandi neighborhood, which is known for its trendy bars and restaurants, and the French Concession, which is filled with charming cafes and boutiques.
此外,还有图片理解的能力,选择“Multimodal Chat”:
在左边上传图片,然后右下方输入问题,选择“Submit”即可:
经过我的测试,这里的对话能力是比较弱的,对于图像的描述很简单,但它是具备一定的图像识别理解能力的。