书生浦语大模型实战营第二期第二次课
八戒-Chat-1.8B 是利用《西游记》剧本中所有关于猪八戒的台词和语句以及 LLM API 生成的相关数据结果,进行全量微调得到的猪八戒聊天模型。八戒-Chat-1.8B 能够回答各种问题,提供建议、信息和娱乐,并与用户进行自然语言交互。课程文档:https://github.com/InternLM/Tutorial/blob/camp2/helloworld/hello_world.md。
课程文档:https://github.com/InternLM/Tutorial/blob/camp2/helloworld/hello_world.md
课程视频:https://www.bilibili.com/video/BV1AH4y1H78d/
基础练习、进阶部分和实战部署
- 创建 Intern Studio 的开发机,并从 Modelscope 下载 InternLM2-Chat-1.8B 模型(1.8B 表示十亿级参数)。Modelscope 是一个模型即服务平台,旨在收集 AI 社区最先进的机器学习模型,并简化在实际应用中使用 AI 的流程。
- 使用 OpenXlab 平台部署八戒-Chat-1.8B 模型的 XiYou 系列作品,完成 Web Demo 的部署和交互。
- 在算力升级后,基于 InternLM2-Chat-7B 模型运行开源框架 Lagent 的智能体 Demo。
- 运用 InternLM-XComposer2 模型实现更加复杂的图文生成写作,实现浅唱多模态实践。
部署八戒chat1.8B模型并进行测试
1.1八戒-Chat-1.8B
八戒-Chat-1.8B 是利用《西游记》剧本中所有关于猪八戒的台词和语句以及 LLM API 生成的相关数据结果,进行全量微调得到的猪八戒聊天模型。可以进行广泛的对话和交流。八戒-Chat-1.8B 能够回答各种问题,提供建议、信息和娱乐,并与用户进行自然语言交互。它被设计用于辅助人们解决问题、获取信息和进行轻松的对话。
2.配置基础环境
2.1配置基础环境,创建开发机配置开发机系统,
进入开发机后,在 terminal 中输入环境配置命令
配置完成后,进入到新创建的 conda 环境之中
2.2完成环境包的安装
2.3下载 InternLM2-Chat-1.8B 模型
2.4运行 cli_demo
运行cli_demo
(双击打开 /root/demo/cli_demo.py
文件,复制以下代码:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name_or_path = "/root/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)
输入命令,执行 Demo 程序:
conda activate demo
python /root/demo/cli_demo.py
等待模型加载完成,输入内容示例:请创作一个300字的小故事
进阶
-
下载运行
Chat-八戒
Demo
使用 Lagent
运行 InternLM2-Chat-7B
使用git命令下载Lagent
相关的代码库
git clone https://gitee.com/internlm/lagent.git
# git clone https://github.com/internlm/lagent.git
cd /root/demo/lagent
git checkout 581d9fb8987a5d9b72bb9ebd37a95efd47d479ac
pip install -e . # 源码安装
-
实践部署
浦语·灵笔2
模型
图文写作实战
输入如下指令,用于启动 InternLM-XComposer
cd /root/demo/InternLM-XComposer
python /root/demo/InternLM-XComposer/examples/gradio_demo_composition.py \
--code_path /root/models/internlm-xcomposer2-7b \
--private \
--num_gpus 1 \
--port 6006
-
图片理解实战
关闭并重新启动一个新的terminal
,输入如下指令,启动InternLM-XComposer2-vl
conda activate demo
cd /root/demo/InternLM-XComposer
python /root/demo/InternLM-XComposer/examples/gradio_demo_chat.py \
--code_path /root/models/internlm-xcomposer2-vl-7b \
--private \
--num_gpus 1 \
--port 6006
更多推荐
所有评论(0)