一、外网机器准备物料
首先在联网机器下载好Unsloth UD‑Q4_K_XL,155GB,脚本可能会多次退出,重新运行就好。
pip uninstall -y huggingface-hub
pip install huggingface-hub==0.29.3
# 清除旧代理
unset HTTP_PROXY HTTPS_PROXY ALL_PROXY http_proxy https_proxy all_proxy
unset HF_HUB_ENABLE_HF_TRANSFER
# 设置国内镜像(hf‑mirror公益镜像)
export HF_ENDPOINT=https://hf-mirror.net
# 下载 Unsloth UD‑Q4_K_XL
huggingface-cli download unsloth/DeepSeek-V4-Flash-0731-GGUF \
--include "UD-Q4_K_XL/*" \
--local-dir ./DeepSeek-V4-Flash-0731-UDQ4_K_XL \
--local-dir-use-symlinks False \
--resume-download
拉取固定版本 llama.cpp b10269 源码
git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
git checkout b10269
# 打包源码
cd ..
tar -zcvf llama.cpp-b10269.tar.gz llama.cpp
下载 Ubuntu22.04 编译依赖(外网下载 deb 包,拷贝离线)
sudo apt update
sudo apt install --download-only -y build-essential cmake gcc g++ libopenblas-dev
# deb包默认缓存路径:/var/cache/apt/archives/
# 把该目录全部deb复制出来,打包为 debs.tar.gz
离网机器预先装好 NVIDIA 驱动 + CUDA‑Toolkit12.x
二、离线 Ubuntu22.04 操作(无外网)
1、安装系统依赖 deb 包
mkdir debs
tar xvf debs.tar.gz -C debs
cd debs
sudo dpkg -i *.deb
# 如有依赖缺失:sudo apt‑get install -f (内网不能执行,外网要把全部依赖下全)
2、解压编译 llama.cpp b10269(CUDA 版本)
tar -zxvf llama.cpp-b10269.tar.gz
cd llama.cpp
# 清理旧构建
rm -rf build
# CUDA编译,离线不需要联网
cmake -B build -DGGML_CUDA=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
3、llama‑cli 快速验证
CUDA_VISIBLE_DEVICES=0,1 ./build/bin/llama-cli \
-m ./DeepSeek-V4-Flash-0731-UDQ4_K_XL/UD-Q4_K_XL/DeepSeek-V4-Flash-0731-UD-Q4_K_XL-00001-of-00005.gguf \
--jinja \
-ngl 999 \
-c 65536 \
--cache-type-k q4_0 \
--cache-type-v q4_0 \
-p "简单介绍你自己" -n 30
加载日志会打印:Using 2 CUDA devices。能输出文字代表成功。