Bootstrap

[InternLM 大模型开源社区]大模型实战营第三期@202408-基础岛-第2关-8G 显存玩转书生大模型 Demo

在线文档

任务类型任务内容预计耗时完成度
基础任务使用 Cli Demo 完成 InternLM2-Chat-1.8B 模型的部署,并生成 300 字小故事,记录复现过程并截图30mins完成
闯关任务使用 LMDeploy 完成 InternLM-XComposer2-VL-1.8B 的部署,并完成一次图文理解对话,记录复现过程并截图。20mins未完成
闯关任务使用 LMDeploy 完成 InternVL2-2B 的部署,并完成一次图文理解对话,记录复现过程并截图。20mins未完成

基础任务:用 Cli Demo 完成 InternLM2-Chat-1.8B 模型的部署,并生成 300 字小故事

  • 我没有按照教程来
  • 启动开发机,并选择cu11.7
  • 撰写部署环境脚本并执行
  • vi demo_env.sh, 复制下面代码进去然后bash demo_env.sh
	conda create -n demo python=3.10 -y
	source activate demo
	pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2 torchtext==0.15.2 -f https://mirror.sjtu.edu.cn/pytorch-wheels/cu117/?mirror_intel_list -f https://download.pytorch.org/whl/cu117/torch_stable.html
	pip install transformers sentencepiece einops \
	protobuf accelerate streamlit
  • vi cli_demo.py, 复制下面代码进去然后conda activate demo && python 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)
            

新建文件夹- ^新建文件夹

请添加图片描述

安装env

  • ^ 安装env

请添加图片描述

  • 载入LLM,进行提问.发现占用5G VRAM

请添加图片描述

  • ^ 问他生成一个黑白小狗的300字故事.(真慢啊1_8b!)
;