|
| 1 | +# Benchmark |
| 2 | + |
| 3 | +This user guide shows how to run benchmarks against a vLLM deployment, by using both the Gateway API |
| 4 | +inference extension, and a Kubernetes service as the load balancing strategy. The |
| 5 | +benchmark uses the [Latency Profile Generator](https://github.com/AI-Hypercomputer/inference-benchmark) (LPG) |
| 6 | +tool to generate load and collect results. |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +### Deploy the inference extension and sample model server |
| 11 | + |
| 12 | +Follow this user guide https://gateway-api-inference-extension.sigs.k8s.io/guides/ to deploy the |
| 13 | +sample vLLM application, and the inference extension. |
| 14 | + |
| 15 | +### [Optional] Scale the sample vLLM deployment |
| 16 | + |
| 17 | +You will more likely to see the benefits of the inference extension when there are a decent number of replicas to make the optimal routing decision. |
| 18 | + |
| 19 | +```bash |
| 20 | +kubectl scale --replicas=8 -f https://github.com/kubernetes-sigs/gateway-api-inference-extension/raw/main/config/manifests/vllm/gpu-deployment.yaml |
| 21 | +``` |
| 22 | + |
| 23 | +### Expose the model server via a k8s service |
| 24 | + |
| 25 | +As the baseline, let's also expose the vLLM deployment as a k8s service: |
| 26 | + |
| 27 | +```bash |
| 28 | +kubectl expose -f https://github.com/kubernetes-sigs/gateway-api-inference-extension/raw/main/config/manifests/vllm/gpu-deployment.yaml --port=8081 --target-port=8000 --type=LoadBalancer |
| 29 | +``` |
| 30 | + |
| 31 | +## Run benchmark |
| 32 | + |
| 33 | +The LPG benchmark tool works by sending traffic to the specified target IP and port, and collect results. Follow the steps below to run a single benchmark. You can deploy multiple LPG instances if you want to run benchmarks in parallel against different targets. |
| 34 | + |
| 35 | +1. Check out the repo. |
| 36 | + |
| 37 | + ```bash |
| 38 | + git clone https://github.com/kubernetes-sigs/gateway-api-inference-extension |
| 39 | + cd gateway-api-inference-extension |
| 40 | + ``` |
| 41 | + |
| 42 | +1. Get the target IP. Examples below show how to get the IP of a gateway or a LoadBalancer k8s service. |
| 43 | + |
| 44 | + ```bash |
| 45 | + # Get gateway IP |
| 46 | + GW_IP=$(kubectl get gateway/inference-gateway -o jsonpath='{.status.addresses[0].value}') |
| 47 | + # Get LoadBalancer k8s service IP |
| 48 | + SVC_IP=$(kubectl get gateway/inference-gateway -o jsonpath='{.status.addresses[0].value}') |
| 49 | +
|
| 50 | + echo $GW_IP |
| 51 | + echo $SVC_IP |
| 52 | + ``` |
| 53 | + |
| 54 | +1. Then update the `<target-ip>` in `./config/manifests/benchmark/benchmark.yaml` to your target IP. Feel free to adjust other parameters such as request_rates as well. For a complete list of LPG configurations, pls refer to the [LPG user guide](https://github.com/AI-Hypercomputer/inference-benchmark?tab=readme-ov-file#configuring-the-benchmark). |
| 55 | + |
| 56 | +1. Start the benchmark tool. `kubectl apply -f ./config/manifests/benchmark/benchmark.yaml` |
| 57 | + |
| 58 | +1. Wait for benchmark to finish and download the results. Use the `benchmark_id` environment variable |
| 59 | +to specify what this benchmark is for. For instance, `inference-extension` or `k8s-svc`. When the LPG tool finishes benchmarking, it will print a log line `LPG_FINISHED`, |
| 60 | +the script below will watch for that log line and then start downloading results. |
| 61 | + |
| 62 | + ```bash |
| 63 | + benchmark_id='my-benchmark' ./benchmark/download-benchmark-results.bash |
| 64 | + ``` |
| 65 | + |
| 66 | +1. After the script finishes, you should see benchmark results under `./benchmark/output/default-run/my-benchmark/results/json` folder. |
| 67 | + |
| 68 | +### Tips |
| 69 | + |
| 70 | +* You can specify `run_id="runX"` environment variable when running the `./download-benchmark-results.bash` script. |
| 71 | +This is useful when you run benchmarks multiple times to get a more statistically meaningful results and group the results accordingly. |
| 72 | +* Update the `request_rates` that best suit your benchmark environment. |
| 73 | + |
| 74 | +### Advanced Benchmark Configurations |
| 75 | + |
| 76 | +Pls refer to the [LPG user guide](https://github.com/AI-Hypercomputer/inference-benchmark?tab=readme-ov-file#configuring-the-benchmark) for a detailed list of configuration knobs. |
| 77 | + |
| 78 | +## Analyze the results |
| 79 | + |
| 80 | +This guide shows how to run the jupyter notebook using vscode. |
| 81 | + |
| 82 | +1. Create a python virtual environment. |
| 83 | + |
| 84 | + ```bash |
| 85 | + python3 -m venv .venv |
| 86 | + source .venv/bin/activate |
| 87 | + ``` |
| 88 | + |
| 89 | +1. Install the dependencies. |
| 90 | + |
| 91 | + ```bash |
| 92 | + pip install -r ./benchmark/requirements.txt |
| 93 | + ``` |
| 94 | + |
| 95 | +1. Open the notebook `./benchmark/benchmark.ipynb`, and run each cell. At the end you should |
| 96 | + see a bar chart like below: |
| 97 | + |
| 98 | +  |
0 commit comments