Team AER

One GPU, many models. No one waits forever.

Avifors sits behind your OpenAI-compatible gateway, loads the model each request needs, and bounds how long any workload can hold the card.

GET /admin/state

policy
latency
state
ready
resident
aer-stt-v1
queued
0
lease_remaining_seconds
217
text-chat text-chat aer-stt-v1 9:40 ana ben ana asleep ben ben ana ana kai kai kai waits while text-chat drains ana, 2 h recording lease 0 s at 7:34 ben’s stream: error eventworker reset, memory freed embed flux2-klein 10.7 GiB worker text-chat vLLM, sleep: true unloaded embed HTTP worker unloaded flux2-klein sdapi, FLUX.2 Klein unloaded aer-stt-v1 stt, durable jobs lease 217 s GPU memory one 16 GiB card 16 0

Illustrative trace: one 16 GiB card, policy: latency, max_hold: 300, three users. Not a benchmark.

  • queued
  • activate
  • serve
  • idle
  • release
  • lease left
  • lease used
  • GPU memory

How a request moves

Every call on the trace above goes through the same four steps. The colours are the ones the timeline uses.

  1. 1admit

    The request joins the queue for its model. Global, per-model and per-user max_pending limits count queued and running work, and a full queue answers 429.

  2. 2activate

    If another model holds the card, it drains and then stops or sleeps. release_check confirms the memory is free, the next worker starts, and its health check has to pass.

  3. 3serve

    Requests go to the worker as sent, up to its concurrency. Avifors never changes sampling, context, quantization or vLLM batch settings.

  4. 4expire

    The lease counts down from max_hold. At zero, running work is cancelled and the worker is reset to prove it stopped, then the next model in line loads. An idle lease with nobody waiting renews without a reload.

Load on demand, unload on time

idle_timeout: 300

The broker starts at boot with every model unloaded. Real inference activates a worker; an idle timeout or a competing model releases it.

  • unloaded

    Nothing on the card. Where the broker boots.

  • loading

    start runs, or a wake for a sleeping vLLM, until the health check passes within activation_timeout.

  • ready

    Requests are admitted up to the worker’s concurrency.

  • draining

    Another model is waiting. No new admissions; running work finishes.

  • releasing

    stop and verify_stopped, or a level-1 sleep, then release_check.

One worker’s states, named as /admin/state reports them, with its GPU memory above.

Commands, not shell strings

Start, stop and verify are argument arrays the administrator writes, never request input. Stops must be idempotent and confirm termination.

Memory checked at every handoff

A root-owned release_check command you supply confirms the GPU has room before the next worker starts. If a release fails, admission stops rather than starting a second owner.

vLLM sleep, level 1

With sleep: true on a vLLM launched with --enable-sleep-mode, weights move to CPU RAM and the KV cache is discarded. A failed sleep falls back to a full stop.

Probes that load nothing

/v1/models and a scoped /backend/NAME/v1/models answer health checks without activating a model. A faulted model reports failure until it activates again.

Fair to many users

policy: latency | fifo | fair | throughput

One setting, server.policy, decides which model gets the card next and whose request runs first. Every limit counts queued and running work.

The four scheduling policies
Policy Switches models Next model Next request for that model
latencydefault As soon as another model queues: stop admitting, drain running work, switch. The earliest waiting request’s model. Arrival order.
fifo When the oldest request in the global queue is for a different model. Strict arrival order; only consecutive compatible jobs batch. Arrival order.
fair As soon as another model queues, like latency. Least measured service time per weight. Aging lets a model that has waited a full max_hold go next. The user with the least measured service time.
throughput When the current model runs out of queued work, or drain_margin seconds before its lease ends. The earliest waiting request’s model. Arrival order.
config.yaml
users:
  - name: ana
    key_env: AVIFORS_KEY_ANA
    models: ["*"]
    max_pending: 8
  - name: ben
    key_env: AVIFORS_KEY_BEN
    models: ["*"]
    max_pending: 8
  - name: kai
    key_env: AVIFORS_KEY_KAI
    models: [embed, flux2-klein]
    max_pending: 2

Authentication is on by default. For a private gateway, trusted_networks can admit keyless calls from listed networks; they all share one identity and the trusted_max_pending quota.

Keys come from the environment

Each named user’s bearer key is read from the variable in key_env and must be at least 16 characters. The config file never holds it.

Allowlists and pending limits

models limits which model ids a user may call; max_pending caps their requests alongside the model and global limits.

Keys stop at the broker

API keys are never forwarded to workers, and caller-supplied forwarding or user headers never establish identity.

A separate admin key

/admin/state needs its own key and reports residency and aggregate queues, not prompts or credentials.

Leases, not hopes

max_hold: 300

Every ownership period has a deadline, and it holds whether or not the work has finished. That is what lets the next request in line count on getting the card.

lease

max_hold starts before activation.

activate

activation_timeout bounds start and health check.

request a

Waiting counts against queue_timeout, not the lease.

request b

Admitted late, it gets only what is left of the lease.

0 s: cancel, reset, release
One ownership period of 300 seconds. The lease starts before activation. Request a waits in the queue, then runs well inside the lease. Request b is admitted late and is cut off when the lease reaches zero, after which the worker is reset and released.
max_hold
300
Ownership period, counted from before activation.
max_runtime
300
Per request, cut short by the ownership period.
queue_timeout
300
Longest wait for admission.
activation_timeout
180
Start plus health check.
release_timeout
15
Each stop, sleep or verify command.
idle_timeout
300
From the last finished inference, not from health probes.

Defaults, in seconds. Set them under defaults or per model.

429
Queue full.
503
Worker fault.
504
Deadline reached before response headers.
A stream at its deadline
data: {"error": {"message": "GPU execution deadline exceeded", "type": "avifors_error"}}

Late requests get the remainder

A request admitted late in an ownership period gets only the budget that is left. No active request extends a lease.

Streams end with an error, not a fake finish

A response that is already streaming cannot change its HTTP status, so the deadline arrives as an error event in the stream.

A reset proves it stopped

At a deadline or worker failure the broker resets the worker. Other requests on that worker may fail too; there is no transparent replay.

Disconnects stay contained

A queued disconnect removes its request. An executing one drains within its original deadline and never resets other users’ work.

Chat, images, speech and decisions

kind: openai
kind: sdapi
kind: stt
kind: decision

HTTP, image, speech and decision workers share a scheduler. Each keeps its own runtime; configured lanes can keep CPU decisions separate from GPU inference.

openaidefault

vLLM text and any HTTP worker you define

JSON and multipart bodies pass through without sampling rewrites. Request and trace context is forwarded; worker credentials, cookies and lifecycle endpoints are not.

  • /v1/chat/completions
  • /v1/completions
  • or the /v1/ paths you register

sdapi

Images through a Stable Diffusion API adapter

OpenAI-shaped requests with n=1 and URL output, sent to an engine’s /sdapi/v1/txt2img, such as stable-diffusion.cpp. PNGs are written atomically before the response, and authenticated reads keep working while the worker is unloaded, isolated by user, for 24 hours by default.

  • /v1/images/generations
  • /generated/NAME.png

stt

Multilingual speech, as durable jobs

Recordings up to 8 hours and 2 GiB by default, checkpointed in chunks of up to 30 seconds that each run as an ordinary GPU job, so a long file never extends a lease. Poll, cancel, retry, and download text, JSON, SRT or VTT. Subtitle cues follow chunk boundaries, not word alignment, so treat them as drafts.

  • /v1/audio/transcriptions/jobs
  • /v1/audio/transcriptions

render_sizessdapi profile

FLUX.2 Klein 9B FP8 render profiles

The example profile renders legacy 512 and 640 square requests at 1024 and returns exactly the size asked for. On one qualification run, a 16 GiB RTX 4060 Ti produced a 1024×1024 image in 25.02 seconds, with 10,922 MiB sampled peak device memory. One run, not a benchmark.

  • FLUX2.md
  • deploy/flux2/

Drop-in behind your gateway

host: 127.0.0.1
port: 8000

Clients keep the OpenAI-compatible routes they already call. Your gateway keeps TLS and routing; Avifors sits behind it and the workers stay on loopback.

  • ClientsOpenAI SDKs, curl
  • Your gatewayTLS, routing, catalog
  • avifors127.0.0.1:8000
  • Workers on loopback:18000 text
    :1234 image
    :18002 speech
POST /v1/chat/completions
Text, streamed or not.
POST /v1/images/generations
Images from an sdapi worker.
POST /v1/audio/transcriptions/jobs
Durable speech jobs; poll by job id.
GET /v1/models
Catalog and health. Never loads a model.
GET /backend/NAME/v1/models
Scoped health for one worker.
GET /metrics
Queue and lifecycle counters.
GET /admin/state
Residency and aggregate queues, with the admin key.

What it leaves to you

  • Models. Avifors does not download weights. Engines, weights and NVIDIA drivers are installed separately.
  • Token scheduling. vLLM keeps its own scheduler; Avifors does not replace it.
  • Other GPU users. It controls its configured workers and cannot arbitrate anything else on the card.
  • Restarts. Pending requests are not persisted and fail when the broker restarts.
  • Your hardware. Real performance, GPU release and sleep compatibility have to be tested on the target GPU.

Install and check a config

requires-python >=3.14

Linux is recommended for production. The broker requires Python 3.14+, aiohttp, PyYAML and Pillow; the isolated Omnilingual speech worker uses Python 3.12. Engines, weights and drivers come from you. Adapt the example’s model ids, paths and worker commands before the first run.

shell
git clone https://github.com/Team-AER/avifors.git
cd avifors
python3.14 -m venv .venv
.venv/bin/pip install .
export AVIFORS_USER_KEY='replace-with-a-long-secret'
export AVIFORS_ADMIN_KEY='replace-with-another-secret'
.venv/bin/avifors --config examples/config.yaml --check
.venv/bin/avifors --config examples/config.yaml

--check validates the file and prints the model count and policy, for example Valid configuration: 2 models, policy=latency.

Optional native systemd deployment
sudo cp deploy/avifors.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now avifors.service

Production also supports Docker Compose with an unprivileged broker and a controller sidecar. Create workers without starting them; the broker owns their lifecycle. See Docker deployment notes for configuration and startup. The optional native unit expects the broker in /opt/avifors/.venv and the config at /etc/avifors/config.yaml, runs as a dedicated avifors user and reads keys from /etc/avifors/secrets.env. Give workers Restart=no and no boot enablement: only the broker starts at boot, with models unloaded. Read the deployment notes

examples/config.yaml, trimmed
server:
  host: 127.0.0.1
  port: 8000
  policy: latency # latency | fifo | fair | throughput
  max_pending: 64
  admin_key_env: AVIFORS_ADMIN_KEY
  store: ./local/images
  public_base: http://localhost:8000/generated
  drain_margin: 15
users:
  - name: example-user
    key_env: AVIFORS_USER_KEY
    models: ["*"]
    max_pending: 8
defaults:
  idle_timeout: 300
  max_hold: 300
  max_runtime: 300
  queue_timeout: 300
  activation_timeout: 180
  release_timeout: 15
models:
  - id: your-text-model
    upstream: http://127.0.0.1:18000
    start: [sudo, /usr/local/sbin/avifors-worker, start, text]
    stop: [sudo, /usr/local/sbin/avifors-worker, stop, text]
    verify_stopped: [sudo, /usr/local/sbin/avifors-worker, verify, text]
    concurrency: 4
    parameters: {route: text}
  - id: your-image-model
    kind: sdapi
    upstream: http://127.0.0.1:1234
    health_path: /v1/models
    paths: [/v1/images/generations]
    start: [sudo, /usr/local/sbin/avifors-worker, start, image]
    stop: [sudo, /usr/local/sbin/avifors-worker, stop, image]
    verify_stopped: [sudo, /usr/local/sbin/avifors-worker, verify, image]
    concurrency: 1
    parameters:
      route: image
      default_size: 640x640

Put one GPU on a schedule.

Avifors is MIT licensed. Inference engines, model weights and vendor dependencies keep their own licences, and none of them ship in the repository.