8G 显存玩转书生大模型 Demo

 

1.InternLM2-Chat-1.8B 模型的部署(基础任务)

1.1.创建开发机

  • 创建的时候名称不能与现有开发及名称重复;
  • 选择镜像为Cuda-12.2;
  • 开发机10%算力,我测试的时候只有这些算力,不过效果还是很棒的

1.2.创建目录及代码文件

mkdir -p /root/demo
touch /root/demo/cli_demo.py

打开cli_demo.py文件并将以下代码粘贴到文件中保存

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM


model_name_or_path = "/root/share/new_models/Shanghai_AI_Laboratory/internlm2-chat-1_8b"

tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True, device_map='cuda:0')
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='cuda:0')
model = model.eval()

system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文.
"""

messages = [(system_prompt, '')]

print("=============Welcome to InternLM chatbot, type 'exit' to exit.=============")

while True:
    input_text = input("\nUser  >>> ")
    input_text = input_text.replace(' ', '')
    if input_text == "exit":
        break

    length = 0
    for response, _ in model.stream_chat(tokenizer, input_text, messages):
        if response is not None:
            print(response[length:], flush=True, end="")
            length = len(response)

1.3.激活已经配置好的预制环境,最开始没激活提示缺少torch等包,自己配置个环境也是怪费劲的,直接用这个预制的环境就好了。

conda activate /root/share/pre_envs/icamp3_demo

1.4.运行及测试效果

1.4.1.执行命令python /root/demo/cli_demo.py,然后就是输入自己的问题等待回复,启动过程也是非常快,大概10s钟以内吧。

1.4.2.然后我就问了个问题,问题为“请帮我围绕ABB机器人为主题写一个300字的奇幻故事”,紧接着就是编故事的过程,效果如下,效果还是很惊艳的,也完全没有偏离一个正常人对这个故事的预期。

1.5.如果想停止问答的话Ctrl+C即可。

2.Streamlit Web Demo 部署 InternLM2-Chat-1.8B 模型

2.1.clone本教程仓库的代码

cd /root/demo
git clone https://github.com/InternLM/Tutorial.git

执行后的效果如下:

2.2.启动streamlit服务

cd /root/demo
streamlit run /root/demo/Tutorial/tools/streamlit_demo.py --server.address 127.0.0.1 --server.port 6006

执行后效果如下:

我在VS code中进行调试的,VS code直接帮我做了端口映射,

如果用Power Shell来做的话,粘贴如下代码运行即可

ssh -CNg -L 6006:127.0.0.1:6006 root@ssh.intern-ai.org.cn -p 你的 ssh 端口号

上图中的端口号在如下位置可以查询到

将网址http://127.0.0.1:6006粘贴到浏览器后回车的效果如下:

随便提一个问题看看效果,只能说效果非常好:

另外发现这个模型还具有较高的政治敏感性,社会热点问题尽量不去碰,不知道内部是不是做了些特殊处理,留个问号吧。

3.LMDeploy 部署 InternLM-XComposer2-VL-1.8B 模型

3.1.使用 LMDeploy 启动一个与 InternLM-XComposer2-VL-1.8B 模型交互的 Gradio 服务。

conda activate /root/share/pre_envs/icamp3_demo
lmdeploy serve gradio /share/new_models/Shanghai_AI_Laboratory/internlm-xcomposer2-vl-1_8b --cache-max-entry-count 0.1

效果如下,系统会经过一顿的自动配置,然后给出一个链接,当然这个时候也是需要做端口映射的

3.2.使用效果

服务器端的运行截图如下

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值