Benchmark Inference Throughput per GPU for AI Agents
In this article
This guide shows you how to measure the number of inference requests your AI agent model can handle per second on a single GPU. You'll get a clear, repeatable number you can use to compare GPUs, size your deployment, or spot performance regressions. Before starting, you need: a working AI model served via an inference server (like vLLM, TensorRT-LLM, or TGI), a GPU with the correct drivers and CUDA installed, and a client tool capable of sending concurrent requests (like hey, wrk, or a simple Python script).
What You'll Need
- A GPU with the model loaded and an inference server running (e.g., vLLM, TensorRT-LLM, Hugging Face TGI).
- CUDA and GPU drivers installed and verified with
nvidia-smi. - A load generation tool:
hey,wrk,ab, or a custom Python script usingrequestsoraiohttp. - A representative prompt dataset (or at least a few fixed prompts) that matches your real agent workload.
- Access to the server's metrics endpoint (e.g., Prometheus or a simple log) to record GPU utilization and latency.
Step-by-Step
- Prepare a fixed input set. Create a file with 20–50 prompts that resemble what your AI agent will actually see. Use the same token lengths and complexity. If you don't have real data, use a mix of short (50 tokens) and long (500 tokens) prompts.
- Start the inference server. Launch your serving framework with the model you want to test. Ensure it's using the target GPU exclusively—set
CUDA_VISIBLE_DEVICESto that GPU's ID. Note the server's port (commonly 8000 for vLLM). - Warm up the model. Send a few single requests (e.g., 5–10) to let the GPU reach steady state and any caches fill. Wait 10 seconds after the last request.
- Define your concurrency level. Start with a low concurrency (e.g., 1–4) and plan to increase it. For a single GPU, typical concurrency ranges from 1 to 64 depending on the model size and batch capabilities.
- Run the load test. Use your load tool to send requests for a fixed duration (e.g., 60 seconds) at a constant concurrency. For
hey, the command looks like:hey -z 60s -c 8 -m POST -d '{"prompt":"Hello"}' http://localhost:8000/generate. For vLLM's OpenAI-compatible endpoint, use the/v1/completionspath. - Record the results. Note the total requests completed, the requests per second (RPS), and the average latency. Most tools print these at the end. Also record the GPU utilization during the test using
nvidia-smiin a separate terminal (e.g.,nvidia-smi --query-gpu=utilization.gpu,memory.used --format=csv -l 1). - Repeat with different concurrency levels. Increase concurrency (e.g., 8, 16, 32, 64) and repeat the test. This gives you a throughput curve. The peak RPS is your benchmark number for that GPU and model.
- Normalize for GPU count. If you test on a system with multiple GPUs but only want per-GPU throughput, divide the total RPS by the number of GPUs used. For a single GPU, the number is already per-GPU.
- Document the configuration. Record the model name, GPU model, batch size settings (e.g., vLLM's
--max-num-seqs), tokenizer, and the exact prompt set. This ensures reproducibility.
Common Mistakes
- Testing with a single prompt. Using the same prompt repeatedly can cause caching effects that inflate throughput. Use a diverse set.
- Ignoring the warm-up. Skipping warm-up leads to lower first-request latencies and skewed RPS numbers.
- Not fixing the input length. If your prompts vary wildly in length, the throughput number becomes meaningless. Keep token counts consistent.
- Forgetting to isolate the GPU. Other processes on the same GPU will steal memory and compute, making your numbers unreliable.
- Using too short a test duration. A 10-second test may not capture steady-state behavior. Use at least 60 seconds.
Tips
- Use a real agent workload. If your agent makes multi-turn calls or uses tool use, simulate that pattern rather than simple single prompts.
- Monitor GPU memory. If memory usage approaches 100%, you may need to reduce concurrency or batch size to avoid OOM errors.
- Check the server's built-in metrics. vLLM exposes Prometheus metrics at
/metrics; use them to see request queue length and time per token. - Run the test multiple times. Run each concurrency level 3 times and take the median to smooth out variance.
- Consider the output length. Throughput depends heavily on how many tokens the model generates. Fix the max tokens parameter (e.g.,
max_tokens=100) for all requests.
Troubleshooting
- Server returns 503 or connection refused. The server may have crashed or not started. Check the server logs and ensure the port is open. Restart if needed.
- GPU memory exhausted. Reduce concurrency or the max batch size. Also check if other processes are using the GPU.
- Throughput is zero or extremely low. Your load tool may be sending malformed requests. Test with a single request first. Also check if the server is waiting for a health check endpoint.
- Latency spikes during the test. This could be due to CPU bottlenecking (tokenization, scheduling). Watch CPU usage; if it's near 100%, you may need a faster CPU or more cores.
- Results vary wildly between runs. Ensure no other GPU tasks are running. Also check that the GPU isn't throttling due to temperature—run
nvidia-smito see temperature and power draw.
Frequently Asked Questions
What is a good throughput number for an AI agent on a GPU?
It varies widely. A small model like a 7B parameter model might handle 50–200 requests per second on a high-end GPU, while a 70B model might only do 5–20. The number depends on model size, quantization, batch size, and hardware.
Should I measure with or without batching?
Measure with batching enabled (as your inference server does by default) because that's how it will run in production. Disabling batching gives you a worst-case number but isn't realistic.
How do I convert requests per second to tokens per second?
Multiply RPS by the average output token count per request. For example, if you get 10 RPS and each request generates 100 tokens, that's 1,000 tokens per second.
Can I benchmark on a CPU instead of a GPU?
Yes, but the process is the same. The numbers will be much lower, and you should not compare CPU numbers to GPU numbers.
Do I need a separate GPU for the load generator?
No. The load generator runs on the CPU and sends network requests. It doesn't need a GPU. However, make sure the load generator machine has enough network bandwidth and CPU to send requests fast enough.
What if I have multiple GPUs and want per-GPU throughput?
Run the test on a single GPU by setting CUDA_VISIBLE_DEVICES=0. That gives you a direct per-GPU number. Alternatively, run on all GPUs and divide the total RPS by the number of GPUs, but that assumes even load distribution.