Views
No views yet
trtllm-build to produce an engine for inference.| Item | Value |
|---|---|
| Base model | Llama-3.2-3B-Instruct |
| Framework | TensorRT-LLM 1.2.0 (checkpoint format) |
| Weight quantization | FP8 E4M3 (W8A8), per-tensor scale |
| KV cache | FP8 |
| Calibration | 512 samples from cnn_dailymail, seq_len=512 |
| Producer | TensorRT-Model-Optimizer llm_ptq (nvidia-modelopt 0.41.0) + TensorRT-LLM 1.2.0 convert_checkpoint (--use_fp8 --fp8_kv_cache) |
| TensorRT | 10.14.1 |
| Architecture | LlamaForCausalLM (28 layers, hidden_size=3072, GQA 24/8 heads) |
| Tensor parallelism | 1 (single GPU) |
1pip install tensorrt_llm==1.2.0 --extra-index-url https://pypi.nvidia.com
2# Install TensorRT-Model-Optimizer (required for FP8 calibration)
3# See https://github.com/NVIDIA/TensorRT-Model-Optimizer
4pip install "nvidia-modelopt[hf]"1# Step 1: PTQ calibration (512 samples, FP8 weight + FP8 KV)
2# This produces saved_models_* with FP8 weights + activation/KV scales
3bash TensorRT-Model-Optimizer/examples/llm_ptq/scripts/huggingface_example.sh \
4 --model meta-llama/Llama-3.2-3B-Instruct \
5 --quant fp8 --kv_cache_quant fp8 \
6 --calib 512 --tasks quant
7
8# Step 2: Convert PTQ output to TRT-LLM checkpoint format
9# TRT-LLM 1.2.0 path: examples/models/core/llama/
10python TensorRT-LLM/examples/models/core/llama/convert_checkpoint.py \
11 --model_dir ./path/to/saved_models_* \
12 --output_dir ./llama-3.2-3b-instruct-trtllm-ckpt-wq_fp8-kv_fp8 \
13 --dtype float16 \
14 --tp_size 1 \
15 --use_fp8 \
16 --fp8_kv_cache \
17 --load_model_on_cpuImportant:--use_fp8is required. Without it,convert_checkpointsetsquant_algo=nulland leaves weights as float16. The resulting engine runs float16 weights with FP8 KV cache (scale=1.0), causing KV overflow, NaN logits, and garbage output.
--output_dir contains config.json and rank0.safetensors; that is the checkpoint in this repo.tensorrt_llm installed:1git clone https://huggingface.co/rungalileo/llama-3.2-3b-instruct-trtllm-ckpt-wq_fp8-kv_fp8
2cd llama-3.2-3b-instruct-trtllm-ckpt-wq_fp8-kv_fp8
3
4trtllm-build --checkpoint_dir . --output_dir ./engine \
5 --max_batch_size 1 --max_input_len 4160 --max_seq_len 4224 \
6 --gemm_plugin auto --gpt_attention_plugin auto1trtllm-serve ./engine --tokenizer meta-llama/Llama-3.2-3B-Instruct --port 8000
2# OpenAI-compatible API: http://localhost:8000/v1/completions| File | Description | Size |
|---|---|---|
config.json | TRT-LLM model config (architecture + quantization metadata) | 2.4 KB |
rank0.safetensors | Rank 0 weights: 140 FP8 E4M3 weight tensors + 336 FP32 scale tensors + 59 FP16 non-quantized tensors (embeddings, layernorms) | 4.5 GB |
weights_scaling_factor (FP32)activation_scaling_factor (FP32), calibrated from 512 cnn_dailymail sampleskv_cache_scaling_factor + kv_cache_rcp_scaling_factor (FP32)