TensorRT-LLM部署Qwen3-14B

TensorRT-LLM部署

TensorRT-LLM 官方文档地址:https://nvidia.github.io/TensorRT-LLM/overview.html

下载相关的镜像

Nvidia官方镜像网址:https://catalog.ngc.nvidia.com/search?filters=resourceType|Container|container\&query=tensorrt-llm

Shell 复制代码
#下载Nvidia tensorRT-LLM 镜像,
docker pull nvcr.io/nvidia/tensorrt-llm/release:1.2.0rc4

注意:release版本镜像并没有将模型转换checkpoint的依赖环境,没有tensorrt-llm ,需要手动安装,或者找其他版本的镜像(本人测试了 devel 版本(nvcr.io/nvidia/tensorrt-llm/devel:1.2.0rc4)仍然没有,网络建议的build版本、engine版本没有找到,只能自己安装)

进入镜像,安装相关的的依赖:

Shell 复制代码
pip install tensorrt-llm
pip install transformers accelerate sentencepiece safetensors huggingface_hu
#如果你是 Qwen3 系列,还必须安装:
pip install tiktoken
pip install einops
#如果你是 LLaMA:
pip install protobuf
#如果你用 chatml / tokenizer 的特殊格式:
pip install sentencepiece

准备基础模型

Qwen3-14B: 官方镜像即可

Shell 复制代码
#存放目录:
/mnt/data/models/Qwen/Qwen3-14B

下载github转换脚本文件

TensorRT-LLM github地址: https://github.com/NVIDIA/TensorRT-LLM/blob/main/examples/models/core/qwen/convert_checkpoint.py

Shell 复制代码
#存放文件目录:
/mnt/data/models/tensor/convert_checkpoint.py

转换checkpoint:

Shell 复制代码
python convert_checkpoint.py \
--model_dir /mnt/data/models/Qwen/Qwen3-14B \ 
--output_dir /mnt/data/models/tensor/trt_checkpoints/qwen3-14b/fp16 \
--dtype fp16

转换模型checkpoint不需要GPU资源,但是当前只使用一个镜像自己完成所有的过程,则需要GPU资源

原则上不需要 GPU

  • 仅涉及权重 reshape/分片
  • 仅涉及 JSON 结构、配置生成
  • 不包含算子编译

构建engine文件:

Shell 复制代码
trtllm-build \
  --checkpoint_dir /mnt/data/models/tensor/trt_checkpoints/qwen3-14b/float16 \
  --output_dir /mnt/data/models/tensor/engine/qwen3-14b-engine \
  --gemm_plugin float16 \
  --max_batch_size 8 \
  --max_input_len 2048 \
  --max_seq_len 4096 \
  --kv_cache_type paged \
  --workers 16 \
  --log_level info

注意:

engine构建是需要GPU资源的,构建engine的GPU资源需要和部实际部署的GPU资源保持一致,

例如:部署使用单卡L20,则构建的engine必须使用相同的GPU资源,型号数量要相同

此步骤需要:

  • CUDA kernel 生成
  • TensorRT builder 编译
  • GPU 上的 profile 校准
  • Plugin 编译优化

必须使用 GPU

  • TensorRT engine 构建只能在 GPU 上完成
  • 并且必须使用目标 GPU(或者至少与目标 GPU 架构兼容)

为什么需要 GPU?

  • TensorRT 需要 GPU 的 Compute Capability 来生成最优 kernel
  • 不同显卡(A100 / H100 / L20 / RTX4090)生成的 Engine 不能通用!

部署engine:

Shell 复制代码
trtllm-serve serve /mnt/data/models/tensor/engine/qwen3-14b-engine \
--tokenizer  /mnt/data/models/Qwen/Qwen3-14B \ 
--host 0.0.0.0 \
--port 8000 \ 
--log_level info \
--backend tensorrt \
--tp_size 1 \
--max_batch_size 8 \
--max_seq_len 4096 
相关推荐
iiiiii111 天前
【论文阅读笔记】ReVal:让大模型强化学习真正支持离策略(off-policy)数据复用
论文阅读·笔记·语言模型·大模型·llm
熊猫钓鱼>_>2 天前
从“流程固化“到“意图驱动“:大模型调智能体调Skill架构深度解析
ai·架构·大模型·llm·agent·skill·openclaw
Baihai_IDP2 天前
微软多模态推理模型 Phi-4-reasoning-vision 训练经验分享
人工智能·面试·llm
Pitayafruit2 天前
Windows 也能跑 Hermes Agent!完整安装教程 + 飞书接入,全程避坑
人工智能·llm·agent
深度学习机器2 天前
一文快速看懂Hermes Agent
llm·agent
Cosolar3 天前
LangChain实战:基于Streamlit+ LangChain + Qwen 快速构建一个多会话AI聊天页面
人工智能·llm·agent
云端FFF3 天前
LLM-based Agent 技术演进 —— 从 Prompt Engineering 到 Harness
llm·agent·skill·ai engineering
小手智联老徐3 天前
OpenClaw 三小时连更三个版本
llm·ai编程·openclaw
得物技术4 天前
财务数仓 Claude AI Coding 应用实战|得物技术
大数据·llm·aiops