On-Premises LLM Deployment Guide: From Hardware Sizing to Production Rollout

    This guide covers the practical steps for deploying large language models on premises, from estimating GPU memory and supporting resources to preparing models, choosing an inference stack, and moving into production. It compares lightweight tools, high-performance engines, multi-GPU orchestration, and domestic accelerator adaptation, and it also addresses out-of-memory issues, latency and concurrency optimization, common errors, license compliance, and how to decide between local deployment and cloud APIs.

    1. Why Enterprises Consider On-Premises Deployment

    Calling cloud-hosted large models is usually billed by token. For low-frequency use, this model is cost-effective. However, for high-frequency, long-term workloads such as internal knowledge base Q&A, coding assistance, and batch document processing, costs accumulate continuously and may exceed the one-time hardware investment.

    Data security is another major reason. Industries such as finance, government, healthcare, and advanced manufacturing have strict data compliance requirements. Business data must remain on the enterprise intranet, and decision processes must be auditable. For these industries, on-premises deployment is often a prerequisite for intelligent upgrades.

    On-premises deployment mainly brings three benefits:

    • Predictable cost: After hardware purchase, the marginal cost per inference is low, but total cost must also include depreciation, electricity, data center space, and operations labor. The benefit is most obvious when equipment utilization is high.
    • Data does not leave the domain: Sensitive business data and user privacy information do not pass through third-party servers, making compliance risks easier to control.
    • Traceable链路? The enterprise can fully retain inference input and output logs for auditing and incident review.

    2. How to Estimate Hardware Before Deployment

    Before choosing a solution, define the hardware boundary. Otherwise, it is easy to select a solution that cannot actually run.

    2.1 How Much GPU Memory Is Needed

    Whether a model can be loaded depends on whether GPU memory can hold two parts at the same time: model weights and intermediate states generated during inference, mainly the KV Cache.

    For an initial estimate, use the following rules of thumb:

    • At FP16 or BF16 precision, weight memory is approximately the number of parameters in billions multiplied by 2, in GB.
    • After INT8 quantization, weight memory is about half of FP16; after INT4 quantization, it is about one quarter.
    • For mixture-of-experts (MoE) models, the activated parameters are the parameters that actually participate in computation for each token. Fewer activated parameters reduce computation and improve throughput, but GPU memory still needs to hold the weights of all experts. Therefore, memory is mainly determined by total parameters and precision.

    The formulas above only give the lower bound for weight memory. In practice, you also need to reserve space for KV Cache, framework overhead, context length, and concurrent requests. During planning, first estimate weight space using 70% to 80% of available GPU memory, then correct the estimate based on measured results.

    2.2 How to Choose a Hardware Tier

    Hardware tier Typical configuration Suitable scenarios Supporting requirements
    Entry level Single consumer-grade GPU, 16 to 24 GB GPU memory Half-precision versions of 7B to 8B models, or INT4 quantized versions of 14B models System memory of at least 32 GB; NVMe SSD
    Advanced Single professional GPU, 40 to 80 GB GPU memory FP16 inference for medium-to-large parameter models Prioritize GPU memory bandwidth; system memory no less than GPU memory capacity
    Enterprise Multi-GPU server with high-speed inter-GPU interconnect Very large parameter models and high-concurrency services Multi-machine scenarios require InfiniBand or high-bandwidth Ethernet
    Domestic compute Domestic AI accelerator cards Domestic-chip and compliance-constrained environments First confirm the model operator and inference framework support list

    2.3 Easily Overlooked Supporting Resources

    • System memory: Used as a transfer buffer during model loading; it is recommended to be no less than total GPU memory.
    • Disk: Model files are usually tens to hundreds of GB. During download, shard merging, and format conversion, reserve two to three times the model size in disk space.
    • Network: In multi-machine deployment, inter-node communication bandwidth determines the efficiency of distributed inference.

    3. How to Set Up the Environment and Obtain Models

    3.1 Set Up the Base Environment

    First check the Python version and CUDA or driver version required by the official documentation of the selected inference framework. The two must match. Dependencies should be placed in an isolated virtual environment (venv or conda) to avoid conflicts with other projects. It is recommended to pin framework versions and record them in the project dependency file.

    Model files can be downloaded from Hugging Face or ModelScope. In network-constrained environments, prefer a reachable hosting platform for more stable downloads; when accessing international platforms, a mirror acceleration service can help.

    3.2 How to Verify After Download

    • Verify files using the SHA256 value provided on the official release page. If the hash does not match, download again.
    • For sharded models, confirm that shard numbers are continuous and the count matches the index file before loading.
    • Use a download tool that supports resumable downloads, such as huggingface-cli, to avoid restarting the entire download after an interruption.

    4. How to Choose Among Four Deployment Approaches

    Clarify the goal first, then choose the approach.

    Core goal Recommended approach
    Quickly validate model quality as an individual Approach 1: Lightweight inference tools
    Internal team service with higher throughput Approach 2: High-performance inference engine
    Model does not fit on a single GPU, or high availability is required Approach 3: Multi-GPU parallelism and container orchestration
    Domestic-chip or compliance requirements Approach 4: Domestic accelerator adaptation

    Approach 1: Use Lightweight Tools for Rapid Experimentation

    Suitable for individual developers. Ollama and llama.cpp (which supports GGUF-format models) both provide command-line startup methods, and you can usually chat through a local interface within a few minutes. Advanced settings include adjusting context length, temperature, top-p, and other sampling parameters. You can also connect a local knowledge base for simple retrieval augmentation.

    Verify three things: whether the service starts normally, whether the interface returns results, and whether answer quality passes manual review with a set of real questions.

    The limitation is clear: throughput and concurrency are limited, so it is not recommended for direct production use. When concurrent requests continue to grow, migrate to Approach 2.

    Approach 2: Use a High-Performance Inference Engine for Production Traffic

    Suitable for teams with some engineering capability. Engines such as vLLM, SGLang, and TensorRT-LLM support continuous batching, efficient KV Cache management, and multi-request concurrency. Taking vLLM as an example, the code for offline batch inference is as follows:

    1. # Dependency: vllm. Pin to the official stable version you use, for example: pip install vllm==<version>
    2. from vllm import LLM, SamplingParams
    3. llm = LLM(
    4. model="./model_weights", # Local model directory; must contain configuration and weight files
    5. tensor_parallel_size=1, # Number of GPUs participating in inference
    6. gpu_memory_utilization=0.85, # Proportion of GPU memory the engine can use
    7. max_model_len=8192, # Maximum context length; directly affects KV Cache usage
    8. )
    9. params = SamplingParams(temperature=0.7, top_p=0.9, max_tokens=512)
    10. outputs = llm.generate(["Explain the principles of quantization techniques"], params)
    11. print(outputs[0].outputs[0].text)

    When integrating with business systems, you can run vllm serve ./model_weights --port 8000 to start a service compatible with a common chat interface format. During integration, mainly modify the request endpoint and model name.

    Verification method: measure first-token latency, output tokens per second, and peak GPU memory under the target concurrency, and run continuous stress tests for several hours to observe whether memory growth or request timeout accumulation occurs.

    Approach 3: Multi-GPU Parallelism and Container Orchestration

    When a single GPU cannot hold the full model, the model must be split across multiple GPUs. Tensor parallelism requires high inter-GPU bandwidth and usually works best within the same server. For cross-machine deployment, pipeline parallelism is more common, but request latency increases.

    This approach should also be combined with a container orchestration platform such as Kubernetes, with health checks and automatic restarts configured to achieve automatic failure recovery.

    Before launch, verify three items: whether inter-GPU communication bandwidth meets expectations, the throughput difference between single-machine multi-GPU and multi-machine approaches, and whether the service can automatically switch when a single GPU or single node failure is simulated. If the multi-GPU approach is unstable, fall back to a quantized single-GPU instance to ensure basic service continuity.

    Approach 4: Domestic Accelerator Adaptation

    When domestic-chip or industry compliance requirements are high, prioritize the vendor’s official inference suite or a mainstream framework that explicitly supports the chip. Before selection, check three lists: whether the operators required by the model are covered, whether the framework version matches the driver and firmware versions, and whether the target model can be loaded on the platform.

    Before launch, run comparative tests against a GPU baseline: compare score differences between the two platforms on the same evaluation set, observe whether outputs are consistent, and record throughput and latency. Stability should also be verified separately. It is recommended to run continuously for several days and record abnormal restarts and error counts.

    If unsupported operators are encountered, first replace them with compatible implementations, or keep a GPU instance as a backup channel and switch gradually in phases. Do not migrate all traffic at once.

    5. What to Do When GPU Memory Is Insufficient

    Prioritize the following three methods and evaluate the trade-offs of each.

    • Quantization: INT8 usually causes a small quality loss, while INT4 causes a more noticeable loss, especially in mathematical reasoning and code generation tasks. Before launch, compare scores before and after quantization using an evaluation set, and retain higher precision for critical tasks.
    • Memory offloading: Place some layers or caches in CPU memory. This can fit larger models, but inference speed drops noticeably. This method is only suitable for low-concurrency or offline tasks and requires continuous latency monitoring.
    • Reduce batch size and maximum context length: This directly reduces GPU memory usage but limits business capability. Before reducing them, confirm the maximum input length with the business team.

    6. What to Do When Inference Becomes Slow

    • Continuous batching: Most inference engines support this by default, and enabling it improves GPU utilization. The key concern is that when the batch is too large, latency for individual requests may increase.
    • Operator fusion: Usually performed automatically by the framework and requires no manual changes. Modifying operators yourself carries higher risk and should be validated in a test environment first.
    • Result caching: Return cached results directly for identical requests, which is suitable for Q&A scenarios. The cache needs an expiration time and sensitive data isolation, especially when sampling temperature is high and answers to the same question may vary.

    Before and after optimization, observe three metrics: first-token latency, output tokens per second, and GPU utilization. Looking at only one metric can easily lead to misjudging the optimization effect.

    7. How to Optimize Under High Concurrency

    • Queuing and timeouts: Set a maximum queue length and request timeout. After exceeding the threshold, fail fast or degrade gracefully to avoid queue buildup causing cascading timeouts.
    • Multi-instance traffic distribution: Distribute requests to multiple inference instances through load balancing. If multi-turn sessions depend on KV Cache within an instance, session affinity is required; otherwise, context will be lost.
    • Scaling timing: Set thresholds based on queue duration and GPU memory utilization. For example, add instances only when queue duration continuously exceeds the upper limit specified by the service level agreement (SLA).

    8. How to Troubleshoot Common Errors

    Check items in the following order. This is faster than random attempts.

    1. Download interruption: Check the download log, resume the download, and compare the SHA256 value.
    2. Loading error: First confirm whether the framework version matches the model format. If ImportError or version conflicts appear in the log, pin dependency versions first. If size mismatch appears, check whether the model configuration corresponds to the weight files.
    3. Port occupation: On Linux, run lsof -i :8000; on Windows, run netstat -ano. After identifying the occupying process, decide whether to change the port or stop the process.
    4. GPU memory overflow (log contains CUDA out of memory): Reduce maximum context length first, then reduce batch size, and finally consider quantization.
    5. Long-text hallucination: Lower sampling temperature and add retrieval augmentation so answers have verifiable evidence.
    6. Excessive KV Cache usage: Use sliding-window attention or paged cache management to reduce fragmented GPU memory usage.
    7. Domestic operator incompatibility: Check the operator coverage list and upgrade to a version verified by the vendor.
    8. Accuracy drop after quantization: Compare results before and after quantization using the same evaluation set, and switch to a higher-precision version if necessary.

    9. How to Conduct Compliance Review

    Open-source model licenses vary significantly and must be checked item by item. Do not rely only on claims that a model is “free to use.” A suggested review checklist includes:

    • License type and whether commercial use is allowed.
    • Distribution conditions for derivative works, including whether attribution or retention of the original license notice is required.
    • Trademark usage restrictions.
    • Training data sources and terms of use.
    • Industry regulatory requirements and retention periods for inference logs.

    Review results can be classified by risk: high risk for prohibited commercial use or separate authorization requirements, medium risk for required source attribution, and low risk for no additional restrictions. High-risk projects should be confirmed by the legal department before launch.

    10. On-Premises Deployment vs. Cloud API Calls

    Comparison dimension On-premises deployment Cloud API calls
    Cost structure High upfront hardware investment, low marginal cost later Pay-as-you-go, no upfront investment
    Data security Data remains on the enterprise intranet Data passes through third-party servers
    Operations requirements Dedicated staff needed to maintain hardware, frameworks, and models Provider manages infrastructure
    Elasticity Scaling requires procurement and deployment cycles Can scale quickly on demand
    Time to launch Usually requires weeks of preparation Usually can be integrated on the same day
    Model upgrades Requires self-download, validation, and switching Provider upgrades centrally

    Use the following rules as a reference: prioritize on-premises deployment when call volume is stable and high-frequency, data sensitivity is high, and the team has operations capability; prioritize cloud API calls when call volume fluctuates widely, hardware budget is limited, and fast launch is desired.

    Many enterprises adopt a hybrid architecture: core sensitive business is deployed on premises, while burst traffic or long-tail scenarios use cloud resources. This approach requires a unified gateway to control routing for sensitive requests and ensure that data does not flow outside due to overflow calls.

    11. Summary

    On-premises deployment involves hardware planning, operations capability, and compliance review. It is a systems engineering effort. Before deployment, calculate GPU memory and supporting resources clearly, then choose an approach based on goals. Before launch, use measured data to verify throughput, latency, and stability. This is more reliable than relying on parameter scale or solution popularity.