On-demand vLLM / SGLang inference platform for HPC clusters.
llm-gateway turns a batch-scheduled GPU cluster into a self-service, OpenAI-compatible inference platform. It runs in production on a university HPC centre's 200-GPU NVIDIA H200 cluster, serving research groups, teaching, and the operations team's own tooling.
HPC clusters are built around batch jobs, not always-on services. Researchers want to reach large open-weight models through a standard API; the scheduler wants every GPU accounted for as a job; and a small operations team cannot hand out admin access or run inference servers by hand.
- OpenAI-compatible API in front of the cluster, so existing clients and tools work unchanged.
- On-demand model serving. A request for a model that is not running submits a scheduler job that launches a vLLM or SGLang worker inside an Apptainer container on GPU nodes; idle workers are torn down so GPUs return to the pool.
- Admission control and capacity limits. Submissions that would queue indefinitely or exceed a project's caps are refused up front rather than left to fail in the scheduler; workers boot on demand and idle workers are reaped so GPUs return to the pool.
- Delegated access control. Project owners receive a scoped token budget and mint tokens for their own users, so onboarding a class or a lab never becomes an admin ticket. Operators keep superuser visibility across all projects.
- Guarded scheduler interface. PBS Pro has no native REST API, so job submission and control go through a hardened FastAPI service over the CLI, authenticated with per-user hashed bearer tokens and scoped by project.
- Inference-server tuning and benchmarking pipelines that validate throughput, latency, and memory behaviour of vLLM and SGLang across large open-weight models before they are offered to users.
Python / FastAPI · vLLM and SGLang workers in Apptainer · PBS Pro
scheduling · per-user hashed bearer tokens · NVIDIA H200 8-GPU nodes over InfiniBand.
Developed for a university HPC cluster; all site-specific values are
placeholders (see .env.example).
clients ──HTTPS──▶ gateway (FastAPI, TLS, tokens, routing, usage ledger)
│ one persistent SSH ControlMaster to the head node
▼
scheduler head ──qsub──▶ worker job (Apptainer: SGLang / vLLM / ComfyUI / ASR)
▲ │ registers host:port in the shared registry
└──────── forwards ◀───────┘
- Gateway (
gateway/llm_gateway/): request auth and RBAC, model catalogue and group policy, worker lifecycle (boot, ready, idle reap, replace), proxying and streaming, usage accounting (files + optional Postgres mirror), admin API and console, Prometheus metrics. - Workers (
pbs/,containers/): one generic PBS job script that reads a model TOML and launches the backend inside an Apptainer image; backend shims underpbs/_backends/. - Models (
models/*.toml): one file per served model — backend, resources, engine flags, idle timeout. - Operations (
scripts/,docs/): staging weights, deploying, health checks, evaluation harnesses, runbooks.
Full description: docs/ARCHITECTURE.md · docs/OVERVIEW.md · design history in docs/PHASE_HISTORY.md.
The same OpenAI-compatible API is also consumed by internal agent tooling; nothing in the gateway is specific to any particular client.
llm-gateway/
├── gateway/ FastAPI gateway package, tests, systemd unit, config.example.toml
├── models/ served-model definitions (TOML)
├── pbs/ worker job script, backend shims, container build jobs
├── containers/ Apptainer definitions and build scripts
├── scripts/ staging, deploy, doctor, ops cron, evaluation harnesses
├── admin/ gateway-admin CLI reference, end-user onboarding
├── docs/ architecture, configuration, operations, guides, gotchas, plans
├── .env.example every environment-specific value, with dummy defaults
└── LICENSE Apache-2.0
Placeholders such as HEAD_NODE, CLUSTER_USER, PBS_PROJECT,
SCHEDULER_QUEUE, SHARED_STORAGE, MODEL_STORE, CHECKOUT_ROOT and <gateway-host> appear
throughout; .env.example lists them all. Replace them for your cluster.
Prerequisites: a PBS Pro cluster with GPU nodes and Apptainer, an SSH login to its head node, a shared filesystem visible from the head and the compute nodes, and a host (VM or workstation) that can reach the head over SSH and that clients can reach over HTTPS.
# 1. Gateway host: install the package
git clone https://github.com/<your-org>/llm-gateway.git && cd llm-gateway/gateway
python3 -m venv .venv && .venv/bin/pip install -r requirements.lock && .venv/bin/pip install -e .
# 2. Configure
cp config.example.toml ~/.config/llm-gateway/config.toml # then edit: head node, user, paths, TLS
cp ../.env.example ../.env # values used by scripts/
# 3. Cluster head: build a backend container and stage weights (PBS jobs)
ssh CLUSTER_USER@HEAD_NODE 'bash llm-gateway/containers/build_sglang_sif.sh home'
ssh CLUSTER_USER@HEAD_NODE 'bash llm-gateway/scripts/stage_model.sh llm-gateway/models/glm-5.2.toml'
# 4. Issue a token and start the gateway
gateway-admin issue --user you --label admin --role owner
systemctl --user enable --now llm-gateway # unit in gateway/systemd/Configuration reference: docs/CONFIGURATION.md.
Operations: docs/OPERATIONS.md. Before debugging anything:
scripts/doctor.sh.
curl --cacert ~/.config/llm-gateway/tls.crt -H "Authorization: Bearer $LLMGW_TOKEN" \
https://<gateway-host>:8443/v1/models
curl --cacert ~/.config/llm-gateway/tls.crt -H "Authorization: Bearer $LLMGW_TOKEN" \
-H "Content-Type: application/json" -X POST https://<gateway-host>:8443/v1/chat/completions \
-d '{"model": "glm-5.2", "messages": [{"role": "user", "content": "Hello"}]}'The first request for an idle model boots a worker (cold start of a few minutes); subsequent requests are proxied to the running worker. Any OpenAI-compatible client works: see docs/STUDENT_GUIDE.md (end users), docs/INSTRUCTOR_GUIDE.md (group admins), docs/SUPERADMIN_GUIDE.md (operators) and docs/CLIENT_APPS.md.
| Question | See |
|---|---|
| How is the system put together? | docs/ARCHITECTURE.md |
| Every config knob | docs/CONFIGURATION.md |
| Day-to-day operations (restart, debug, failover) | docs/OPERATIONS.md |
| Footguns we hit (and the fixes) | docs/GOTCHAS.md |
| Why decisions were made | docs/PHASE_HISTORY.md |
| Backend choice (SGLang vs vLLM) | docs/BACKEND_COMPARISON.md |
| What was deferred | docs/FUTURE_WORK.md |
gateway-admin CLI |
admin/README.md |
| Onboard an end user | admin/USER_ONBOARDING.md |
Apache-2.0 — see LICENSE.