Skip to content
mentoor

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  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

  1. Choose the model and fetch it safely

    Skill: local-hub

    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
    FileWhy she checks it
    modeling_custom.pyRuns as code if trust_remote_code is on
    training_args.binPickle format can run code when loaded
    model-*.safetensorsTensor data only
  2. Check the licence and test it on real reviews

    Skill: local-open-weights

    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 sizeShare of trafficOpen modelFrontier model
    Small40%29/3030/30
    Medium35%7/88/8
    Large25%1/22/2
  3. Size the memory and the speed

    Skill: local-hardware

    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
    ComponentGiB
    Usable GPU memory44
    Weights (about 4.8 bits)19
    Runtime overhead1
    Left for KV cache24
  4. Quantize and measure the loss

    Skill: local-quantization

    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
    BuildPerplexityReview tasks passed
    16-bit6.0537/40
    4-bit6.1231/40
  5. Serve it with batching and a cache plan

    Skill: local-serving

    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"
  6. Set the budget and the alerts

    Skill: llmops-budgets

    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
    MeasureTargetNow
    p95 latency20 s or less31.5 s
    Cost per successful review$0.25 or less$0.185
    Evaluation pass rate90% or more92.5%

Skills this scenario uses

Where to study