Open-Source LLM Weights: What to Check Before Going to Production
Once the weights of an open-source LLM are published, any team can download, test, and deploy them. But usable weights do not mean production-ready. Before going live, you need to confirm at least three things: the license permits your intended use, GPU memory can hold the model with headroom to spare, and the service can handle real concurrency and be monitored. This article walks through five parts—model evaluation, GPU memory estimation, model loading and inference, cloud-native serving, and troubleshooting and compliance—each with checklists, formulas, or code. It is vendor-agnostic; always read the official model card first, and treat all numbers and versions as examples to be verified against official documentation and your own measurements.
Once the weights of an open-source LLM are published, any team can download, test, and deploy them. But usable weights do not mean production-ready. Before going live, you need to confirm at least three things: the license permits your intended use, GPU memory can hold the model with headroom to spare, and the service can handle real concurrency and be monitored. This article covers five parts, each with checklists, formulas, or code.
This article does not target any specific vendor or model. Before using any model, read its official model card to confirm the license, commercial-use terms, and usage restrictions. All numbers and versions below are examples; verify them against official documentation and your own measurements.
1. How to Evaluate Whether a Model Fits Your Business
Start with whether the model can actually do your job. Public leaderboard scores only reflect performance on specific test sets and cannot directly represent your business outcomes. Evaluate with your own data.
| Dimension | How to check | Pass criteria | Weight |
|---|---|---|---|
| Business fit | Sample 200+ records from your own data and score them by business rules | Key task metrics meet team-defined thresholds | 40% |
| Inference cost | Estimate GPU count and cost from target QPS and average token count | Cost per request within budget | 20% |
| Output stability | Run the same input repeatedly; measure the rate of valid structured output | Pass rate meets team threshold | 15% |
| Context length | Test with the longest real production inputs | Covers 95%+ of request lengths | 10% |
| Ecosystem and maintenance | Check update frequency, issue response time, inference framework support | Loads directly in mainstream inference frameworks | 15% |
Score each dimension from 0 to 100, then apply the weights:
Overall score = Business fit × 0.4 + Inference cost × 0.2 + Output stability × 0.15 + Context length × 0.1 + Ecosystem × 0.15
A worked example (fictional, for illustration only): if a model scores 80, 60, 90, 70, and 75 on the five dimensions, the overall score is 80 × 0.4 + 60 × 0.2 + 90 × 0.15 + 70 × 0.1 + 75 × 0.15 = 75.75.
The license is not part of the weighted score—it is a veto. If the license does not allow commercial use, redistribution, or your specific use case, the model is out of the candidate list regardless of its score.
2. How to Estimate GPU Memory
Insufficient GPU memory is the most common cause of failed deployments. Estimate before deploying:
GPU memory required ≈ (weight memory + KV cache memory) × (1 + margin ratio)
Weight memory = parameter count × bytes per parameter
- FP16 or BF16: 2 bytes per parameter
- INT8: 1 byte per parameter
- INT4: 0.5 bytes per parameter. Quantization parameters and scaling factors consume additional memory; verify with actual measurements after loading.
KV cache memory = 2 × layers × KV heads × head dimension × sequence length × batch size × bytes per element
Take a 7B (7 billion parameter) model. In FP16, weights are roughly 7 × 10⁹ × 2 bytes = 14 GB. In INT4, weights are roughly 3.5 GB, plus quantization overhead that must be measured.
KV cache grows with sequence length and batch size. Assume a model with 32 layers, 8 KV heads, head dimension 128, sequence length 4096, in FP16. At batch size 1, KV cache is about 2 × 32 × 8 × 128 × 4096 × 1 × 2 bytes ≈ 0.54 GB. At batch size 8, about 4.3 GB.
The following function encodes these formulas; the margin ratio should be calibrated with real measurements:
def estimate_gpu_memory_gb(params_b: float, # parameter count in billions, e.g. 7 for 7Bbytes_per_param: float, # FP16=2, INT8=1, INT4=0.5layers: int,kv_heads: int,head_dim: int,seq_len: int,batch: int,kv_bytes: int = 2, # KV cache is usually FP16margin: float = 0.2, # headroom ratio; calibrate with measurements) -> float:weights = params_b * 1e9 * bytes_per_paramkv_cache = 2 * layers * kv_heads * head_dim * seq_len * batch * kv_bytesreturn (weights + kv_cache) * (1 + margin) / 1e9if __name__ == "__main__":fp16 = estimate_gpu_memory_gb(7, 2, 32, 8, 128, 4096, batch=8)int4 = estimate_gpu_memory_gb(7, 0.5, 32, 8, 128, 4096, batch=8)print(f"FP16 ~ {fp16:.1f} GB, INT4 ~ {int4:.1f} GB")
This example prints roughly FP16 22.0 GB and INT4 9.4 GB. Compare the estimate against the memory capacity of a single GPU, and re-verify under real load.
3. How to Load the Model and Run Inference
Dependency versions must match the CUDA driver on your machine. One example set:
torch==2.3.1transformers==4.44.2accelerate==0.33.0bitsandbytes==0.43.3
The code below loads a local model with 4-bit quantization and generates text:
import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfigMODEL_DIR = "/data/models/your-open-model" # local dir containing weights, config.json, and tokenizer filesdef load_model(model_dir: str, quant: str = "int4"):# Keep trust_remote_code disabled. Only enable it after reviewing# the custom code in the repository.tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=False)qconfig = Noneif quant == "int4":qconfig = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_quant_type="nf4",bnb_4bit_compute_dtype=torch.bfloat16,bnb_4bit_use_double_quant=True,)model = AutoModelForCausalLM.from_pretrained(model_dir,quantization_config=qconfig,torch_dtype=torch.bfloat16,device_map="auto",trust_remote_code=False,)model.eval()return tokenizer, modeldef generate(tokenizer, model, prompt: str, max_new_tokens: int = 256) -> str:inputs = tokenizer(prompt, return_tensors="pt").to(model.device)with torch.inference_mode():out = model.generate(**inputs, max_new_tokens=max_new_tokens, do_sample=False)new_tokens = out[0][inputs["input_ids"].shape[1]:]return tokenizer.decode(new_tokens, skip_special_tokens=True)if __name__ == "__main__":tok, mdl = load_model(MODEL_DIR, quant="int4")print(generate(tok, mdl, "Explain what GPU memory is in one sentence."))
If the model repository ships pre-quantized weights, common formats are AWQ and GPTQ. They require their respective loading libraries; check the official documentation for library names and interfaces.
| Quantization method | Weight form | Dependency | Notes |
|---|---|---|---|
| BitsAndBytes 4-bit | Quantized at load time | bitsandbytes | Good for quick validation; verify CUDA version |
| AWQ | Pre-quantized weights | Corresponding AWQ loading library | Confirm the repo provides AWQ weights and config files |
| GPTQ | Pre-quantized weights | Corresponding GPTQ loading library | Verify quantization config against library version |
After quantization, compare the original precision against the quantized precision on the same evaluation set and record the difference. There is no universal number for accuracy loss—it can only be measured on your own data.
4. How to Build a Cloud-Native Service
A single-process script is fine for validation, not for production. Serving requires handling concurrency, health checks, rate limiting, and monitoring.
- Inference engine: in production you can use inference-serving frameworks such as vLLM or TGI, which provide mature batching and KV cache management. Before launch, verify that the framework supports the model architecture and quantization format.
- Concurrency control: set a maximum concurrency and queue length. Return 429 when the queue is full, so request buildup does not trigger OOM.
- Rate limiting and caps: rate-limit by API key and cap max_tokens per request, so a single request cannot exhaust GPU memory.
- Health checks: model loading takes a long time; give the readiness probe enough startup delay, or the container will be restarted repeatedly.
- Monitoring: at minimum, collect time to first token, output tokens per second, GPU memory usage, queue length, and error rate.
- Auth and logging: the inference endpoint must require authentication. Do not log full user inputs and outputs, or log only redacted content.
Here is a Kubernetes deployment snippet showing GPU resource requests and a readiness probe:
apiVersion: apps/v1kind: Deploymentmetadata:name: llm-inferspec:replicas: 1selector:matchLabels:app: llm-infertemplate:metadata:labels:app: llm-inferspec:containers:- name: serverimage: your-registry/llm-infer:1.0.0ports:- containerPort: 8000resources:limits:nvidia.com/gpu: 1memory: "32Gi"readinessProbe:httpGet:path: /healthport: 8000initialDelaySeconds: 120periodSeconds: 10
Adjust the image tag and memory limit to your actual model and load.
5. Troubleshooting and Compliance Checks
The most common post-launch failures:
| Symptom | Common cause | Fix |
|---|---|---|
| CUDA out of memory | Sequence length or batch size too large, no headroom reserved | Reduce max_new_tokens and batch size, use lower precision, or add GPUs |
| CUDA or driver errors | Driver version does not match the CUDA version torch was built against | Check the driver with nvidia-smi; install matching versions per the framework’s official compatibility matrix |
| Quantized model fails to load | Quantization format does not match the loading library, or config files are missing | Verify quantization_config against the loading library version |
| Garbled or malformed output | Tokenizer and weight versions mismatch, or wrong chat template | Always use the tokenizer files from the same model card |
| Degraded output quality | Quantization loss or precision change | Compare on your own evaluation set; switch precision or model if needed |
| File checksum errors at load/startup | Model files incomplete or replaced | Verify against the officially published SHA256 checksums |
Compliance checklist:
- The license permits the intended use, including commercial use, redistribution, and internal deployment.
- Confirm the usage restrictions in the model card and keep a copy of the license file.
- Confirm that the terms for training data and output content meet business requirements, and that personal data handling complies with internal policies.
- Model files come from a trusted source and have been verified.
- Legal or compliance staff have reviewed the deployment before launch. If terms are not met, switch models—do not circumvent license restrictions.
Final pre-launch checklist: license reviewed; business metrics met on the evaluation set; GPU memory estimate calibrated with real measurements and headroom reserved; quantized precision compared; the service has concurrency control, health checks, and monitoring; logging and access control configured; troubleshooting procedures documented in the operations runbook.
