KTransformers的关键特点包括:
(1).支持DeepSeek-R1、DeepSeek-V2/V3、Qwen2-57B、Mixtral 8x7B/22B等SOTA大模型
(2).兼容OpenAI API,可作为VSCode Copilot、Tabby等AI助手的后端
(3).支持自动量化(Q4_K_M)、MoE(专家模型)优化,极限压缩显存占用
(4).Prefill+Decode双阶段优化,相比llama.cpp最高提升27.79×的推理速度
(5).RESTful API & Web UI交互,支持本地部署和云端推理
https://github.com/kvcache-ai/ktransformers
https://github.com/kvcache-ai/ktransformers/blob/main/doc/en/DeepseekR1_V3_tutorial.md
安装KTransformers
1.安装系统依赖
sudo apt update && sudo apt install -ybuild-essential git wgetcurl
2.安装 Python 及 Pip
V0.3版本推荐Python 3.11
sudo apt install -y python3.11 python3.11-pip python3.11-venv
python3.11 -m venv venv
source venv/bin/activate
V0.2/V0.2.1版本支持Python 3.10及以上
sudo apt install -y python3 python3-pip python3-venv
python3 -m venv venv
source venv/bin/activate
3.安装CUDA及PyTorch
V0.3-Preview(CUDA 12.6 + PyTorch 2.6)
pip install torch==2.6.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
V0.2/V0.2.1(根据CUDA版本安装PyTorch)
#如果使用 CUDA 12.x
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu12x
#如果使用 CUDA 11.x(如 11.8)
pip install torch==2.1.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
4.安装KTransformers
最佳性能,V0.3-Preview推荐
wget https://github.com/kvcache-ai/ktransformers/releases/download/v0.3/ktransformers-0.3.0rc0+cu126torch26fancy-cp311-cp311-linux_x86_64.whlpip install ./ktransformers-0.3.0rc0+cu126torch26fancy-cp311-cp311-linux_x86_64.whl
最新稳定版,V0.2/V0.2.1
pip install ktransformers
适合开发者,源码安装
git clone https://github.com/kvcache-ai/ktransformers.git
cd ktransformers
git submodule init
git submodule update
sh ./install.sh # 或 make dev_install
5.下载DeepSeek-R1/V3
#使用--depth1 参数,只克隆最新版本,减少下载量
git clone --depth1 https://huggingface.co/deepseek-ai/DeepSeek-R1
git clone --depth 1 https://huggingface.co/deepseek-ai/DeepSeek-V3
或者,也可以从Hugging Face直接下载GGUF量化版本
# 以DeepSeek-V3的Q4_K_M量化版本为例
wget https://huggingface.co/deepseek-ai/DeepSeek-V3-GGUF/resolve/main/deepseek-v3-q4_k_m.gguf
运行DeepSeek-R1/V3
1.4090单GPU运行
python -m ktransformers.local_chat
--model_path <模型路径或 Hugging Face Hub ID>
--gguf_path <GGUF 文件路径或 Hugging Face Hub 文件名>
--prompt_file <提示文件路径(可选)>
--cpu_infer33
--max_new_tokens1000
参数解析
cpu_infer 33:使用33线程进行推理(可根据CPU调整)
max_new_tokens 1000:最大生成Token数
2.多GPU运行
python -m ktransformers.local_chat
--model_path <模型路径或 Hugging Face Hub ID>
--gguf_path <GGUF 文件路径或 Hugging Face Hub 文件名>
--prompt_file <提示文件路径(可选)>
--cpu_infer65
--multi_gpu true
--max_new_tokens1000
原文始发于微信公众号(哆啦安全):KTransformers高性能LLM推理优化框架
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论