qwentensorrtllm
在开始之前,请先确保你的电脑安装了显卡驱动、cuda12.1、cudnn 和 miniconda。同时有些显卡目前不支持 tensorrt-llm,测试中 T4 和 P100 显卡均不支持 tensorrt-llm
克隆本仓库
git clone https://www.modelscope.cn/tiansz/qwen_tensorrt_llm.git
cd qwen_tensorrt_llm
创建新的 python 环境
conda create -n trt_llm python==3.10.12
conda activate trt_llm
安装依赖
请注意以下命令逐行运行:
pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu121
conda install -y mpi4py
pip install tensorrt_llm==0.7.0 --extra-index-url https://pypi.nvidia.com --extra-index-url https://download.pytorch.org/whl/cu121
pip install pynvml>=11.5.0
pip install -r requirements.txt
pip install --upgrade optimum auto-gptq
安装完依赖后在终端中运行如下代码,校验 tensorrt-llm 是否安装成功:
python -c "import tensorrt_llm; print(tensorrt_llm.__version__)"
下载 huggingface 模型
git clone https://www.modelscope.cn/qwen/Qwen-1_8B-Chat-Int4.git
编译为 tensorrt-llm 模型
? 编译前你还需要根据实际情况修改 default_config.py 中的配置
python build.py --use_weight_only --weight_only_precision int4_gptq --per_group --use_inflight_batching --paged_kv_cache --remove_input_padding --enable_context_fmha
验证模型
python run.py
python cli_chat.py
使用 fastapi 部署服务
目前 tritonserver 部署 tensorrt-llm 服务我还未跑通,但我们可以先使用 fastapi 部署服务:
python api.py
启动 api 服务后,可以在另一个终端中运行如下命令:
python client.py
python web_demo.py
测试速度
python benchmark.py --backend hf
若以上命令无法运行,可能是 exllama 的问题,你可以在 huggingface 模型的 config.json
的 quantization_config
字段中添加: "disable_exllama": true
python benchmark.py --backend trt_llm
参考资料
请注意本教程同样适用于 ubuntu 系统
评论