Private Deployment of LLMs: Running an AI Coding Assistant in a Multi-GPU Environment

    This article shares a practical engineering guide on deploying an open-source large language model (LLM) as an AI coding assistant within a multi-GPU environment. It covers hardware planning, inference framework selection, integration with coding agents through API compatibility, context engineering, performance evaluation, and essential operational considerations. By following this approach, development teams can achieve a stable, cost-effective, and secure local coding experience without relying on external third-party services.

    Background and Motivation

    As Large Language Models (LLMs) rapidly improve in capabilities such as code generation, code review, and refactoring suggestions, an increasing number of developers want to integrate “AI coding assistants” into their daily development workflows. However, two common pain points often arise during actual implementation:

    1. Cost Issues: Mainstream commercial coding assistants charge per seat or per API call. Scaling up for a team incurs considerable expenses, and the subscription fees for high-quality models can be prohibitive for individual developers.
    2. Data and Compliance Issues: Uploading enterprise core code to third-party services poses a risk of leakage. Industries such as finance, government, and manufacturing have strict requirements to keep code assets within their own environments.

    Therefore, the technical route of “acquiring a few high-performance GPUs, running an open-source LLM on local machines, and connecting it to a local coding agent tool” has become highly attractive. This article documents a recent complete practice: deploying an open-source code LLM on multiple servers equipped with data-center-grade GPUs, and summarizing the engineering experience after continuous usage over a period of time.

    I. Hardware and Deployment Topology Selection

    1.1 GPU and VRAM Budgeting

    Before deployment, capacity planning is essential. For models with parameters ranging from tens of billions to hundreds of billions:

    • FP16/BF16 weights: VRAM consumption is approximately “parameter count × 2 bytes”. Adding KV Cache and activations, a 20%~30% margin should be reserved for actual requirements.
    • Quantized deployment: Using INT8/INT4 or FP8 quantization can compress the weight size to 1/2~1/4 of the original, which is the key to accommodating the model on a single machine with multiple GPUs.

    In this practice, a single server was configured with 8 high-end data-center GPUs. Three machines formed a small cluster, splitting the model across multiple GPUs via Tensor Parallelism (TP) to balance throughput and fault tolerance. For most teams, a single server with 4 to 8 GPUs is sufficient to support the daily coding assistance workload for dozens of developers.

    1.2 Inference Framework Selection

    Common open-source inference frameworks in the industry mainly fall into several categories:

    • vLLM-like: A high-throughput serving framework based on PagedAttention, naturally suited for multi-user concurrency scenarios. It is compatible with OpenAI-style API protocols and is the preferred choice for team-level deployment.
    • SGLang-like: Performs excellently in multi-turn dialogue and prefix caching (RadixAttention) scenarios. Coding agents frequently reuse long system prompts, making the benefits of prefix caching highly noticeable.
    • llama.cpp-like: Suitable for single-machine consumer-grade GPUs or CPU hybrid inference. It is good for individual experimentation but not suitable for team-level serving.

    An illustrative service launch command (framework name represented by a placeholder):

    1. python -m inference_server.launch \
    2. --model ./models/code-llm \
    3. --tensor-parallel-size 8 \
    4. --max-model-len 131072 \
    5. --gpu-memory-utilization 0.92 \
    6. --enable-prefix-caching

    Here, --max-model-len determines the upper limit of the context that can be processed. For coding agent scenarios, at least 128K is recommended; otherwise, the code index of large repositories cannot be fed in all at once.

    II. Integration with Coding Agent Tools

    2.1 Protocol Compatibility is Key

    After local deployment, the core issue is making the coding agent tool (represented by command-line interactive agents) recognize the self-built service. The common approach is:

    1. The inference service exposes an OpenAI-compatible Chat Completions API;
    2. Modify the base_url and model name in the tool’s configuration to point to the self-built endpoint;
    3. Handle authentication (internally, simple API Key validation + gateway authentication can be used).
    1. {
    2. "base_url": "http://llm-gateway.internal:8000/v1",
    3. "model": "code-llm-quantized",
    4. "max_tokens": 8192
    5. }

    2.2 Context Engineering Tuning

    For open-source models to approach the coding experience of flagship commercial models, thorough homework must be done on prompt and context management:

    • Simplify system prompts: Open-source models have weaker compliance with ultra-long system prompts compared to flagship models. It is recommended to trim the default prompts provided by the tool and retain only the most core behavioral constraints.
    • Limit repository index size: Agents inject a large amount of file content per turn. A reasonable retrieval scope and token limit must be configured to prevent a “context explosion” that leads to a sudden drop in output quality.
    • Reduce agent automation steps: Errors accumulate in long-chain, multi-step reasoning for open-source models. It is recommended to lower the maximum number of tool call rounds per task initially and manually confirm key nodes.

    III. Performance Evaluation After a Period of Usage

    3.1 Subjective Experience

    After continuous use for several weeks, the overall conclusion is that the output quality is usable, specifically manifesting in:

    • Function generation, completion, and comment quality within a single file are comparable to commercial experiences;
    • “Read-more-write-less” tasks such as code explanation and unit test generation perform stably;
    • Occasional hallucinations (referencing non-existent APIs) occur in complex cross-file refactoring, requiring human supervision.

    3.2 Objective Evaluation Suggestions

    To avoid vague conclusions like “it feels good,” it is recommended to establish a small benchmark:

    1. Fix a set of representative tasks (bug fixes, algorithm implementation, SQL writing, regex construction, etc.);
    2. Use automated scripts to batch call the API and compare test case pass rates;
    3. Record Time To First Token (TTFT) and throughput (tokens/s); the former affects the interactive experience, while the latter determines the total time for an agent’s multi-step tasks.
    1. import time, requests
    2. def bench(prompt):
    3. t0 = time.time()
    4. r = requests.post(API, json={"prompt": prompt, "max_tokens": 512})
    5. dt = time.time() - t0
    6. n = len(r.json()["tokens"])
    7. return dt, n / dt # first token latency and throughput

    IV. Cost and Operational Key Points

    • Power and Cooling: Multi-GPU servers have extremely high power consumption at full load. Data center power supply and cooling solutions must be planned in advance.
    • Model Updates: The open-source community iterates rapidly. It is recommended to use object storage to uniformly manage weight versions, combined with blue-green deployment for updating services.
    • Monitoring and Alerting: Integrate a general monitoring system, focusing on GPU utilization, VRAM usage, and request queue length for timely scaling.
    • Security Boundaries: Even with private deployment, whitelist management should be applied to code network egress and model download sources.

    Conclusion

    Privately deploying an open-source LLM and integrating it with coding agent tools is no longer a question of “can it run,” but rather “how to run it stably and cost-effectively.” This practice demonstrates that, with the help of general open-source inference frameworks and protocol-compatible solutions, teams can entirely achieve an AI coding experience with acceptable quality and localized data on their own hardware. For budget-constrained individual developers, starting with a single-GPU quantized deployment and gradually evolving to a multi-GPU serving architecture is also viable. Maintaining neutrality in technology selection and driving decisions with benchmark testing data are key to the long-term evolution of this route.

    For rapid cloud capabilities, you can also consider using GPU compute instances and model services provided by cloud vendors, combining self-hosted and cloud-based elastic resources to balance cost and flexibility.