|
| 1 | +--- |
| 2 | +name: llm-backend-setup |
| 3 | +description: > |
| 4 | + Configure and connect to an OpenAI-compatible LLM or VLM backend for Multi-modal AI Studio. |
| 5 | + Covers vLLM, Ollama, and OpenAI API setup including Docker commands, |
| 6 | + model listing, health checks, and warmup. Use when setting up the language model backend |
| 7 | + before running voice or vision sessions. |
| 8 | +license: Apache-2.0 |
| 9 | +metadata: |
| 10 | + author: NVIDIA Corporation |
| 11 | + version: "1.0" |
| 12 | +--- |
| 13 | + |
| 14 | +# LLM Backend Setup |
| 15 | + |
| 16 | +Configure an OpenAI-compatible LLM/VLM backend for Multi-modal AI Studio. |
| 17 | + |
| 18 | +## Overview |
| 19 | + |
| 20 | +MMAS connects to any OpenAI-compatible API (`/v1/chat/completions`). Supported backends: |
| 21 | + |
| 22 | +| Backend | Default Port | Vision Support | Best For | |
| 23 | +|---------|-------------|---------------|----------| |
| 24 | +| vLLM | 8010 | Yes (image + video) | Production VLM serving | |
| 25 | +| Ollama | 11434 | Yes (images only) | Easy local setup | |
| 26 | +| OpenAI API | N/A | Yes (GPT-4V) | Cloud-based | |
| 27 | + |
| 28 | +## Prerequisites |
| 29 | + |
| 30 | +- Docker with NVIDIA runtime configured (for containerized backends) |
| 31 | +- GPU with sufficient VRAM for the chosen model |
| 32 | +- For vLLM with Cosmos-Reason2: download the model first — see [INSTALL.md](../../../INSTALL.md) or [vlm_guide.md](../../../docs/vlm_guide.md) for model setup instructions |
| 33 | + |
| 34 | +## Instructions |
| 35 | + |
| 36 | +### Option A: Ollama (easiest) |
| 37 | + |
| 38 | +```bash |
| 39 | +# Install Ollama |
| 40 | +curl -fsSL https://ollama.com/install.sh | sh |
| 41 | + |
| 42 | +# Pull a model |
| 43 | +ollama pull nemotron-3-nano:4b # Text-only LLM |
| 44 | +ollama pull gemma3:4b # Vision LLM (images only, no video) |
| 45 | + |
| 46 | +# Ollama auto-starts on port 11434 |
| 47 | +curl -s http://localhost:11434/v1/models | python3 -m json.tool |
| 48 | +``` |
| 49 | + |
| 50 | +### Option B: vLLM (recommended for VLMs) |
| 51 | + |
| 52 | +> **Model setup**: Download the Cosmos-Reason2 model before running vLLM. |
| 53 | +> See [INSTALL.md](../../../INSTALL.md) or [vlm_guide.md](../../../docs/vlm_guide.md) for download instructions and Jetson AI Lab links. |
| 54 | +
|
| 55 | +```bash |
| 56 | +export MODEL_PATH=/path/to/cosmos-reason2-8b-fp8 |
| 57 | + |
| 58 | +sudo docker run -d --network host --runtime=nvidia \ |
| 59 | + --name vllm-cosmos \ |
| 60 | + -v $MODEL_PATH:/models/cosmos-reason2-8b:ro \ |
| 61 | + ghcr.io/nvidia-ai-iot/vllm:latest \ |
| 62 | + vllm serve /models/cosmos-reason2-8b \ |
| 63 | + --served-model-name nvidia/cosmos-reason2-8b-fp8 \ |
| 64 | + --max-model-len 8192 \ |
| 65 | + --gpu-memory-utilization 0.7 \ |
| 66 | + --reasoning-parser qwen3 \ |
| 67 | + --media-io-kwargs '{"video": {"num_frames": -1}}' \ |
| 68 | + --enable-prefix-caching \ |
| 69 | + --port 8010 |
| 70 | +``` |
| 71 | + |
| 72 | +> **GPU memory cleanup**: If vLLM fails with OOM after stopping another GPU container: |
| 73 | +> ```bash |
| 74 | +> sudo sysctl -w vm.drop_caches=3 |
| 75 | +> ``` |
| 76 | +
|
| 77 | +### Option C: OpenAI API |
| 78 | +
|
| 79 | +Set your API key as an environment variable: |
| 80 | +
|
| 81 | +```bash |
| 82 | +export OPENAI_API_KEY=sk-... |
| 83 | +python -m multi_modal_ai_studio \ |
| 84 | + --llm-api-base https://api.openai.com/v1 \ |
| 85 | + --llm-api-key "$OPENAI_API_KEY" \ |
| 86 | + --llm-model gpt-4o |
| 87 | +``` |
| 88 | +
|
| 89 | +### Verify the backend |
| 90 | + |
| 91 | +```bash |
| 92 | +# List available models |
| 93 | +curl -s http://localhost:8092/api/llm/models?api_base=http://localhost:8010/v1 | python3 -m json.tool |
| 94 | + |
| 95 | +# Health check |
| 96 | +curl -s http://localhost:8092/api/health/llm?api_base=http://localhost:8010/v1 |
| 97 | +# {"status": "ok"} |
| 98 | + |
| 99 | +# Warm up the model (first request is slow due to CUDA graph capture) |
| 100 | +curl -s -X POST http://localhost:8092/api/llm/warmup \ |
| 101 | + -H "Content-Type: application/json" \ |
| 102 | + -d '{"api_base": "http://localhost:8010/v1", "model": "nvidia/cosmos-reason2-8b-fp8"}' |
| 103 | +``` |
| 104 | + |
| 105 | +### Direct API test |
| 106 | + |
| 107 | +```bash |
| 108 | +curl -s http://localhost:8010/v1/chat/completions \ |
| 109 | + -H "Content-Type: application/json" \ |
| 110 | + -d '{ |
| 111 | + "model": "nvidia/cosmos-reason2-8b-fp8", |
| 112 | + "messages": [{"role": "user", "content": "Hello"}], |
| 113 | + "max_tokens": 50, |
| 114 | + "stream": false |
| 115 | + }' | python3 -m json.tool |
| 116 | +``` |
| 117 | + |
| 118 | +## Input Schema |
| 119 | + |
| 120 | +MMAS LLM configuration fields: |
| 121 | + |
| 122 | +- `api_base` (string, required): Backend URL (e.g., `"http://localhost:8010/v1"`) |
| 123 | +- `model` (string, required): Model name as served by the backend |
| 124 | +- `api_key` (string, optional): API key for authenticated endpoints |
| 125 | +- `temperature` (float, optional, default: 0.7): Sampling temperature |
| 126 | +- `max_tokens` (integer, optional, default: 512): Maximum response tokens |
| 127 | +- `extra_request_body` (string, optional): JSON merged into every request (e.g., `'{"chat_template_kwargs": {"enable_thinking": false}}'`) |
| 128 | + |
| 129 | +## Output Schema |
| 130 | + |
| 131 | +Health check: |
| 132 | +```json |
| 133 | +{"status": "ok"} |
| 134 | +``` |
| 135 | + |
| 136 | +Model list: |
| 137 | +```json |
| 138 | +{ |
| 139 | + "models": ["nvidia/cosmos-reason2-8b-fp8"], |
| 140 | + "default_model": "nvidia/cosmos-reason2-8b-fp8" |
| 141 | +} |
| 142 | +``` |
| 143 | + |
| 144 | +## Guidelines |
| 145 | + |
| 146 | +- Only one GPU-heavy container should run at a time on Jetson (shared memory) |
| 147 | +- Stop and remove old containers before starting new ones: `docker stop <name> && docker rm <name>` |
| 148 | +- Ollama does not support `video_url` — use image-only vision or vLLM for video |
| 149 | +- vLLM first request is slow (CUDA graph compilation); use the warmup endpoint |
0 commit comments