|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2026 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Generic benchmark script for MaxText models using vLLM on TPU. |
| 17 | +# |
| 18 | +# Usage: |
| 19 | +# bash tests/inference/benchmark_vllm.sh <MODEL_NAME> [ATTENTION] [TP_SIZE] |
| 20 | +# |
| 21 | +# Arguments: |
| 22 | +# $1 (MODEL_NAME) : MaxText model name (e.g., "qwen3-0.6b", "llama3.1-8b") [Required] |
| 23 | +# $2 (ATTENTION) : Attention kernel to benchmark (default: "vllm_rpa") |
| 24 | +# $3 (TP_SIZE) : Tensor parallelism size (default: 4) |
| 25 | +# |
| 26 | +# Environment Variable Overrides: |
| 27 | +# TOKENIZER : HuggingFace tokenizer/model path (default: "Qwen/Qwen3-0.6B") |
| 28 | +# |
| 29 | +# Examples: |
| 30 | +# bash tests/inference/benchmark_vllm.sh qwen3-0.6b |
| 31 | +# bash tests/inference/benchmark_vllm.sh qwen3-0.6b vllm_batched_rpa |
| 32 | +# TOKENIZER=meta-llama/Llama-3.1-8B bash tests/inference/benchmark_vllm.sh llama3.1-8b vllm_batched_rpa 4 |
| 33 | + |
| 34 | +set -e |
| 35 | + |
| 36 | +if [ -z "$1" ]; then |
| 37 | + echo "Error: MODEL_NAME is required as the first argument." |
| 38 | + echo "Usage: bash tests/inference/benchmark_vllm.sh <MODEL_NAME> [ATTENTION] [TP_SIZE]" |
| 39 | + echo "Example: bash tests/inference/benchmark_vllm.sh qwen3-0.6b" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +MODEL_NAME=$1 |
| 44 | +ATTENTION=${2:-${ATTENTION:-"vllm_rpa"}} |
| 45 | +TP_SIZE=${3:-${TP_SIZE:-4}} |
| 46 | +TOKENIZER=${TOKENIZER:-"Qwen/Qwen3-0.6B"} |
| 47 | + |
| 48 | +INPUT_LEN=${INPUT_LEN:-512} |
| 49 | +OUTPUT_LEN=${OUTPUT_LEN:-128} |
| 50 | +NUM_PROMPTS=${NUM_PROMPTS:-32} |
| 51 | +LOAD_FORMAT=${LOAD_FORMAT:-"dummy"} |
| 52 | +GPU_MEM_UTIL=${GPU_MEM_UTIL:-0.6} |
| 53 | +PYTHON_EXEC=${PYTHON_EXEC:-"python3"} |
| 54 | + |
| 55 | +echo "=================================================================" |
| 56 | +echo "Running vLLM Benchmark for MaxText" |
| 57 | +echo "Model Name : $MODEL_NAME" |
| 58 | +echo "Tokenizer Path : $TOKENIZER" |
| 59 | +echo "Attention Kernel : $ATTENTION" |
| 60 | +echo "Tensor Parallel : $TP_SIZE" |
| 61 | +echo "Input / Output : $INPUT_LEN in / $OUTPUT_LEN out ($NUM_PROMPTS prompts)" |
| 62 | +echo "Load Format : $LOAD_FORMAT" |
| 63 | +echo "=================================================================" |
| 64 | + |
| 65 | +# Set standard TPU & vLLM environment variables |
| 66 | +export PYTHONPATH=$(pwd)/src:${PYTHONPATH} |
| 67 | +export SKIP_JAX_PRECOMPILE=1 |
| 68 | +export NEW_MODEL_DESIGN=1 |
| 69 | +export VLLM_ENABLE_V1_MULTIPROCESSING=0 |
| 70 | + |
| 71 | +if [ "$ATTENTION" = "vllm_batched_rpa" ]; then |
| 72 | + export USE_BATCHED_RPA_KERNEL=1 |
| 73 | +else |
| 74 | + export USE_BATCHED_RPA_KERNEL=0 |
| 75 | +fi |
| 76 | + |
| 77 | +# Run offline throughput benchmark |
| 78 | +$PYTHON_EXEC -m vllm.entrypoints.cli.main bench throughput \ |
| 79 | + --model "$TOKENIZER" \ |
| 80 | + --tensor-parallel-size "$TP_SIZE" \ |
| 81 | + --gpu-memory-utilization "$GPU_MEM_UTIL" \ |
| 82 | + --load-format "$LOAD_FORMAT" \ |
| 83 | + --hf-overrides '{"architectures": ["MaxTextForCausalLM"]}' \ |
| 84 | + --additional-config "{\"maxtext_config\": {\"model_name\": \"$MODEL_NAME\", \"weight_dtype\": \"bfloat16\", \"attention\": \"$ATTENTION\", \"allow_split_physical_axes\": true, \"scan_layers\": true, \"enable_nnx\": true, \"pure_nnx_decoder\": true}}" \ |
| 85 | + --dataset-name random \ |
| 86 | + --random-input-len "$INPUT_LEN" \ |
| 87 | + --random-output-len "$OUTPUT_LEN" \ |
| 88 | + --num-prompts "$NUM_PROMPTS" |
| 89 | + |
| 90 | +echo "=================================================================" |
| 91 | +echo "Benchmark completed successfully for $MODEL_NAME ($ATTENTION)!" |
| 92 | +echo "=================================================================" |
0 commit comments