Self-hosting

Sharing one GPU

How the models server and the vision service share a GPU, what fits on a 12 GB card, and running on bigger or several cards.

Hubstruct's models run on the GPU in two containers:

ContainerModelsSteps
modelsGemma 4, EmbeddingGemma, d1description, title, reading text, visual, embedding, tagging, nsfw, and search queries
visionFace and text detectorsfaces, finding text

The models server fits the models to the card

The models container is llama-swap in front of llama.cpp: one llama.cpp server per model, started when a step first asks for it and stopped after 10 minutes without use, or when another model needs the room. You don't switch anything by hand: all the steps run, and one whose model isn't loaded yet waits a few seconds for it.

On a 12 GB card, with the default models:

ModelVideo memoryUsed for
Gemma 4 E2Babout 4 GBdescriptions, titles, reading text
d1 2Babout 3.3 GBsmart tags and NSFW
EmbeddingGemma 2about 2 GBsearch, and finding look-alikes

All three fit at once, beside the vision service's models (about 1.7 GB together once warm, given back after 10 minutes without use). The bigger describing model, Gemma 4 E4B (about 6.8 GB, chosen in Settings → Processing), doesn't fit beside d1, so the two take turns: while descriptions run, tagging waits for the model to be swapped, and back. That's slower, as each swap takes a few seconds, but nothing fails.

Which models may run together, and how much context each gets, is in the server's configuration, src/services/models/config.yaml (in the ghcr.io/hubstruct/models image at /etc/llama-swap/config/config.yaml). On a bigger card, mount your own copy there with every model in one set.

Several GPUs

Each GPU service asks Docker for count: all GPUs by default. To pin each to its own card, change its deploy.resources.reservations.devices in the Compose file to device_ids: ["0"], ["1"] and so on. llama.cpp spreads a model that doesn't fit on one card across the cards it's given.

The vision service's settings

VariableDefaultMeans
VISION_TEXT_DEVICEcudaRun the text detector on cuda or cpu.
VISION_CONCURRENCY1How many requests it handles at once.
VISION_FACES_DEVICEcudaRun the face models on cuda or cpu.
VISION_IDLE_MS600000 (10 min)Close the models after this long without a request, giving their GPU memory back. The next request opens them again (a few seconds). 0 keeps them open.
VISION_CPUS8Its CPU limit, and its threads per model.

Without a GPU

The models server's image is built for NVIDIA cards (CUDA 12: Pascal through Ada). Without one, the steps that need a model show as waiting on the dashboard; everything else works. Running the models on the CPU needs llama-swap's CPU image and a configuration without -ngl; we haven't measured how slow that is yet.