1.环境配置
conda create -n demo python==3.10 -y conda activate demo conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
2.激活环境
conda activate demo
3.环境包安装
pip install huggingface-hub==0.17.3 pip install transformers==4.34 pip install psutil==5.9.8 pip install accelerate==0.24.1 pip install streamlit==1.32.2 pip install matplotlib==3.8.3 pip install modelscope==1.9.5 pip install sentencepiece==0.1.99
4.下载 InternLM2-Chat-1.8B
模型
python /root/demo/download_mini.py
5.加载模型
python /root/demo/cli_demo.py
6.chat创作小故事
进阶作业
1.使用 Lagent 运行 InternLM2-Chat-7B 模型
Lagent 相关知识:
Lagent 是一个轻量级、开源的基于大语言模型的智能体(agent)框架,支持用户快速地将一个大语言模型转变为多种类型的智能体,并提供了一些典型工具为大语言模型赋能。流式输出,接口统一。
配置基础环境
打开文件路径:cd /root/demo git 命令下载 Lagent 相关的代码并安装代码库:git clone https://gitee.com/internlm/lagent.git cd /root/demo/lagent git checkout 581d9fb8987a5d9b72bb9ebd37a95efd47d479ac pip install -e .
Lagent
运行 InternLM2-Chat-7B
模型为内核的智能体
使用7b模型:InternLM2-Chat-7b
打开lagent路径:cd /root/demo/lagent
构造模型软连接:ln -s /root/share/new_models/Shanghai_AI_Laboratory/internlm2-chat-7b /root/models/internlm2-chat-7b
修改lagent
/examples/internlm2_agent_web_demo_hf.py
文件71行为7b模型:
value='/root/models/internlm2-chat-7b'
输入以下命令运行加载模型:
streamlit run /root/demo/lagent/examples/internlm2_agent_web_demo_hf.py --server.address 127.0.0.1 --server.port 6006
本地端口环境配置本地 PowerShell
,在ssh链接中查看端口号,修改自己的端口号
ssh -CNg -L 6006:127.0.0.1:6006 root@ssh.intern-ai.org.cn -p 自己的端口号
PowerShell
环境输入链接密码,密码在ssh连接中复制。
浏览器访问 http://127.0.0.1:6006
提示词栏中输入:请解方程 2*X=1360 之中 X 的结果。求x,7b模型返回如下:
提示词栏中输入:快速傅里叶推导,7b模型返回如下: