TensorRT-LLM

Build a TensorRT-LLM engine for an open-weight LLM and compare its latency and throughput with vLLM on the same GPU.

Updated CompTech Team

vLLM will serve Llama or Mistral as soon as the weights are on disk. TensorRT-LLM builds an engine for a chosen batch size and sequence length, and that engine is often faster on the same GPU. It is also less forgiving: a prompt longer than the engine allows is rejected, and changing the limit means a rebuild.

This lab builds an engine for an open-weight instruct model, serves it, and runs the same measurement against vLLM. Record the numbers the tool prints. A result from another machine is not yours.

Prerequisites

  • A GPU node that can hold the model in the precision you build. An 8B model in float16 is the lab size
  • The TensorRT-LLM container image from NGC, and a vLLM image
  • The model weights on a volume, after you have accepted the licence. Llama 3.1 8B Instruct and Mistral instruct builds are both freely downloadable weights
  • genai-perf for the measurement

The overview explains when this is worth doing. If a NIM of this model already meets the latency you measured, stop there.

Build an engine

Run the conversion and the build inside the TensorRT-LLM container, with the weights mounted at /weights. The script path is under the container's examples/llama directory. Mistral has its own example directory and the same two steps.

python3 examples/llama/convert_checkpoint.py \
  --model_dir /weights/Llama-3.1-8B-Instruct \
  --output_dir /ckpt \
  --dtype float16

trtllm-build \
  --checkpoint_dir /ckpt \
  --output_dir /engines/llama \
  --gemm_plugin float16 \
  --max_batch_size 32 \
  --max_input_len 2048 \
  --max_seq_len 4096

max_seq_len is the sum of input and output tokens the engine will accept. max_batch_size is how many requests it will run together. Both raise memory use. An engine built at 4096 will refuse a 5000-token prompt that vLLM, started with a higher --max-model-len, would accept. Pick the limit from the longest prompt you really serve.

Serve the engine with an OpenAI-compatible endpoint so the client does not change:

trtllm-serve /engines/llama \
  --tokenizer /weights/Llama-3.1-8B-Instruct \
  --host 0.0.0.0 --port 8000

On OpenShift this is a Deployment with one nvidia.com/gpu, the engine on a PVC, and a Service on port 8000. The same shape as Triton on OpenShift, with a different command. Use Triton's TensorRT-LLM backend when this model must sit in a model ensemble or share a metrics port with other models.

The vLLM baseline

vllm serve /weights/Llama-3.1-8B-Instruct \
  --dtype float16 \
  --max-model-len 4096 \
  --host 0.0.0.0 --port 8000

Use the same weights, the same dtype and the same maximum length. A comparison against a quantised build, or against a shorter context, measures more than one change.

Measure both, then write the report down

Point genai-perf at each Service with the same flags. The report includes time to first token, inter-token latency, and output token throughput.

genai-perf profile \
  --model /weights/Llama-3.1-8B-Instruct \
  --service-kind openai \
  --endpoint-type chat \
  --url http://llm:8000 \
  --synthetic-input-tokens-mean 256 \
  --output-tokens-mean 128 \
  --concurrency 4

Run it at concurrency 1 and at concurrency 4. Single-stream latency and batched throughput move differently, and a server can win one and lose the other. Copy the three numbers for each server into the lab notes with the GPU name, the engine flags and the concurrency. Do not average the two concurrencies together.

You observe What it means
TensorRT-LLM is faster at concurrency 4 and refuses long prompts The engine limit is doing what you built. Raise max_seq_len only if those prompts are real, then rebuild
vLLM is faster at concurrency 1 The build did not pay off for this traffic. Stay on vLLM or a NIM
The two runs differ in tokens per second but the prompts differed The run is invalid. Fix the flags and repeat
GPU memory is exhausted at build time Lower max_batch_size or max_seq_len, or use a smaller model

Repeat the measurement after any change to the engine flags. The previous numbers are the baseline, not a souvenir.

What's next

  1. Put a tokenizer and a decoder around a model in model ensembles if clients should send plain text to Triton.
  2. A NIM that already serves this model is the path in the NeMo overview, and it skips the build.
  3. Scoring requests as they arrive, against whichever server won, is Kafka for AI.