【InternLM】轻松玩转书生·浦语大模型趣味 Demo

基于浦语提供的代码,演示了一些toy demo,总结如下:

1. InternLM2-Chat-1.8B 智能对话

InternLM2-Chat-1.8B是上海人工智能实验室提供的18亿参数“小体量”语言模型,共有三组模型(base model、经过STF的模型和经过指令对其的chat model)

modelscope和transformers均对tokenizer、model的加载和推理提供了简便的方式,如下面代码即可以实现流式输出:

from modelscope import snapshot_download, AutoTokenizer, AutoModelForCausalLM
import torch

model_dir = snapshot_download("Shanghai_AI_Laboratory/internlm2-chat-1_8b")
tokenizer = AutoTokenizer.from_pretrained(model_dir, device_map="auto", trust_remote_code=True)
# Set `torch_dtype=torch.float16` to load model in float16, otherwise it will be loaded as float32 and might cause OOM Error.
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto",  trust_remote_code=True, torch_dtype=torch.float16)
model = model.eval()
length = 0
for response, history in model.stream_chat(tokenizer, "Hello", history=[]):
    print(response[length:], flush=True, end="")
    length = len(response)

让其生成一个300字的小故事,效果如下图:
在这里插入图片描述

2. 部署实战营优秀作品 八戒-Chat-1.8B 模型

在第一期实战营中,部分学员运用 InternLM2-Chat-1.8B 模型进行微调训练,产生了一些效果不错的role play模型,本期给出的示例是八戒-Chat-1.8B 模型

该chat-model是利用《西游记》剧本中所有关于猪八戒的台词和语句,以及Chat-GPT-3.5生成的相关问题结果,基于InternLM2-chat-1.8b进行全量微调得到的模仿猪八戒语气的聊天语言模型。测试效果如下:

在这里插入图片描述

3. 使用 Lagent 运行 InternLM2-Chat-7B 模型

在前文中简单介绍了Lagent这款智能体框架,支持用户快速地将一个大语言模型转变为多种类型的智能体,并提供了一些典型工具为大语言模型赋能。

利用huggingface_hub 下载InternLM2-Chat-7B 模型(这里只下载config文件作为演示):

from huggingface_hub import hf_hub_download  # Load model directly 

hf_hub_download(repo_id="internlm/internlm2-7b", filename="config.json", local_dir="/root/models/internlm2-chat-7b")

在这里插入图片描述
验证其数据分析能力:
在这里插入图片描述
内部调用了python解释器,整个过程还是比较漫长的。

4. 实践部署 浦语·灵笔2 模型

浦语·灵笔2 是基于 书生·浦语2 大语言模型研发的突破性的图文多模态大模型,支持图文写作、图文问题解答等能力。

  • 文生图
    在这里插入图片描述
  • 图生文
    在这里插入图片描述

5. 参考

  1. 书生·浦语大模型趣味 Demo
  2. https://www.bilibili.com/video/BV1AH4y1H78d/
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值