前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >chatglm-6b on ubuntu 本地部署

chatglm-6b on ubuntu 本地部署

原创
作者头像
用户3016686
修改2024-09-23 10:56:30
720
修改2024-09-23 10:56:30

本地环境

系统:Ubuntu 24.04

显卡:NVIDIA Corporation GA106 GeForce RTX 3060 Lite Hash Rate (rev a1) (prog-if 00 VGA controller)

内存:64G

初始化基础环境

更换ubuntu源

阿里源为例

代码语言:shell
复制
sudo cp /etc/apt/sources.list.d/ubuntu.sources  /etc/apt/sources.list.d/ubuntu.sources.bak

sudo vi /etc/apt/sources.list.d/ubuntu.sources

添加下面内容
# 阿里云
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

更新源列表

代码语言:shell
复制
sudo apt-get update

更新系统软件包

代码语言:shell
复制
sudo apt-get upgrade

安装ssh

代码语言:shell
复制
sudo apt install openssh-server
sudo apt install openssh-client

安装必要工具(根据自己需要安装)

代码语言:shell
复制
sudo apt update
sudo apt install vim -y
sudo apt install pigz -y
sudo apt install iotop -y
sudo apt install linux-tools-common -y
sudo apt install tree -y
sudo apt install binutils -y
sudo apt install nload -y
sudo apt install iftop -y
sudo apt install iptraf-ng -y
sudo apt install nethogs -y
sudo apt install bmon -y
sudo apt install slurm -y
sudo apt install net-tools -y
sudo apt  install nmap -y
sudo apt install inetutils-traceroute -y
sudo apt install traceroute -y
sudo apt install pbzip2 -y

初始化目录

代码语言:shell
复制
sudo mkdir -p /usr/local/app/tars
sudo chown -R $USER:$USER /usr/local/app

磁盘挂载【可选】

我这里是有多个磁盘,选择一个大于200G的磁盘存放数据等,最好是ssd,快一点

代码语言:shell
复制
lsblk
sudo mkdir /data
sudo mount /dev/nvme0n1p1 /data

GPU准备

GPU型号查看

代码语言:shell
复制
# 使用lspci命令查看GPU信息
lspci |grep -i vga
# 输出如下:
01:00.0 VGA compatible controller: NVIDIA Corporation GA106 [GeForce RTX 3060 Lite Hash Rate] (rev a1)

安装驱动

代码语言:shell
复制
安装
sudo apt install python3-pip

升级
sudo pip3 install --upgrade pip
如果要卸载,使用命令:
sudo apt-get remove python3-pip

禁用 Nouveau驱动
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
2、添加两行语句:
blacklist nouveau
options nouveau modeset=0
3、更新initramfs

sudo update-initramfs -u
4、重启

reboot
5、验证,终端输入语句,

lsmod | grep nouveau


查找可选择安装的版本自动安装
sudo ubuntu-drivers autoinstall

参考 https://blog.csdn.net/m0_53353946/article/details/133769280

安装docker

https://docker-practice.github.io/zh-cn/install/ubuntu.html

代码语言:shell
复制
sudo apt-get remove docker \
               docker-engine \
               docker.io
               
               
# 更新 apt 软件包缓存,并安装 docker-ce               
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
    
    
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose -y


sudo systemctl enable docker
sudo systemctl disable docker
sudo systemctl start docker

添加docker的用户组,把当前用户加入组中。

代码语言:shell
复制
# 添加docker的用户组,把当前用户加入组中
sudo groupadd docker  #  #添加用户组
sudo gpasswd -a $USER docker #将当前用户添加至用户组
sudo newgrp docker #更新用户组

安装mincoda

安装命令

代码语言:shell
复制
cd /usr/local/app/tars
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

bash Miniconda3-latest-Linux-x86_64.sh # 依次按 任意键|yes|no
# 安装路径选择 /usr/local/app/miniconda3



You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes    <== 这里输入yes

source /root/.bashrc

修改环境变量

cat ~/.bash_profile 配置环境变量

代码语言:shell
复制
# miniconda3
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/app/miniconda3/bin

export PATH

生效环境变量

代码语言:shell
复制
source ~/.bash_profile

替换源为清华源

touch /home/$USER/.condarc

代码语言:bash
复制
channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

检查

代码语言:shell
复制
conda clean -i # 清除索引缓存,保证用的是镜像站提供的索引
conda config --show #查看是否已经换源,可以看到已经更换为清华源了

创建虚拟环境

安装完成后使用conda命令就可以创建对应的环境

代码语言:shell
复制
conda create -n chatglm-6b-310 python=3.10

初始化

代码语言:shell
复制
conda init --system --all

激活环境

代码语言:shell
复制
conda activate chatglm-6b-310 

# 添加到默认激活环境

# cat ~/.bash_profile

conda activate chatglm-6b-310

退出环境

代码语言:shell
复制
conda deactive

pip设置国内源

代码语言:shell
复制
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /root/.config/pip/pip.conf

ChatGLM3部署

下载源码

代码语言:shell
复制
git clone https://github.com/THUDM/ChatGLM3

安装依赖

代码语言:shell
复制
conda activate chatglm-6b-310 # 务必激活
cd ChatGLM3
pip3 install -r requirements.txt
#或者 指定源下载
pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

下载模型

下载地址:https://hf-mirror.com/THUDM/chatglm3-6b

镜像网站下载方法可以参考它的首页https://hf-mirror.com/介绍

采用方法2

huggingface-cli

huggingface-cli 是 Hugging Face 官方提供的命令行工具,自带完善的下载功能。

切换环境

代码语言:shell
复制
conda activate chatglm-6b-310

安装依赖

代码语言:shell
复制
# 安装依赖 https://hf-mirror.com/
pip3 install -U huggingface_hub

设置环境变量

代码语言:shell
复制
export HF_ENDPOINT=https://hf-mirror.com

建议将上面这一行写入 ~/.bashrc

下载模型

代码语言:shell
复制
cd /usr/local/app
huggingface-cli download --resume-download THUDM/chatglm3-6b --local-dir chatglm3-6b --local-dir-use-symlinks False

下载数据集

代码语言:shell
复制
huggingface-cli download --repo-type dataset --resume-download wikitext --local-dir wikitext --local-dir-use-symlinks False

可以添加 --local-dir-use-symlinks False 参数禁用文件软链接,这样下载路径下所见即所得,详细解释请见上面提到的教程。

模型使用

修改模型加载地址

代码语言:shell
复制
#MODEL_PATH = os.environ.get('MODEL_PATH', 'THUDM/chatglm3-6b')
MODEL_PATH = os.environ.get('MODEL_PATH', '/usr/local/app/ai/chatglm3-6b')

client 命令行demo

代码语言:shell
复制
conda install gpustat # 如果有必要
python  /usr/local/app/ai/ChatGLM3/basic_demo/cli_demo.py

基于 Gradio 的网页版 demo

代码语言:shell
复制
python /usr/local/app/ai/ChatGLM3/basic_demo/web_demo_gradio.py

启动基于 Streamlit 的网页版 demo

代码语言:shell
复制
pip3 install streamlit

cd /usr/local/app/ai/ChatGLM3/basic_demo
streamlit run web_demo_streamlit.py



# 输出如下

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.1.8:8501

至此,开始大模型之旅吧

下载下载 Embedding 模型

安装git lsf

ubuntu

代码语言:shell
复制
sudo apt-get install git-lfs

centos

代码语言:shell
复制
sudo yum install git-lfs

验证

代码语言:shell
复制
git lfs install
# 显示下面信息表示成功
 Git LFS initialized.

下载模型

代码语言:shell
复制
git clone https://www.modelscope.cn/AI-ModelScope/bge-large-zh-v1.5.git
cd bge-large-zh-v1.5
git lfs pull

Linux系统下查看GPU占用情况

nvidia-smi

watch

代码语言:shell
复制
watch -n 2 --color gpustat --c

参考资料

Linux快速部署ChatGLM3-6B

大模型加载的参数介绍及推荐表

Linux系统下查看GPU占用情况

Dify docker 部署要搞清楚的两个文件

https://github.com/THUDM/ChatGLM3

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 本地环境
  • 初始化基础环境
    • 更换ubuntu源
      • 阿里源为例
      • 更新源列表
      • 更新系统软件包
    • 安装ssh
      • 安装必要工具(根据自己需要安装)
        • 初始化目录
          • 磁盘挂载【可选】
          • GPU准备
            • GPU型号查看
              • 安装驱动
              • 安装docker
                • 添加docker的用户组,把当前用户加入组中。
                • 安装mincoda
                  • 安装命令
                    • 修改环境变量
                      • 生效环境变量
                        • 替换源为清华源
                          • 检查
                          • 创建虚拟环境
                            • 初始化
                              • 激活环境
                                • 退出环境
                                  • pip设置国内源
                              • ChatGLM3部署
                                • 下载源码
                                  • 安装依赖
                                    • 下载模型
                                      • huggingface-cli
                                        • 切换环境
                                        • 安装依赖
                                        • 设置环境变量
                                        • 下载模型
                                        • 下载数据集
                                    • 模型使用
                                      • 修改模型加载地址
                                        • client 命令行demo
                                          • 基于 Gradio 的网页版 demo
                                            • 启动基于 Streamlit 的网页版 demo
                                            • 下载下载 Embedding 模型
                                              • 安装git lsf
                                                • ubuntu
                                                • centos
                                                • 验证
                                              • 下载模型
                                              • Linux系统下查看GPU占用情况
                                                • nvidia-smi
                                                  • watch
                                                  • 参考资料
                                                  相关产品与服务
                                                  大模型知识引擎
                                                  大模型知识引擎(LLM Knowledge Engine),是面向企业客户及合作伙伴的,基于大语言模型的知识应用构建平台,结合企业专属数据,提供知识问答等应用范式,更快更高效地完成大模型应用的构建,推动大语言模型在企业服务场景的应用落地。
                                                  领券
                                                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档