Phase 03/Alternative engines/TensorRT-LLM
PHASE 03 · Alternative engines

TensorRT-LLM

0%
8 h5 subtopics2 lessons · 1 required
In plain English

vLLM and SGLang are like kitchens that can cook any recipe the moment it arrives. TensorRT-LLM, from NVIDIA, is more like a factory line built for one specific dish on one specific set of machines. Before serving, it spends minutes compiling the model into an "engine", a plan tailored to the exact GPU, batch sizes and number formats you choose. That planning lets it fuse steps together and use the fastest hand-written routines, so it is often the quickest option on NVIDIA hardware. The cost is flexibility: change the GPU or the settings and you rebuild. This topic also introduces quantization at the engine level, shrinking the numbers the model stores so it fits in less memory and runs faster, which Phase 4 then treats in depth.

Why it matters

TensorRT-LLM is what many NVIDIA-centric production deployments and Triton Inference Server users run, and it is the engine to beat in NVIDIA's own benchmarks. Its ahead-of-time compilation model is also the clearest illustration of why static shapes, kernel fusion and quantization matter.

Hiring signal

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Anyscale, Baseten, Cerebras, CoreWeave, Crusoe, Databricks, ElevenLabs, Fireworks, Hugging Face, Liquid AI, Modal, nvidia, OpenAI, Perplexity, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Explain the build-then-serve workflow and what an engine file contains.
  • Read a TensorRT-LLM engine config.json and explain every major field.
  • Build and run an engine for a small model on a cheap cloud GPU, or inspect a published engine config as a fallback.
  • Describe FP8 and INT8/INT4 weight-only quantization as build-time options and their trade-offs.
  • Compare the operational trade-offs of TensorRT-LLM against vLLM and SGLang.

Key concepts

Engine
A serialized, GPU-specific compiled plan of the model with fused kernels and fixed maximum shapes.
Build phase
Converting HF checkpoints to TRT-LLM format, then trtllm-build with max batch size, input and output lengths and plugins.
Plugins
Hand-optimized kernels (GPT attention, GEMM, all-reduce) inserted into the TensorRT graph.
In-flight batching
NVIDIA's name for continuous batching in the TRT-LLM batch manager.
Weight-only quantization
Storing weights in INT8 or INT4 while computing in FP16; reduces memory traffic during memory-bound decode.
FP8
8-bit floating point supported on Hopper and later; quantizes weights and activations with calibration.
Paged KV cache
TRT-LLM's block-based KV cache, equivalent in spirit to PagedAttention.
Triton Inference Server backend
The production front end NVIDIA pairs with TRT-LLM engines for multi-model serving.

Subtopics

  1. 1. The build-then-serve workflow

    convert_checkpoint.py, trtllm-build, engine directory layout, and why engines are tied to GPU architecture and TRT version.

  2. 2. Reading an engine config

    config.json fields for builder settings, plugin config, max shapes, dtype and quantization; what each costs in memory.

  3. 3. Serving an engine

    trtllm-serve for an OpenAI-compatible endpoint, the LLM Python API, and the Triton backend.

  4. 4. Engine-level quantization intro

    Weight-only INT8/INT4, SmoothQuant INT8, FP8 and AWQ as build-time choices; memory and accuracy trade-offs at a high level.

  5. 5. Where TRT-LLM wins and loses

    Peak performance and NVIDIA feature support versus rebuild friction, hardware lock-in and slower model support.

Resources

Hands-on lessons

L1

Build and serve a TinyLlama engine on a rented GPU

Rented GPUcli180 minoptional

Goal · A TensorRT-LLM engine for TinyLlama-1.1B-Chat built by you, served with trtllm-serve, and queried with the openai client, for under about 3 USD of GPU time.

  1. 1Rent an hourly L4 or A10 (RunPod, Lambda Cloud or Vast.ai; roughly 0.3 to 0.8 USD per hour) and start the nvcr.io/nvidia/tensorrt-llm/release container or pip install tensorrt-llm per the quick start.
  2. 2Download TinyLlama/TinyLlama-1.1B-Chat-v1.0 with huggingface-cli and run examples/llama/convert_checkpoint.py to produce a TRT-LLM checkpoint in float16.
  3. 3Run trtllm-build with max_batch_size 8, max_input_len 1024, max_seq_len 2048 and the paged KV cache plugin enabled; time the build.
  4. 4Open the produced config.json and write a one-line explanation for each top-level field.
  5. 5Serve with trtllm-serve <engine_dir> and query /v1/chat/completions with the openai client.
  6. 6Rebuild with weight-only INT8 quantization (convert_checkpoint.py --use_weight_only --weight_only_precision int8) and compare engine size and decode tokens per second over 20 requests.
  7. 7Stop the instance and record the total cost.
Deliverable
Both config.json files with your annotations, engine sizes, the two tokens-per-second numbers and the cost.
Check
The INT8 engine is roughly half the size of the FP16 engine; both answer the openai client correctly; the recorded cost is under 5 USD.
Fallback
On colab-gpu or cpu, read the TinyLlama or Llama example README in the TensorRT-LLM repo, pull an engine config.json from a public Hugging Face repo tagged tensorrt-llm, annotate every field, and write the exact trtllm-build command you would run with justification for each flag.
L2

Engine config inspection and build-plan design

CPU · your Macdesign60 minrequired

Goal · A written build plan for serving Llama-3.1-8B-Instruct on one L4 with TensorRT-LLM, with justified shape and quantization choices.

  1. 1From the TRT-LLM docs, list the memory implications of max_batch_size, max_input_len, max_seq_len and the paged KV cache.
  2. 2Using your p3-llm-serving-architecture-l2 calculator, check that FP16 8B weights do not fit comfortably on a 24 GB L4 with useful KV space.
  3. 3Choose a quantization mode (INT8 weight-only, INT4 AWQ or FP8 if the GPU supports it) and justify it.
  4. 4Write the full convert_checkpoint.py and trtllm-build commands and the expected engine size.
Deliverable
A one-page markdown build plan with commands and a memory table.
Check
The plan leaves at least 6 GB for KV cache on the L4 and justifies choosing INT4-AWQ over FP8 (which the Ada L4 does support) by the extra KV headroom it buys at 24 GB.

Build your own

Build your own engine build planner

PythonCPU · your Mac~5 h

A CPU tool that reads a Hugging Face config.json and a GPU spec, computes the memory plan and emits the exact trtllm-build, quantize and trtllm-serve commands, so you can design TensorRT-LLM deployments without renting the GPU first.

The real thing: nvidia.github.io/TensorRT-LLM/commands/trtllm-build.html ↗

How you know a stage passes

Write tests/test_planner.py first with golden numbers for three models (Qwen2.5-0.5B, TinyLlama-1.1B, Llama-3.1-8B) on three GPUs (T4, L4, H100). Later stages are snapshot tests, a diff of the emitted plan against a committed expected file. The CLI, plan.py, is the user-facing artifact. Run `pytest -q`; a stage passes when its tests pass and the snapshots match.

Stages, in order. Each one leaves you with something that runs.0/6
  1. 01parse config.json into an architecture summary
    Given a config.json, print layers, hidden size, heads, KV heads, head dim, vocab, intermediate size and the computed parameter count.
    test · Llama-3.1-8B gives 8.03B parameters within 0.5 percent and Qwen2.5-0.5B gives 494M within 0.5 percent; pytest asserts both.
  2. 02a GPU spec table and capability checks
    A table of T4, L4, A10G, A100-40, A100-80 and H100 with memory, bandwidth, compute capability and FP8 support; the planner rejects quantization formats the GPU cannot run.
    test · Requesting FP8 on T4 or A10G raises UnsupportedOnGPU naming the compute capability; FP8 on L4 and H100 is accepted; INT4-AWQ is accepted everywhere.
  3. 03the memory plan
    Compute weight bytes at the chosen dtype, KV bytes per token, an activation reserve, and the maximum KV tokens that fit, given max_batch_size and max_seq_len.
    test · Llama-3.1-8B in FP16 on L4 reports about 16 GB of weights and 128 KB KV per token, and the maximum KV tokens with a 1 GB activation reserve matches your lesson's spreadsheet within 5 percent.
  4. 04emit the commands
    The planner prints a convert or quantize command, the trtllm-build command with max_batch_size, max_num_tokens, paged KV and plugin flags, and a trtllm-serve command.
    test · shlex.split parses every emitted command; each contains the required flags; the output for Llama-3.1-8B on L4 with int4_awq matches the committed snapshot byte for byte.
  5. 05feasibility and warnings
    Infeasible plans fail with a message that states the shortfall in GB; marginal plans warn when fewer than 2,048 KV tokens remain or when max_num_tokens exceeds what the KV budget supports.
    test · Llama-3.1-70B in FP16 on L4 exits non-zero with a message containing the shortfall (about 117 GB); Llama-3.1-8B FP16 on T4 warns about a KV budget below 2,048 tokens.
  6. 06the markdown plan
    plan.py --model ... --gpu L4 --quant int4_awq --out plan.md writes a one-page plan with the architecture table, memory table, commands and justification lines.
    test · diff against the committed reference plan for Llama-3.1-8B on L4 is empty apart from the generated-at line, and the plan runs end to end for all nine model-GPU pairs in under 2 seconds.

Knowledge check

QWhy must a TensorRT-LLM engine be rebuilt when you move to a different GPU model?

The engine is compiled for a specific compute capability with kernels auto-tuned for that hardware; TensorRT does not guarantee portability across architectures.

QWhat does max_batch_size at build time cost you at run time?

It fixes the upper bound on in-flight requests and sizes workspace buffers; too small limits throughput, too large wastes memory.

QWhy does weight-only INT8 speed up decode even though compute stays FP16?

Decode is memory-bound; reading half as many weight bytes per step shortens the step, and dequantization in the kernel is cheap by comparison.

QName one operational drawback of TensorRT-LLM relative to vLLM.

Any change in model, GPU, precision or max shapes requires a rebuild that takes minutes to hours, and new model architectures arrive later.

Completion

  • All 5 subtopics marked done
  • All 1 required lessons done
  • All subtopics marked completed.
  • Lesson l1 (or its fallback) deliverable saved with annotated engine configs.
  • Can explain build-then-serve and name three build flags and their memory effect without notes.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →