ChatGLM2-6B

背景

之前一直在用ChatGLM,前不久ChatGLM2出了,试试差别有多大

安装

准备环境

  • python3 (miniconda)
  • Linux 或 Windows (有无显卡均可)

step 1. 代码和模型

clone 代码

git clone https://github.com/THUDM/ChatGLM2-6B

cd ChatGLM2-6B

再把 model 也 clone 下来(不要返回目录,就在这个代码目录里)

mkdir THUDM
cd THUDM

# # Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install
git clone https://huggingface.co/THUDM/chatglm2-6b

# if you want to clone without large files – just their pointers
# prepend your git clone with the following env var:
GIT_LFS_SKIP_SMUDGE=1

step 2. 安装依赖

# 回到 ChatGLM2-6B 目录
cd ..

pip install -r requirements.txt
# 网络不好就用镜像
# pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/

step 3. 启动 WebUI 和 参数调试

模型的通用配置

如果你的模型路径不太一样,那么可以修改这两行

tokenizer = AutoTokenizer.from_pretrained("{your_model_path}", trust_remote_code=True)
model = AutoModel.from_pretrained("{your_model_path}", trust_remote_code=True).half().cuda()

使用 GPU 计算:

model = AutoModel.from_pretrained("{your_model_path}", trust_remote_code=True).half().cuda()

使用 CPU 计算:

model = AutoModel.from_pretrained("{your_model_path}", trust_remote_code=True).float()

两种UI方案 任选其一

gradio

vim web_demo.py


# 换主题
with gr.Blocks() as demo:
# 更换为 Soft
with gr.Blocks(theme=gr.themes.Soft()) as demo:


# 更换端口 和 绑定地址
demo.queue().launch(server_name="0.0.0.0", server_port=7870 ,share=False)

运行:

python web_demo.py

streamlit

运行:

streamlit run web_demo2.py