Serve an open-weight model on your own hardware
For engineers
Choosing, quantizing, serving and budgeting an open-weight model from the Hub.
One-sentence idea: to run an open-weight model yourself, choose it, size its memory, quantize it, serve it and put a budget on it as one connected plan, because each choice limits the next.
The case
Fernhill Analytics has 40 engineers. Its security team does not allow source code to leave the company, so a hosted assistant is out. Dana, the platform engineer, is asked for a code-review assistant that runs on one server with a single 48 GB GPU. The bar is a review in under 20 seconds at p95 (the time 95 out of 100 reviews beat), at most $0.25 per successful review, and no more than a small quality loss against a frontier model.
Why the skills connect
Every decision feeds the next. The model size sets the weights. The weights and the context length set the memory. The memory sets how many people can be served at once. That sets latency and cost per review. A mistake at the start shows up as a missed budget at the end.
How Dana does it
- Pick and fetch the model. She searches the Hub for an instruct build of a 32B dense model, reads the model card as a list of claims, reads the licence for her use, and downloads a pinned commit. She checks the files and refuses to run repository code she has not read.
- Test it on your own work. She builds a 40-task set from real reviews, weights it like real traffic, and compares the open model with a frontier model. A benchmark on a card is a claim, not a result.
- Do the memory arithmetic. Weight memory is parameters times bytes per parameter. At 16 bits, 32B parameters need 64 GiB. At 8 bits they need 32 GiB. At about 4.8 bits (a 4-bit K-quant) they need about 19 GiB. Only the last leaves room on a card with 44 GiB usable.
- Quantize and measure. She takes a 4-bit build and runs the same 40 tasks. Perplexity (how surprised the model is by general text) barely moves, but the task pass rate is what she ships on.
- Serve and size the cache. She runs vLLM with continuous batching. Each token of context costs KV cache: 64 layers, 8 KV heads and head size 128 in 16-bit is 256 KiB per token. An 8,192-token sequence takes 2 GiB, so 24 GiB of free cache holds 12 sequences. At 16,384 tokens it holds 6.
- Budget and alert. She turns the targets into numbers, measures p50 and p95, divides the monthly cost by successful reviews, and chooses the change that fits every limit.
vllm serve fernhill/review-32b-awq \
--max-model-len 8192 \
--gpu-memory-utilization 0.90 \
--api-key "$REVIEW_API_KEY"
Before and after
Before: "The card says it beats frontier models, a 4-bit file fits on the card, so we launch with 16k context for 12 users." After: the evaluation is re-weighted by real traffic, the quantized build is scored on the review tasks, the cache is calculated for the chosen context, and the launch has an API key, a timeout and alerts on queue depth and cache use.
What goes wrong
- A headline score hides a weak slice. A model that passes 92.5% overall can fail half of the large diffs that make up a quarter of traffic.
- Memory is counted for weights only. The cache grows with context and users, and a longer context cuts concurrency.
- Cost is divided by calls, not by successes. Failed runs use the GPU and produce nothing.
- Owning is assumed cheaper. At 8,800 reviews a month, a hosted API can cost less than a rented server. Owning is justified here by privacy, and the numbers should say so.
- The endpoint is left open. An internal network is not authentication.
Assistants can write these commands, tables and checklists quickly, and they often get one detail wrong while sounding certain. Dana checks every number with her own arithmetic before it goes into a plan.
Steps
Choose the model and fetch it safely
Dana searches for an instruct build of a 32B dense model, reads the card as claims, and pins a commit. She flags two files for review before loading anything.
hf download fernhill-mirror/review-32b-instruct --revision 9f3c2e1 --include "*.safetensors" "*.json"Files she reviews first Repository listing File Why she checks it modeling_custom.py Runs as code if trust_remote_code is on training_args.bin Pickle format can run code when loaded model-*.safetensors Tensor data only Check the licence and test it on real reviews
She confirms the licence allows internal commercial use, builds 40 review tasks that match real traffic, and scores the open model against a frontier model. The result by diff size, not the average, decides.
Evaluation weighted by traffic Passes by diff size Diff size Share of traffic Open model Frontier model Small 40% 29/30 30/30 Medium 35% 7/8 8/8 Large 25% 1/2 2/2 Size the memory and the speed
Weights plus KV cache plus overhead must fit in 44 GiB usable. At 960 GB/s and 19 GB of weights per token, one user can expect at most about 50 tokens per second.
Memory plan 4-bit build of the 32B model Component GiB Usable GPU memory 44 Weights (about 4.8 bits) 19 Runtime overhead 1 Left for KV cache 24 Quantize and measure the loss
She picks a 4-bit K-quant because 8-bit leaves only 12 GiB. She then runs her task set on both builds. Perplexity is a sanity check, and the pass count decides.
Quantization check 16-bit versus 4-bit on the review tasks Build Perplexity Review tasks passed 16-bit 6.05 37/40 4-bit 6.12 31/40 Serve it with batching and a cache plan
With 24 GiB of cache and 2 GiB per 8,192-token sequence, the server holds 12 sequences. She keeps the 8k limit, requires an API key and puts the endpoint behind TLS.
launch.sh launch.sh
vllm serve fernhill/review-32b-awq \ --max-model-len 8192 \ --gpu-memory-utilization 0.90 \ --api-key "$REVIEW_API_KEY"Set the budget and the alerts
She divides $1,500 by 8,096 successful reviews for $0.185 each and measures p95 against the 20 s target. Prefix caching on the shared prompt is the change that meets every limit. Alerts watch p95, failures and cache use, not spend, because the server's cost is flat.
Budget status Targets and measurements Measure Target Now p95 latency 20 s or less 31.5 s Cost per successful review $0.25 or less $0.185 Evaluation pass rate 90% or more 92.5%
Skills this scenario uses
Where to study
- vLLM documentation (opens in a new tab)DocsFree
Serve flags, quantization support, parallelism and prefix caching used in the launch command.
- Hugging Face Hub documentation (opens in a new tab)DocsFree
Gated models, revisions, model cards and repository security for downloading models.
- Hugging Face Hub command line guide (opens in a new tab)ArticleFree
How to log in and download a pinned revision with the CLI.
- llama.cpp (opens in a new tab)ToolFree
The GGUF format, the convert and quantize tools and the K-quant levels.
- Safetensors documentation (opens in a new tab)DocsFree
Why a tensor-only format is safer to load than pickle files.
- Efficient Memory Management for LLM Serving with PagedAttention (opens in a new tab)PaperFree
The paper behind vLLM's KV cache management and continuous batching.
- Model Cards for Model Reporting (Mitchell et al.) (opens in a new tab)PaperFree
What a model card should report and why to read the gaps.