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:

    1. def estimate_gpu_memory_gb(
    2. params_b: float, # parameter count in billions, e.g. 7 for 7B
    3. bytes_per_param: float, # FP16=2, INT8=1, INT4=0.5
    4. layers: int,
    5. kv_heads: int,
    6. head_dim: int,
    7. seq_len: int,
    8. batch: int,
    9. kv_bytes: int = 2, # KV cache is usually FP16
    10. margin: float = 0.2, # headroom ratio; calibrate with measurements
    11. ) -> float:
    12. weights = params_b * 1e9 * bytes_per_param
    13. kv_cache = 2 * layers * kv_heads * head_dim * seq_len * batch * kv_bytes
    14. return (weights + kv_cache) * (1 + margin) / 1e9
    15. if __name__ == "__main__":
    16. fp16 = estimate_gpu_memory_gb(7, 2, 32, 8, 128, 4096, batch=8)
    17. int4 = estimate_gpu_memory_gb(7, 0.5, 32, 8, 128, 4096, batch=8)
    18. 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:

    1. torch==2.3.1
    2. transformers==4.44.2
    3. accelerate==0.33.0
    4. bitsandbytes==0.43.3

    The code below loads a local model with 4-bit quantization and generates text:

    1. import torch
    2. from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
    3. MODEL_DIR = "/data/models/your-open-model" # local dir containing weights, config.json, and tokenizer files
    4. def load_model(model_dir: str, quant: str = "int4"):
    5. # Keep trust_remote_code disabled. Only enable it after reviewing
    6. # the custom code in the repository.
    7. tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=False)
    8. qconfig = None
    9. if quant == "int4":
    10. qconfig = BitsAndBytesConfig(
    11. load_in_4bit=True,
    12. bnb_4bit_quant_type="nf4",
    13. bnb_4bit_compute_dtype=torch.bfloat16,
    14. bnb_4bit_use_double_quant=True,
    15. )
    16. model = AutoModelForCausalLM.from_pretrained(
    17. model_dir,
    18. quantization_config=qconfig,
    19. torch_dtype=torch.bfloat16,
    20. device_map="auto",
    21. trust_remote_code=False,
    22. )
    23. model.eval()
    24. return tokenizer, model
    25. def generate(tokenizer, model, prompt: str, max_new_tokens: int = 256) -> str:
    26. inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    27. with torch.inference_mode():
    28. out = model.generate(**inputs, max_new_tokens=max_new_tokens, do_sample=False)
    29. new_tokens = out[0][inputs["input_ids"].shape[1]:]
    30. return tokenizer.decode(new_tokens, skip_special_tokens=True)
    31. if __name__ == "__main__":
    32. tok, mdl = load_model(MODEL_DIR, quant="int4")
    33. 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:

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: llm-infer
    5. spec:
    6. replicas: 1
    7. selector:
    8. matchLabels:
    9. app: llm-infer
    10. template:
    11. metadata:
    12. labels:
    13. app: llm-infer
    14. spec:
    15. containers:
    16. - name: server
    17. image: your-registry/llm-infer:1.0.0
    18. ports:
    19. - containerPort: 8000
    20. resources:
    21. limits:
    22. nvidia.com/gpu: 1
    23. memory: "32Gi"
    24. readinessProbe:
    25. httpGet:
    26. path: /health
    27. port: 8000
    28. initialDelaySeconds: 120
    29. periodSeconds: 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.