Deploying Qwen 3 on Triton Inference Server (container) with TensorRT-LLM backend
From the publisher’s feed, collected in the ZeroLabs newsroom.
BackgroundWhen it comes to serving LLM models, there are different platform / library / format for them, I would like to get some hands on experience on that lately.I have used Ollama / LM Studio / llama.cpp (the former 2 just leverage the llama.cpp but provide better user experience) which run using GGUF that can serve the LLM with limited GPU VRAM (thanks to layer offloading for me) with a trade of inference speed.I also tried vllm and vllm-omni (both in container) to serve models, which directly use safetensors format, which I can only work on smaller models as vllm, unlike llama.cpp, need the full model weight (and KV cache) in GPU VRAM.Then I came across TensorRT, which is highly optimized towards NVIDIA hardware, like NVFP4 and inference graph / kernel optimization which leads to performance gain, so I decided to give it a try.How to serveThen I came across 2 things: Triton Inference Server and TensorRT-LLM. Long story short, Triton Inference Server is a layer on top of back-end layer like TensorRT-LLM, vLLM, python back-end...The benefit of using Triton Inference Server, as NVIDIA claimed, is it allow some feature like dynamic batching, rate limiting, support different library and framework…I do have my question as some of the feature like dynamic batching should be supported by vLLM and TensorRT-LLM back-end (this point is pretty ambiguous when reading document and checking containers folder structure and package installed, as Triton Inference Server container have a TensorRT-LLM back-end, while TensorRT-LLM also have a triton back-end, and I believe this triton back-end is referring to triton inference server)I decided to use Triton Inference Server, with the official NVIDIA NGC Catalog container (nvcr.io/nvidia/tritonserver:26.02-trtllm-python-py), note that this container is only bundled with minimal dependencies, mainly the Triton Inference Server v26.02 and TensorRT-LLM runtime ( which some scripts are missing for prepare model )The ProcessThe high level process would be:Download the HuggingFace modelConvert the HuggingFace model to checkpointBuild the Checkpoint into TensorRT engineConfigure the Triton Inference Server to load the engineWhat are the hiccups1. The script to prepare the loading of TensorRT engine with Triton Inference Server is missingAs mentioned, the container image is bundled with minimal dependencies, the TensorRT-LLM runtime is included, but the necessary scripts is missing.The solution would be download the TensorRT-LLM github repo (part of the repo, as the full repo is 1GB+ and balloon the image size a lot), and we use the below docker file to create a local/tritonserver:26.02-trtllm-python-py3 image for use# Docker File for including TensorRT-LLM repoFROM nvcr.io/nvidia/tritonserver:26.02-trtllm-python-py3RUN git clone --filter=blob:none --no-checkout --branch v1.1.0 https://github.com/NVIDIA/TensorRT-LLM.git && \pushd TensorRT-LLM && \git sparse-checkout init --cone && \git sparse-checkout set triton_backend benchmarks && \git checkout && \popdservices: triton: build: context: . dockerfile: Dockerfile image: local/tritonserver:26.02-trtllm-python-py3 container_name: triton-serve environment: - HF_TOKEN=${HF_TOKEN} volumes: - ~/.cache/huggingface:/root/.cache/huggingface - ./models:/models deploy: resources: reservations: devices: - driver: nvidia capabilities: [gpu] command: bash stdin_open: true tty: true2. The Triton Inference Server config missing config variable replacementFirst off, the Triton Inference Server run with pipelines, there is a template folder structure in the TensorRT-LLM repo’s subfolder triton_backend/all_models, there are following subfolders:The preprocess and postprocess is responsible for tokenizing the string input and decode the result token ID back to string outputThe tensor_llm is the main place that we would put our built TesnroRT engine file intoThe tensor_llm_bls is for custom business logic, which I have not touch yet. I am only guessing, it should involve creating draft model(s) [speculative decoding?] and managing LoRA (guess it related to different LoRA for different business logic or domain?)The ensemble is the pipeline that chain preprocess -> tensor_llm -> postprocessEach subfolder have a config.pbtxt that have some variables to be replaced specific to our model, we can run a readily made fill_template.py in the TensorRT-LLM github repo’s relative sub path: triton_backend/tools/fill_template.pyThere are examples online or in the github repo, but when we run the triton inference server to serve the model, it keep complaining some variable is missing.The missing one for my Qwen3 model is prompt_embedding_table_data_type, which should be TYPE_FP16 for my case ( I am only guessing it’s the target data type that we build the TensorRT target model)My script to prepare the serving:# bash - preapre.shFILL=/opt/tritonserver/TensorRT-LLM/triton_backend/tools/fill_template.py# this is where we copy the templatesMODEL_TEMPLATE_DIR=/models/qwen3_0.6b_tensorrt/trial1TARGET_ENGINE_PATH=$MODEL_TEMPLATE_DIR/tensorrt_llm/1HF_MODEL=/root/.cache/huggingface/hub/models--Qwen--Qwen3-0.6B/snapshots/c1899de289a04d12100db370d81485cdf75e47ca# I only have 1 GPUTARGET_DEVICE_IDS="0"# this should match trtllm-build max_batch_size switchMAX_BATCH=4python3 $FILL -i ${MODEL_TEMPLATE_DIR}/ensemble/config.pbtxt triton_max_batch_size:4,logits_datatype:TYPE_FP32python3 $FILL -i ${MODEL_TEMPLATE_DIR}/preprocessing/config.pbtxt triton_max_batch_size:4,tokenizer_dir:${HF_MODEL},preprocessing_instance_count:1python3 $FILL -i ${MODEL_TEMPLATE_DIR}/postprocessing/config.pbtxt triton_max_batch_size:4,tokenizer_dir:${HF_MODEL},postprocessing_instance_count:1python3 $FILL -i ${MODEL_TEMPLATE_DIR}/tensorrt_llm/config.pbtxt triton_max_batch_size:4,decoupled_mode:False,logits_datatype:TYPE_FP32,triton_backend:tensorrtllm,max_tokens_in_paged_kv_cache:2560,max_attention_window_size:2560,kv_cache_free_gpu_mem_fraction:0.5,exclude_input_in_output:False,enable_kv_cache_reuse:True,batching_strategy:inflight_fused_batching,max_queue_delay_microseconds:0,encoder_input_features_data_type:TYPE_FP16,engine_dir:${TARGET_ENGINE_PATH},gpu_device_ids:${TARGET_DEVICE_IDS},max_queue_size:64,prompt_embedding_table_data_type:TYPE_FP16python3 $FILL -i ${MODEL_TEMPLATE_DIR}/tensorrt_llm_bls/config.pbtxt triton_max_batch_size:4,decoupled_mode:False,logits_datatype:TYPE_FP32,bls_instance_count:1,prompt_embedding_table_data_type:TYPE_FP16My full steps# [Host machine] Start the containerdocker compose up -d# [Host machine] Get into the BASH of the container interactivelydocker exec -it triton-serve bash# [In Container] download the huggingface modelhf download Qwen/Qwen3-0.6B# [In Container] Convert HF model into checkpoint## Note that the snapshot subfolder might be different ## at the time you download the modelpython3 -c "import tensorrt_llmfrom tensorrt_llm.models import QWenForCausalLMmodel = QWenForCausalLM.from_hugging_face( '/root/.cache/huggingface/hub/models--Qwen--Qwen3-0.6B/snapshots/c1899de289a04d12100db370d81485cdf75e47ca', dtype='bfloat16')checkpoint_dir = '/models/qwen3_0.6b_ckpt'os.makedirs(checkpoint_dir, exist_ok=True)model.save_checkpoint(checkpoint_dir)print(f'Successfully saved checkpoint to {checkpoint_dir}')"# [In Container] Build the TensorRT engine## Note that the output would be a rank0.engine and a config.json in## /models/qwen3_engine foldertrtllm-build --checkpoint_dir /models/qwen3_0.6b_ckpt \ --output_dir /models/qwen3_engine \ --gemm_plugin bfloat16 \ --max_batch_size 4# [In Container] Prepare the template## note that we are putting the setup into /models/qwen3_0.6b_tensorrt/trial1 foldercp TensorRT-LLM/triton_backend/all_models/* /models/qwen3_0.6b_tensorrt/trial1 -r# [In Container] Run the prepare script## make sure to change the target folder path in the prepare.sh scriptbash /path/to/prepare.sh# [In Container] Serve it for verificationtritonserver --model-repository=/models/qwen3_0.6b_tensorrt/trial1/# [In Container] List the models being run## Note: Expected result as follow:## [## {"name":"ensemble","version":"1","state":"READY"},## {"name":"postprocessing","version":"1","state":"READY"},## {"name":"preprocessing","version":"1","state":"READY"},## {"name":"tensorrt_llm","version":"1","state":"READY"},## {"name":"tensorrt_llm_bls","version":"1","state":"READY"}## ]curl -X POST http://localhost:8000/v2/repository/index# [In Container] Query the model to verify if it responsecurl -X POST http://127.0.0.1:8000/v2/models/ensemble/generate \ -H 'content-type: application/json' \ -d '{ "text_input": "hi", "parameters": { "max_tokens": 16, "bad_words":[""], "stop_words":[""] } }'Some additional thoughtsI think my understanding on TensorRT is, it work on tensor level, thus we need a pipeline step like preprocess and postprocess to chain together, while if we use vLLM as backend, because vLLM would take string as input and string as output, so the preprocess and postprocess is not needed.I am seeing triton inference server could create custom business logic and ensemble (at least for TensorRT-LLM backend), which we can chain up tensors operation “graph” (e.g. preprocess output being tensor, chain to the LLM, and then the postprocess) without needing to pass the intermediate output between RAM and VRAM, which could be nice in production setup (in dev setup we can run python script to keep everything in VRAM but we might need to take care other stuff like dynamic batching), but I have not come up a chain idea to test with yet.More to exploredynamic batching — I did run trtllm-bench but that’s the lower layer on TensorRT-LLM, I would like to explore how I can benchmark the dynamic batching using variable length datamultiple model deployment — this is tough as I only got a 32GB VRAM GPU, so I can only run multiple small modelsmix of models and ensemble — I am guessing a pipeline to do RAG processing with embedding models and LLM (e.g. hierarchical embedding => document summary embedding and individual document / chunk embedding)VLLM as backend for Triton Inference ServerConclusionI would say I am still puzzle about triton inference server and compare it with pure vLLM deployment to see in what scenario I should use which one.ReferencesNGC Catalog for Triton Inference ServerTensorRT-LLM official documentTriton Inference Server with TensorRT-LLM backend official documentConcept article about Triton Inference Server by softwaremill.comChinese (on Zhihu) article serving VLM (Llava) on Triton Inference ServerDeploying Qwen 3 on Triton Inference Server (container) with TensorRT-LLM backend was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.