|
| 1 | +# vLLM Load Balancer |
| 2 | + |
| 3 | +A FastAPI-based load balancer for serving vLLM models with RunPod integration. Provides OpenAI-compatible APIs with streaming and non-streaming text generation. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Before you begin, make sure you have: |
| 8 | + |
| 9 | +- A RunPod account (sign up at [runpod.io](https://runpod.io)) |
| 10 | +- RunPod API key (available in your RunPod dashboard) |
| 11 | +- Basic understanding of REST APIs and HTTP requests |
| 12 | +- `curl` or a similar tool for testing API endpoints |
| 13 | + |
| 14 | +## Docker Image |
| 15 | + |
| 16 | +Use the pre-built Docker image: `runpod/vllm-loadbalancer:dev` |
| 17 | + |
| 18 | +## Environment Variables |
| 19 | + |
| 20 | +Configure these environment variables in your RunPod endpoint: |
| 21 | + |
| 22 | +| Variable | Required | Description | Default | Example | |
| 23 | +|----------|----------|-------------|---------|---------| |
| 24 | +| `MODEL_NAME` | **Yes** | HuggingFace model identifier | None | `microsoft/DialoGPT-medium` | |
| 25 | +| `TENSOR_PARALLEL_SIZE` | No | Number of GPUs for model parallelism | `1` | `2` | |
| 26 | +| `DTYPE` | No | Model precision type | `auto` | `float16` | |
| 27 | +| `TRUST_REMOTE_CODE` | No | Allow remote code execution | `true` | `false` | |
| 28 | +| `MAX_MODEL_LEN` | No | Maximum sequence length | None (auto) | `2048` | |
| 29 | +| `GPU_MEMORY_UTILIZATION` | No | GPU memory usage ratio | `0.9` | `0.8` | |
| 30 | +| `ENFORCE_EAGER` | No | Disable CUDA graphs | `false` | `true` | |
| 31 | + |
| 32 | +## Deployment on RunPod |
| 33 | + |
| 34 | +1. Create a new serverless endpoint |
| 35 | +2. Use Docker image: `runpod/vllm-loadbalancer:dev` |
| 36 | +3. Set required environment variable: `MODEL_NAME` (e.g., "microsoft/DialoGPT-medium") |
| 37 | +4. Optional: Configure additional environment variables as needed |
| 38 | + |
| 39 | +## API Usage with curl |
| 40 | + |
| 41 | +### Text Completion (Non-streaming) |
| 42 | + |
| 43 | +```bash |
| 44 | +curl -X POST "https://your-endpoint-id.api.runpod.ai/v1/completions" \ |
| 45 | + -H "Authorization: Bearer YOUR_RUNPOD_API_KEY" \ |
| 46 | + -H "Content-Type: application/json" \ |
| 47 | + -d '{ |
| 48 | + "prompt": "Write a story about a brave knight", |
| 49 | + "max_tokens": 100, |
| 50 | + "temperature": 0.7, |
| 51 | + "stream": false |
| 52 | + }' |
| 53 | +``` |
| 54 | + |
| 55 | +### Text Completion (Streaming) |
| 56 | + |
| 57 | +```bash |
| 58 | +curl -X POST "https://your-endpoint-id.api.runpod.ai/v1/completions" \ |
| 59 | + -H "Authorization: Bearer YOUR_RUNPOD_API_KEY" \ |
| 60 | + -H "Content-Type: application/json" \ |
| 61 | + -d '{ |
| 62 | + "prompt": "Tell me about artificial intelligence", |
| 63 | + "max_tokens": 200, |
| 64 | + "temperature": 0.8, |
| 65 | + "stream": true |
| 66 | + }' |
| 67 | +``` |
| 68 | + |
| 69 | +### Chat Completions |
| 70 | + |
| 71 | +```bash |
| 72 | +curl -X POST "https://your-endpoint-id.api.runpod.ai/v1/chat/completions" \ |
| 73 | + -H "Authorization: Bearer YOUR_RUNPOD_API_KEY" \ |
| 74 | + -H "Content-Type: application/json" \ |
| 75 | + -d '{ |
| 76 | + "messages": [ |
| 77 | + {"role": "user", "content": "What is the capital of France?"} |
| 78 | + ], |
| 79 | + "max_tokens": 50, |
| 80 | + "temperature": 0.7 |
| 81 | + }' |
| 82 | +``` |
| 83 | + |
| 84 | +### Health Check |
| 85 | + |
| 86 | +```bash |
| 87 | +curl -X GET "https://your-endpoint-id.api.runpod.ai/ping" \ |
| 88 | + -H "Authorization: Bearer YOUR_RUNPOD_API_KEY" |
| 89 | +``` |
| 90 | + |
| 91 | +## Local Testing |
| 92 | + |
| 93 | +Run the test script: |
| 94 | +```bash |
| 95 | +export ENDPOINT_ID="your-endpoint-id" |
| 96 | +export RUNPOD_API_KEY="your-api-key" |
| 97 | +python example.py |
| 98 | +``` |
0 commit comments