diff --git a/ChatGLM/02-ChatGLM3-6B-Code-Interpreter.md b/ChatGLM/02-ChatGLM3-6B-Code-Interpreter.md new file mode 100644 index 0000000..2b0c8e1 --- /dev/null +++ b/ChatGLM/02-ChatGLM3-6B-Code-Interpreter.md @@ -0,0 +1,89 @@ +# ChatGLM3-6B Code Interpreter + +> 请注意,本项目需要 Python 3.10 或更高版本。 + +## 环境准备 + +由于项目需要`python 3.10`或更高版本,所以我们在在[autodl](https://www.autodl.com/)平台中租一个3090等24G显存的显卡机器,如下图所示镜像选择`Miniconda`-->`conda3`-->`3.10(ubuntu20.04)`-->`11.8`。 + +![Alt text](images/image-4.png) + +接下来打开刚刚租用服务器的`JupyterLab`,并且打开其中的终端开始环境配置、模型下载和运行`demo`。 + +pip换源和安装依赖包 + +```bash +# 更换 pypi 源加速库的安装 +pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple + +pip install modelscope==1.9.5 +pip install transformers==4.35.2 + +pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu117 +``` + +## 模型下载 + +使用 `modelscope` 中的`snapshot_download`函数下载模型,第一个参数为模型名称,参数`cache_dir`为模型的下载路径。 + +在 `/root/autodl-tmp` 路径下新建 `download.py` 文件并在其中输入以下内容,粘贴代码后记得保存文件,如下图所示。并运行 `python /root/autodl-tmp/download.py`执行下载,模型大小为 14 GB,下载模型大概需要 10~20 分钟 + +```python +import torch +from modelscope import snapshot_download, AutoModel, AutoTokenizer +import os +model_dir = snapshot_download('ZhipuAI/chatglm3-6b', cache_dir='/root/autodl-tmp', revision='master') +``` + +## 代码准备 + +首先`clone`代码,打开autodl平台自带的学术镜像加速。学术镜像加速详细使用请看:https://www.autodl.com/docs/network_turbo/ + +```shell +source /etc/network_turbo +``` + +然后切换路径, clone代码. + +```shell +cd /root/autodl-tmp +git clone https://github.com/THUDM/ChatGLM3.git +``` + +切换commit版本,与教程commit版本保持一致,可以让大家更好的复现。 + +```shell +cd ChatGLM3 +git checkout f823b4a3be9666b9b2a9daa43b29659e876a040d +``` + +最后取消镜像加速,因为该加速可能对正常网络造成一定影响,避免对后续下载其他模型造成困扰。 + +```shell +unset http_proxy && unset https_proxy +``` + +然后切换路径到`composite_demo`目录,并安装相关依赖 +```bash +cd /root/autodl-tmp/ChatGLM3/composite_demo +pip install -r requirements.txt +``` + +## demo 运行 + +在终端运行以下代码,导入模型路径和Jupyter内核: + +```shell +export MODEL_PATH=/root/autodl-tmp/ZhipuAI/chatglm3-6b +export IPYKERNEL=python3 +``` + +然后运行以下代码,运行demo: + +```shell +streamlit run /root/autodl-tmp/ChatGLM3/composite_demo/main.py --server.address 127.0.0.1 --server.port 6006 +``` + +如下图所示,可以愉快的玩耍代码解释器了~ + +![Alt text](images/image-5.png) \ No newline at end of file diff --git a/ChatGLM/images/image-4.png b/ChatGLM/images/image-4.png new file mode 100644 index 0000000..5c67d8f Binary files /dev/null and b/ChatGLM/images/image-4.png differ diff --git a/ChatGLM/images/image-5.png b/ChatGLM/images/image-5.png new file mode 100644 index 0000000..3b8eb16 Binary files /dev/null and b/ChatGLM/images/image-5.png differ diff --git a/InternLM/03-浦语灵笔图文理解&创作.md b/InternLM/03-浦语灵笔图文理解&创作.md index 158753d..cb80764 100644 --- a/InternLM/03-浦语灵笔图文理解&创作.md +++ b/InternLM/03-浦语灵笔图文理解&创作.md @@ -23,7 +23,7 @@ pip install transformers==4.33.1 timm==0.4.12 sentencepiece==0.1.99 gradio==3.44 安装`modelscope`,下载模型的老朋友了 ```shell -pip install modelscope +pip install modelscope==1.9.5 ``` 在 `/root/autodl-tmp` 路径下新建 `download.py` 文件并在其中输入以下内容,并运行 `python /root/autodl-tmp/download.py`执行下载 diff --git a/README.md b/README.md index feb7609..5b42e6b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ - [x] [浦语灵笔图文理解&创作](InternLM/03-浦语灵笔图文理解&创作.md) - ChatGLM - [x] [ChatGLM3-6B chat](ChatGLM/01-ChatGLM3-6B-chat.md) - - [ ] ChatGLM3-6B Code Interpreter + - [x] [ChatGLM3-6B Code Interpreter](ChatGLM/02-ChatGLM3-6B-Code-Interpreter.md) - Qwen - [ ] Qwen-7B-chat - Yi (暂时只有base模型,没有chat模型)