一、进入conda环境,按如图教程进入环境并安装依赖
二、之后下载模型,如使用官方的开发机,使用圈1中的代码,如使用自己的本机或其他开发机,使用圈2中的方式
三、克隆代码,并改变模型的引用地址
改地址具体如图:
四、我们接着可以选择用终端来运行Demo
我们可以在 /root/code/InternLM
目录下新建一个 cli_demo.py
文件,将以下代码填入其中:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name_or_path = "/root/model/Shanghai_AI_Laboratory/internlm-chat-7b"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map='auto')
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("User >>> ")
input_text = input_text.replace(' ', '')
if input_text == "exit":
break
response, history = model.chat(tokenizer, input_text, history=messages)
messages.append((input_text, response))
print(f"robot >>> {response}")
然后在终端运行以下命令,即可体验 InternLM-Chat-7B模型的对话能力。
python /root/code/InternLM/cli_demo.py
效果如图:
五、也可以选择Web Demo方式来运行
注意:要在浏览器打开 http://127.0.0.1:6006
页面后,模型才会加载,如下图所示:
以上就基本完成了部署具体的步骤可以看https://github.com/InternLM/tutorial/blob/main/helloworld/hello_world.md
上面还有其他的操作,大家也都可以尝试一下
六、接着我要交一下我的作业【苦笑】模型下载
由于我的电脑内存的缘故,我没有下载完,以下是过程中的图片
中间经历了pip找不到,huggingface找不到,又做了调环境变量,用powershell重新安装等各种方法,基本算是把问题解决了。目前先就这样吧,第一次做博主,之后会将内容越来越完善的
还是建议大家参照github上的原链接https://github.com/InternLM/tutorial/blob/main/helloworld/hello_world.md(需要魔法)