做的比较好的电商网站,百度竞价排名医院事件,网页游戏大全链接,影视网站建设多少钱一、代码仓库#xff1a;
InternLM: https://github.com/InternLM/InternLM/
课程讲师#xff1a;宋志学大佬#xff0c;d2l-ai-solutions-manual 开源项目负责人 二、Lagent框架 三、基于InternLM的智能对话
3.1 环境配置#xff1a;
cuda11.7
pytorch2.0.1
其他环境…一、代码仓库
InternLM: https://github.com/InternLM/InternLM/
课程讲师宋志学大佬d2l-ai-solutions-manual 开源项目负责人 二、Lagent框架 三、基于InternLM的智能对话
3.1 环境配置
cuda11.7
pytorch2.0.1
其他环境
# 升级pip
python -m pip install --upgrade pippip install modelscope1.9.5
pip install transformers4.35.2
pip install streamlit1.24.0
pip install sentencepiece0.1.99
pip install accelerate0.24.1 3.2 模型下载
3.2.1.ModelScope 方式下载
import torch
from modelscope import snapshot_download, AutoModel, AutoTokenizer
import os
model_dir snapshot_download(Shanghai_AI_Laboratory/internlm-chat-7b, cache_dir/root/model, revisionv1.0.3)
3.2.2.Hugging Face 方式下载
使用 Hugging Face 官方提供的 huggingface-cli 命令行工具。安装依赖:
pip install -U huggingface_hub
然后新建 python 文件填入以下代码运行即可。
import os
# 下载模型
os.system(huggingface-cli download --resume-download internlm/internlm-chat-7b --local-dir your_path) resume-download断点续下 local-dir本地存储路径。linux 环境下需要填写绝对路径
使用 huggingface_hub 下载模型中的部分文件
import os
from huggingface_hub import hf_hub_download # Load model directly
hf_hub_download(repo_idinternlm/internlm-7b, filenameconfig.json)
3.2.3 OpenXLab 方式下载
首先需要安装依赖
pip install -U openxlab
下载代码
from openxlab.model import download
download(model_repoOpenLMLab/InternLM-7b, model_nameInternLM-7b, outputyour local path)
3.3 demo运行
import torch
from transformers import AutoTokenizer, AutoModelForCausalLMmodel_name_or_path /root/model/Shanghai_AI_Laboratory/internlm-chat-7btokenizer AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_codeTrue)
model AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_codeTrue, torch_dtypetorch.bfloat16, device_mapauto)
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:breakresponse, history model.chat(tokenizer, input_text, historymessages)messages.append((input_text, response))print(frobot {response})
3.4 效果