Open-Source LLM Deployment Guide: Model Selection, Fine-Tuning, Serving, and Compliance

    This guide presents a practical path for deploying open-source LLMs in production. It covers closed API versus private deployment trade-offs, memory estimation and model selection, a minimal LoRA/QLoRA fine-tuning configuration, quantization and inference serving choices, key latency metrics, and a security and compliance checklist to complete before switching production traffic.

    1. Confirm the Scope of Any Statistics

    Public reports sometimes cite cumulative download figures of more than 10 billion for open-source LLMs. Such a number can indicate community scale, but it should not be used directly as a model-selection criterion. Different platforms count downloads differently; some include repeated downloads, automatic updates, and mirror-site traffic. Before citing figures like this, check the original announcement from the publisher and confirm the measurement period and methodology. The discussion below does not rely on this number and focuses only on technical and engineering issues that can be reproduced locally.

    2. Open Source vs. Closed Source

    Closed-source models are accessed through APIs and are suitable for quickly validating ideas or for teams without AI engineering experience. Open-source models require the team to handle deployment and operations, but they keep data inside the organization’s own environment and allow model behavior to be audited and modified. The differences are summarized below:

    Dimension Closed-Source API Open-Source Private Deployment
    Startup cost Low; sign up and use High; requires purchasing or renting GPUs
    Per-unit inference cost Billed per token; more expensive as volume grows Mostly fixed cost; more economical at higher utilization
    Data egress risk Data must be sent to a third party Data remains inside the enterprise boundary
    Model controllability Constrained by the provider’s version and policies Can pin versions, fine-tune, and roll back independently
    Operations requirements Almost none Requires model serving, monitoring, and scaling capability
    Compliance audit Depends on materials provided by the provider Can record data and model versions independently

    To decide whether private deployment makes sense, compare two monthly costs:

    Monthly private deployment cost = hardware depreciation (or rental fee) + power and data center costs + allocated operations labor

    If the monthly closed-source API bill consistently exceeds this value, or if business data is not allowed to leave the organization, private deployment is usually more reasonable. Conversely, for workloads with unstable usage, continuing to use an API is simpler.

    3. Model Selection

    Before selecting a model, clarify three things: task type, context-length requirements, and VRAM budget.

    1. Task type: General chat, code generation, information extraction, and industry Q&A require different model capabilities. Domain models usually need fine-tuning on domain data before they meet requirements.
    2. Context length: Long-document analysis and multi-turn conversations require longer context windows. The longer the context, the more VRAM inference consumes.
    3. VRAM budget: Estimate weight VRAM first, then reserve runtime overhead.

    The weight VRAM estimation formula is:

    Weight VRAM (GB) ≈ number of parameters (billions) × bytes per parameter

    Approximate bytes per parameter are: 2 bytes for FP16 or BF16, 1 byte for INT8, and about 0.5 bytes for INT4. For a 7B model, FP16 weights are about 14 GB, and INT4 weights are about 3.5 GB. Actual deployment also requires KV Cache (attention intermediate results stored during inference) and framework overhead, so reserve another 20% to 30%. KV Cache grows with concurrency and context length, so long-context scenarios need a separate estimate.

    After selecting about three candidate models, compare them using your own evaluation set. The evaluation set should contain 100 to 300 real business samples and cover common questions and edge cases. Public leaderboard scores alone often do not reflect business performance.

    4. Minimal LoRA and QLoRA Fine-Tuning Configuration

    The goal of fine-tuning is to teach a general model specific output formats, terminology, and business rules. LoRA trains a small set of low-rank matrices alongside the original model while keeping the original weights unchanged. QLoRA further quantizes the base model to 4 bits, reducing VRAM usage.

    The following is a starting configuration for a 7B-class model that can serve as an experimental baseline:

    1. data:
    2. training_samples: 500-2000
    3. format: JSONL with instruction, input, and output fields per record
    4. validation_split: 10%
    5. base_model: 7B-class open-source chat model
    6. quantization: 4-bit NF4 (QLoRA), compute precision bf16
    7. lora:
    8. rank (r): 16
    9. alpha: 32
    10. dropout: 0.05
    11. target_modules: q_proj, v_proj (expand to all linear layers if VRAM allows)
    12. training:
    13. learning_rate: 2e-4 with cosine decay
    14. epochs: 2-3
    15. per_device_batch_size: 2
    16. gradient_accumulation_steps: 8 (effective batch size 16)
    17. max_seq_length: 2048

    With this configuration, a single GPU with 24 GB of VRAM can usually run the job. If the sequence length exceeds the VRAM limit, reduce batch size or sequence length first before considering a different GPU.

    During training, monitor three issues:

    • Overfitting: Training loss keeps decreasing, but validation loss starts to rise. Reduce the number of epochs or add more training data.
    • General capability degradation: The fine-tuned model performs worse on unrelated tasks. Mix a small number of general instruction samples into the training data to reduce forgetting.
    • Unstable output format: The model occasionally outputs incomplete JSON or extra explanatory text. Add more correctly formatted samples and separately track format pass rate in evaluation.

    After fine-tuning, do not rely only on validation loss. Sample outputs for manual evaluation and compare them with the base model on the same evaluation set.

    5. Inference Serving and Quantization

    Quantization reduces VRAM usage but introduces some accuracy loss. The table below gives approximate weight VRAM for a 7B model at different precisions. Actual values depend on the quantization format and framework implementation, so use measured results.

    Precision Approx. Weight VRAM Suitable Scenario Main Risk
    FP16 / BF16 14 GB Quality baseline; use when VRAM is sufficient High VRAM usage; limited single-card concurrency
    INT8 7 GB Balanced choice for many workloads Accuracy loss is usually small; evaluate by task
    INT4 (AWQ, GPTQ, GGUF Q4) 3.5-4 GB Tight VRAM or edge devices More noticeable degradation on complex reasoning and long-text tasks

    Inference service performance metrics should include at least three items:

    • Time to first token (TTFT): The time from sending a request to returning the first token, which directly affects user perception.
    • Output tokens per second: Measures generation speed for a single instance.
    • P95 latency under concurrency: 95% of requests complete within this time, which reflects real experience better than an average.

    For high-concurrency scenarios, use inference frameworks that support continuous batching, such as vLLM or Text Generation Inference. PagedAttention can reduce KV Cache VRAM fragmentation and improve concurrency. For edge or CPU environments, consider options such as llama.cpp that support the GGUF format. After choosing a framework, load-test it with the same batch of requests and record the three metrics above.

    6. Security and Compliance Checklist

    Open-source models do not automatically meet compliance requirements. Enterprises need controls at three stages: data, model, and output.

    Data collection and fine-tuning stage:

    • Training data has had sensitive personal information such as government ID numbers, phone numbers, and addresses removed
    • Each data batch records its source, authorization scope, and collection time
    • Training and evaluation sets contain no duplicate samples
    • Bias and harmful-content test samples are used to evaluate the fine-tuned model

    Model version management stage:

    • The model license has been reviewed to confirm whether commercial use and redistribution are allowed and under what conditions
    • Model weights, training data, prompts, and configuration files all have version numbers
    • The previous version is retained on every release so it can be rolled back if a failure occurs

    Inference and output stage:

    • Both input and output pass through content safety filtering
    • Personal information in request logs is redacted, and a log retention period is defined
    • Service APIs have authentication and access control
    • Alerts and manual review processes are in place for refusals, privilege escalation, and abnormal output

    7. Three Checks Before Launch

    Step 1, confirm model selection. Verify task type, context length, and VRAM budget, and compare at least two candidate models on your own evaluation set.

    Step 2, confirm deployment. Complete measured testing of the quantization plan, record TTFT, output tokens per second, and P95 latency, and confirm that business requirements are met.

    Step 3, confirm compliance. Complete the security and compliance checklist item by item, especially the license review and rollback plan. Do not switch production traffic until these three checks are complete.

    Open-source models return technical choice to the enterprise, but they also place model quality, operations, and compliance responsibility on the enterprise. Following the three steps above helps teams complete deployment within a controllable range of cost and risk.