本文目的是让大家先熟悉模型的部署,简单入门;所以只需要很小的算力,单台服务器 单GPU显卡(显存不低于12GB),操作系统需要安装 Ubuntu 18.04。

1 服务器&操作系统 

        1.1服务器的准备

        准备一台服务器 单张英伟达GPU显卡(显存不低于12GB),操作系统需要安装 Ubuntu 18.04 (具体安装过程忽略)。 重装系统前注意备份现有存储上的相关重要数据。 GPU显卡驱动先不安装; 后续介绍驱动和CUDA的安装步骤。

        如果手上没有相应的服务器硬件设备、可以购买带GPU的云服务器, 以下可供选择参考。

 上云精选_云服务器秒杀_开发者上云推荐-腾讯云腾讯云推出云产品限时特惠抢购活动:2C2G云服务器9元/月起;还有短信、CDN、COS等热门云产品限时特惠...https://cloud.tencent.com/act/pro/seckill_season?from=20210

地域选择国内适合的城市;   预装镜像为 Ubuntu 18.04

        购买后一般云厂商会自动安装显卡的驱动和CUDA , 因为目前大部分的项目对 cuda 11.7 和 11.8 版本兼容的比较好,后续我们要指定安装特定的版本; 所以如果云主机已经预装了GPU驱动,我们需要卸载。 如果不了解卸载的指令,可以在控制台 点击“重装系统”; 

        然后 注意 不要勾选后台自动安装 GPU 驱动; 这样重置后就是一台干净的 Ubuntu18.04的系统,且没有安装GPU的驱动。

1.2系统工具和环境 

   安装一些基础的相关软件工具

sudo apt update

sudo apt install -y vim git wget curl net-tools language-pack-zh-hans language-pack-en

中文环境

echo '

LANG="en_US.utf8"; export LANG

LANGUAGE="en_US.utf8"; export LANGUAGE

LC_ALL="en_US.utf8"; export LC_ALL

LC_CTYPE="en_US.utf8"; export LC_CTYPE

SUPPORTED=en_US.UTF8:en_US:en; export SUPPORTED

TZ="Asia/Shanghai"; export TZ

' >> ~/.profile

source ~/.profile

locale

#确认当前是UTF8

2 安装  显卡驱动  和  CUDA

2.1 确认操作系统当前没有安装驱动 

        确认当前系统没有安装GPU显卡驱动, 且没有加载nvidia相关模块

lsmod | grep nvidia

sudo lsof /dev/nvidia*

#以上命令 应该没有输出 nvidia 等字样的信息

                 

 2.2 如何安装指定版本的显卡驱动(可选)

        后续 2.3 中 cuda 安装包中含有配合的显卡驱动,可以一步安装; 如果需要指定安装和 cuda 包中不同版本的驱动,可参考本节, 否则建议直接跳至 2.3 节。 

根据显卡型号下载适合的驱动

Official Drivers | NVIDIADownload latest drivers for NVIDIA products including GeForce, TITAN, NVIDIA RTX, Data Center, GRID and more.https://www.nvidia.com/download/index.aspxUnix Drivers | NVIDIALinux AMD64 Display Driver Archive | NVIDIA

 

 下载并安装显卡驱动 (需要 root 权限)

wget https://us.download.nvidia.com/XFree86/Linux-x86_64/535.98/NVIDIA-Linux-x86_64-535.98.run

sudo sh ./NVIDIA-Linux-x86_64-535.98.run

tail /var/log/nvidia-installer.log

2.3 安装 cuda (可一并安装显卡驱动) 

CUDA Toolkit Archive | NVIDIA DeveloperPrevious releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production drivers appropriate for your hardware configuration.https://developer.nvidia.com/cuda-toolkit-archive下载 cuda 11.8 版本安装包 (内含 显卡驱动)

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run

CUDA Toolkit 11.8 Downloads | NVIDIA DeveloperResources CUDA Documentation/Release NotesMacOS Tools Training Sample Code Forums Archive of Previous CUDA Releases FAQ Open Source PackagesSubmit a BugTarball and Zip Archive Deliverableshttps://developer.nvidia.com/cuda-11-8-0-download-archive

安装 cuda 需要 root 权限; 

如跳过上节没有安装显卡驱动则:要勾选安装驱动项; 否则 , 要去掉安装驱动的勾选项

sudo sh cuda_11.8.0_520.61.05_linux.run

最后运行 nvidia-smi 确认 驱动 和 cuda 安装成功

tail /var/log/cuda-installer.log

nvidia-smi

注意 : 使用 nvidia-smi  查看  CUDA 版本必须是 11.8

3 准备  Python 环境  (安装conda & 配置国内镜像源)

        3.1安装 conda

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh

sh Miniconda3-py39_4.12.0-Linux-x86_64.sh

#都回答 yes

source ~/.bashrc

        3.2 为 pip 配置国内镜像源

pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/simple

pip config set install.trusted-host mirrors.tuna.tsinghua.edu.cn

        3.3 为 conda 配置国内镜像源

        编辑当前用户下的 .condarc 文件   

conda config --set show_channel_urls yes

vim ~/.condarc

        替换成如下内容:

channels:

- defaults

show_channel_urls: true

default_channels:

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r

- 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

pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

         清除索引缓存

conda clean --all --yes

conda clean -i

        3.4 以下国内常用的 pip 镜像源 仅供参考

清华:https://mirrors.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣:http://pypi.douban.com/simple/

        3.5 常用conda命令 仅供参考

创建虚拟环境:conda create -n 环境名称 python=版本号

查看已有虚拟环境:conda env list

激活虚拟环境:conda activate 环境名称

删除虚拟环境:conda remove -n 环境名称 --all

查看当前环境下已安装的包:conda list

导出当前环境下的包:conda env export > environment.yml

根据导出的包安装环境:conda env create -f environment.yml

安装包:conda install 包名

安装下载到本地的包:conda install --use-local  包路径

卸载当前环境下包:conda uninstall 包名

卸载指定虚拟环境中的包:conda remove --name 环境名称 包名

 

4 创建环境 安装相关包

        4.1 Conda创建一个新的环境

conda create -n llm python=3.10.9

conda activate llm

         4.2安装 Web 交互 UI 工程 text-generation-webui

GitHub - oobabooga/text-generation-webui: A Gradio web UI for Large Language Models. Supports transformers, GPTQ, llama.cpp (ggml), Llama models.A Gradio web UI for Large Language Models. Supports transformers, GPTQ, llama.cpp (ggml), Llama models. - GitHub - oobabooga/text-generation-webui: A Gradio web UI for Large Language Models. Supports transformers, GPTQ, llama.cpp (ggml), Llama models.https://github.com/oobabooga/text-generation-webui

wget https://github.com/oobabooga/text-generation-webui/releases/download/installers/oobabooga_linux.zip

unzip oobabooga_linux.zip

cd oobabooga_linux/

conda activate llm

bash ./start_linux.sh

 bash ./start_linux.sh 首次运行会下载大量数据, 时间较长。

成功后会 默认监听 7860 端口 开启web服务,如下所示:

              

 5 语言 交互 UI 

        5.1进入 web 交互页面

conda activate llm

HF_TOKEN="hf_XXXXXXXXXXXXXXXXXXXXXX" # HuggingFace  的 Access Tokens

export HF_TOKEN

./start_linux.sh

./start_linux.sh 开启web服务,成功后会显示:

使用 SSH Tunnel 建立隧道 将 服务器的 7860 端口 映射到本地, 然后使用浏览器打开 。

         5.2 使用交互页面自动下载模型

        首先需要在 Model 模型页签中下载一个Llama2模型 。

        输入模型名称路径:“FlagAlpha/Llama2-Chinese-7b-Chat”

        然后点击下载按钮

注意:如果下载某些模型 出现 Http 401 错误,则需要设置  HuggingFace  的 Access Tokens

需要登录 Hugging Face – The AI community building the future.

在设置页面的  Access Tokens 中创建  Tokens 并复制。然后在 ./start_linux.sh 启动前 设置“HF_TOKEN” 环境变量 。

        另外,可以在 HuggingFace 上寻找其它开放的大预言模型, 如果使用 13B 或者 更大的模型推理,依据参数规模可能需要更高的GPU显存,甚至多张GPU来加载运行。 Hugging Face – The AI community building the future.We’re on a journey to advance and democratize artificial intelligence through open source and open science.https://huggingface.co/  

          5.3手动下载 Llama2 模型 (可选)

模型文件建议去官网下载,  国内Llama2 下载地址 仅供参考

Llama2-7B官网版本:迅雷云盘 Llama2-7B-Chat官网版本:迅雷云盘 Llama2-13B官网版本:迅雷云盘 Llama2-13B-Chat官网版本:迅雷云盘 Llama2-7B Hugging Face版本:迅雷云盘 Llama2-7B-Chat Hugging Face版本:迅雷云盘 Llama2-13B Hugging Face版本:迅雷云盘 Llama2-13B-Chat Hugging Face版本:迅雷云盘 Llama2-70B-Chat Hugging Face版本:迅雷云盘

另外 Llama2 中文模型 供参考选择  , 通过访问Llama2中文社区链接 仅供参考:

GitHub - FlagAlpha/Llama2-Chinese: Llama中文社区,最好的中文Llama大模型,完全开源可商用Llama中文社区,最好的中文Llama大模型,完全开源可商用. Contribute to FlagAlpha/Llama2-Chinese development by creating an account on GitHub.https://github.com/FlagAlpha/Llama2-Chinese  将下载好的模型文件目录放到 /data/ai/oobabooga_linux/text-generation-webui/models中

        5.4加载模型

        在 Model 模型页签中 加载模型 。 

        如下图: 刷新现有模型、 下拉菜单选中模型,点击 Load 加载 模型 , 成功加载后会显示:  “Successfully loaded FlagAlpha_Llama2-Chinese-7b-Chat.”

        5.3使用 Chat 页签 Web 交互 UI

文章链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: