A Developer's Guide to Selecting and Deploying Open-Source Large Language Models

    Open-source large language models (LLMs) are now capable of handling a broader range of tasks. Whether to build in-house and how to select the right model depends on data sensitivity, budget, and quality requirements. This guide explores LLM capability boundaries, model selection and comparison (including VRAM estimation), implementation paths such as local deployment, fine-tuning, RAG, and Agents, alongside pre-launch checks. It also includes a practical LoRA-based fine-tuning example for developers.

    1. Conclusions and Scope

    Open-source large language models are increasingly capable of taking on more tasks, but whether to build your own infrastructure and how to select a model depends on data sensitivity, budget constraints, and quality requirements. This article is organized into four parts: capability evolution and boundaries, model selection and comparison, implementation paths (local deployment, fine-tuning, RAG, Agent), and pre-launch checks. The VRAM figures mentioned are estimates based on parameter counts and do not represent actual test results for any specific model. Every solution should be tested with your own data before making a final decision.

    2. Capability Evolution and Boundaries

    2.1 Are Larger Parameters Always Better?

    Parameter count determines a model’s capacity; theoretically, larger capacity allows it to represent more complex language patterns and reasoning paths. However, the relationship between parameters and performance is not strictly proportional. Training data quality, model architecture, training processes, and optimization strategies are equally critical. A large model trained on poor-quality data may underperform on specific tasks compared to a well-designed medium-sized model.

    Therefore, when selecting a model, first evaluate its performance on your specific tasks, then refer to standard evaluation benchmarks. While standard benchmark scores are informative, you must verify whether the evaluation criteria, model version, and test conditions align with your use case.

    2.2 Key Changes in Next-Generation Models

    Over the past two years, open-source weights have become widely available, with parameter scales expanding from the tens of billions to higher tiers. Cloud service providers have also focused on enhancing the following capabilities in next-generation models:

    • Instruction Following: The ability to understand complex instructions with multiple constraints and execute them step-by-step.
    • Long-Context Understanding: The ability to correlate information across paragraphs. This opens up more possibilities for long-document scenarios such as contracts, research reports, and technical documentation.
    • Deep Research: The ability to decompose a question, retrieve, verify, and synthesize information to output a conclusion.

    2.3 Long Context Does Not Equal Effective Understanding

    Some models claim context windows of up to 128K tokens or more, but window length does not mean the model can effectively utilize all the content. To evaluate long-context capabilities, test the model with your own documents. You can bury key clauses in the middle of a document to see if the model can accurately locate them, and design questions that require synthesizing information from two or more paragraphs. Test results should be recorded to serve as a baseline before going live.

    3. Model Selection and Comparison

    Model selection must consider four dimensions: model size, quantization level, deployment method, and cost. VRAM can be roughly estimated using the following formula:

    Weight VRAM ≈ Parameter count × Bytes per parameter

    In FP16 or BF16, each parameter takes 2 bytes; in INT8, 1 byte; and in INT4, about 0.5 bytes. For a 7B parameter model, the weights alone require approximately 14 GB (FP16), 7 GB (INT8), or 3.5 GB (INT4). Actual usage also includes the KV cache, activations, and runtime overhead; the longer the context, the larger the KV cache. Therefore, you must measure the peak VRAM usage under your target context length and concurrency before launching.

    The table below compares several common solutions. The values are only weight estimates:

    Solution Weight VRAM Est. Deployment Method Suitable Scenarios Main Risks
    7B FP16/BF16 ~14 GB Single mid-to-high-end GPU Classification, information extraction, internal Q&A prototypes Limited complex reasoning, prone to errors
    7B INT4 Quantized ~3.5 GB Consumer-grade GPU or CPU, depending on framework Low-cost local tools, offline scenarios Quantization may reduce quality, requires benchmarking
    32B FP16/BF16 ~64 GB Multi-GPU or large VRAM server More complex document analysis High hardware and operational costs
    70B INT4 Quantized ~35 GB Multi-GPU or large VRAM server Long-document analysis, deep research tasks High hardware cost, potentially high latency
    Cloud-based Closed-Source API No local VRAM Pay-per-call Rapid prototyping, non-sensitive data Data must leave the domain, single vendor dependency

    When selecting a model, follow this sequence: first confirm whether data can leave your domain, then confirm the hardware budget. Within those constraints, choose the smallest viable model size, and finally, use your own evaluation set to compare quality differences before and after quantization.

    4. Implementation Paths

    4.1 Local Deployment and Inference Services

    For local deployment, you can choose mature inference frameworks such as vLLM, llama.cpp, or Ollama, depending on your hardware and service requirements. Implementation should follow these steps:

    1. Select a framework in your test environment and load the target model.
    2. Perform stress testing with real requests, recording time-to-first-token (TTFT), throughput, and peak VRAM.
    3. Set maximum context length and concurrency limits to prevent a single request from exhausting resources.
    4. Add authentication to the inference API and log requests (logs must be desensitized, see Section 5).

    4.2 Fine-Tuning: When Is It Worth It?

    Fine-tuning is suitable for solving three types of problems: fixing output formats, standardizing professional terminology, and stabilizing a specific response style. If the requirement involves integrating frequently changing knowledge, prioritize RAG, as the cost of updating knowledge through fine-tuning is high. The recommended sequence is to establish a baseline using prompts and RAG first, and only consider fine-tuning if the performance is insufficient.

    The quality of fine-tuning data is more important than the quantity. Before training, you should deduplicate, clean, and format-check your data, and hold out a portion of the samples as a validation set that does not participate in training.

    Below is a minimal runnable example based on LoRA.

    Environment Setup: It is recommended to install torch, transformers, datasets, peft, and accelerate in a virtual environment. After installation, use pip freeze to record versions for reproducibility. bf16 training requires a GPU that supports bfloat16; mainstream NVIDIA Ampere and newer architectures generally meet this requirement. If your GPU does not support it, switch to FP16 or FP32 and adjust the code accordingly.

    Data Format: In the data file train.jsonl, each line is a JSON object with a text field. The content is a fully concatenated training sample (including the prompt and response), and the format must match the model’s conversation template. Example:

    1. {"text": "Question: What attachments are required for the reimbursement form?\nAnswer: Scanned original invoices and the approval form are required."}

    Training Code:

    ```python
    import torch
    from datasets import load_dataset
    from transformers import (
    AutoTokenizer,
    AutoModelForCausalLM,
    DataCollatorForLanguageModeling,
    Trainer,
    TrainingArguments,
    )
    from peft import LoraConfig, get_peft_model

    MODEL_PATH = “/path/to/local/model” # Local model weights directory
    DATA_PATH = “train.jsonl” # One JSON per line, field is “text”
    OUTPUT_DIR = “lora-out” # LoRA adapter output directory
    MAX_LEN = 512 # Max tokens per sample

    tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
    if tokenizer.pad_token is None:
    tokenizer.pad_token = tokenizer.eos_token

    model = AutoModelForCausalLM.from_pretrained(
    MODEL_PATH