注意:前提条件已安装好Anaconda、NOTE.JS(最新版)、Python 3.11、cuda 和cuDNN。
1、建立conda环境
#Conda python3.11版本下创建Ktransformers独立环境 conda create -n Ktransformers021 python=3.11 #激活使用环境 conda activate Ktransformers021
2、安装必要的组件包
pip install torch packaging ninja cpufeature numpy
3、更换torch为GPU版本(默认安装CPU版本)
#卸载刚安装的torch pip uninstall torch #安装匹配系统及GPU版本的torch 这里需要注意!需要安装跟系统一致的版本,包括操作系统、语言环境、CUDA版本(官网下载https://pytorch.org/) pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
4、下载源码
#0.2.1版本 git clone https://github.com/kvcache-ai/ktransformers.git cd ktransformers git submodule init #更新下载子模块(子目录模块) git submodule update
5、编译源码并安装
(1)先编译WEB部分(如果需要运行 Web 界面)
cd ktransformers/website/
npm install @vue/cli
npm run build
(2)自动编译主程序并安装
cd ../../ pip install .
或使用
install.bat
注意:如果系统重没有安装过跨平台编译工具CMake需要先安装
#在 Conda 环境中安装 CMake跨平台编译工具
conda install -c conda-forge cmake
6、启动程序
注意:启动程序前,将KT github官方站点(https://github.com/kvcache-ai/ktransformers)说明中支持的大模型的厂商和版本先下载到本地磁盘目录中,以下例子是下载的 Qwen/Qwen2-57B-A14B-Instruct模型文件,gguf或safetensors格式的都可以,启动参数略有不同,另外还需要注意 大模型文件的配置文件例如config.json等也要下载到模型文件同目录下。 #安装Flash Attention注意力算法组件,更有效地缩放基于transformer的模型,从而实现更快的训练和推理 #For Qwen2 推理加速(如果使用的模型是QWEN2 安装这个可以加速推理) pip install flash_attn
(1)Start without website(不使用WEB启动):
(Ktransformers021) ktransformers --model_path Qwen/Qwen2-57B-A14B-Instruct --gguf_path E:\MySynPan\TOOLS\Z2AIModels\LMStudioModels\lmstudio-community\Qwen2-57B-A14B-GGUF\qwen2-57b-a14b-instruct-q4_k_m.gguf --port 10002
(2)Start with website(使用WEB启动):
(Ktransformers021) ktransformers --model_path Qwen/Qwen2-57B-A14B-Instruct --gguf_path E:\MySynPan\TOOLS\Z2AIModels\LMStudioModels\lmstudio-community\Qwen2-57B-A14B-GGUF\qwen2-57b-a14b-instruct-q4_k_m.gguf --port 10002 --web True
(3)大模型文件为Safetensors格式(使用WEB启动):
#Or you want to start server with transformers, the model_path should include safetensors(路径必须包含safetensors文件): (Ktransformers021) ktransformers --type transformers --model_path E:\MySynPan\TOOLS\Z2AIModels\Safetensors\Qwen-Qwen2-57B-A14B-Instruct --port 10002 --web True
浏览器访问: http://localhost:10002/web/index.html#/chat
7、其它注意事项
(1)检查系统中配置CUDA的相关环境变量
Path:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\lib\x64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\libnvvp