How to Select and Deploy Open-Source Chinese LLMs: A Practical Engineering Guide

    As open-source large language models grow more capable, more enterprises are evaluating them for private deployment. This article covers recent progress in open-source Chinese LLMs, including deployment challenges from growing parameter counts, KV Cache memory planning, improvements in instruction following and long-context understanding, and infrastructure considerations. It also provides a code example for a unified inference wrapper and a practical checklist for model selection and launch.

    As open-source large language models continue to improve, more and more enterprises are evaluating how to integrate them into their own business systems. Open-source model weights can be downloaded and deployed privately, but there is still a large amount of engineering work between “getting it to run” and “running it reliably.” This article reviews recent changes in the core capabilities of open-source Chinese LLMs and explains the key metrics to consider when selecting and deploying them.

    According to public reports, the cumulative weight downloads of open-source Chinese models have reached the tens of billions level. However, each platform uses different counting methods, and numbers from platforms like Hugging Face and ModelScope cannot simply be added together. Download counts reflect community interest but say little about whether a given model fits a particular business. Model selection should always come back to the task itself, tested with your own data.

    1. Deployment Pressure from Growing Parameter Counts

    As parameter counts grow, a model’s knowledge capacity and reasoning ability generally improve, but deployment difficulty increases as well. When a model reaches tens or hundreds of billions of parameters, a single GPU often cannot hold all the weights in memory. At that point, you need tensor parallelism or pipeline parallelism to split the model across multiple GPUs or machines.

    To reduce memory usage and inference cost, INT8 and INT4 quantization (such as GPTQ and AWQ) has become common practice. Quantization introduces some accuracy loss, and the magnitude depends on the model architecture, calibration data, and task type. It’s recommended to compare accuracy before and after quantization on your target business data, while also recording throughput, first-token latency, and memory usage.

    2. Planning KV Cache Memory Capacity

    When handling long texts or high-concurrency requests, KV Cache is often one of the largest consumers of GPU memory. Many people mistakenly assume it grows exponentially with context length, but in reality its size scales roughly linearly with sequence length and batch size. You can estimate capacity with the following formula:

    KV Cache memory ≈ 2 × number of layers × number of KV heads × head dimension × sequence length × batch size × bytes per element

    The factor of 2 accounts for the K and V caches. For models using GQA or MQA, the number of KV heads is far smaller than the number of attention heads, so the cache is significantly smaller—always use the actual values from the model’s configuration file when estimating.

    Mechanisms like PagedAttention split the KV Cache into fixed-size blocks allocated on demand, reducing memory fragmentation and improving concurrency. The benefit depends on the distribution of request lengths. If request lengths are fairly uniform, fragmentation is already low and gains will be limited. During load testing, monitor both fragmentation rate and request queuing time.

    3. Instruction Following, Long-Context Understanding, and Long-Horizon Tasks

    Newer open-source models are more stable at instruction following, less likely to go off-topic or produce rambling output. Developers can further constrain output formats with stricter system prompts and few-shot examples. In RAG systems, models are more willing to answer based on retrieved context, which helps reduce hallucination rates. That said, hallucinations cannot be fully eliminated, so citation verification is still necessary.

    Long-context understanding allows models to process inputs of tens or even hundreds of thousands of words. This typically relies on RoPE positional encoding extensions and efficient attention implementations like FlashAttention. For tasks such as global summarization and key information extraction, long context can reduce dependence on vector databases. But for scenarios where knowledge needs frequent updates or results require traceability, retrieval augmentation remains the better fit.

    Long-horizon task capabilities enable models to break down tasks, call tools, analyze web pages, and consolidate results into structured reports. These Agent applications also carry higher risks. Tool calls can fail, multi-step reasoning can accumulate errors, and token costs per request can spiral out of control. Before going live, set maximum step counts, timeouts, and budget limits.

    4. Infrastructure: A Reference from Baidu AI Cloud

    Model deployment requires compute, storage, and observability working together. Taking Baidu AI Cloud as an example, elastic GPU instances and container platforms can scale compute up and down with traffic fluctuations. Model weights can be stored in object storage (BOS) with unified version management and mounted on demand at service startup, shortening cold start time. Actual cold start duration depends on weight size, network bandwidth, and loading method, so benchmark it in your own environment.

    In Agent scenarios, a single user request may trigger multiple model calls and tool calls. Logging services and monitoring alerts can record the latency and token consumption of each step, helping pinpoint the source of latency and cost anomalies. The more complete your tracing coverage, the faster you can troubleshoot.

    5. Example: A Unified Inference Wrapper

    The following example calls a model service that is compatible with the OpenAI Chat Completions format via HTTP, and performs basic validation on the response. It depends on the requests library, version 2.31 or later is recommended.

    1. import json
    2. import requests
    3. def invoke_llm_with_instruction(api_url, api_key, instruction, user_input):
    4. """
    5. Call an LLM service and require it to output JSON according to the given instruction.
    6. """
    7. headers = {
    8. "Content-Type": "application/json",
    9. "Authorization": f"Bearer {api_key}",
    10. }
    11. system_prompt = (
    12. "You are a professional data analyst. Strictly follow these instructions:\n"
    13. f"{instruction}\n"
    14. "The output must be valid JSON with no additional explanatory text."
    15. )
    16. payload = {
    17. "messages": [
    18. {"role": "system", "content": system_prompt},
    19. {"role": "user", "content": user_input},
    20. ],
    21. "temperature": 0.2, # Lower randomness for more stable output
    22. "max_tokens": 2048,
    23. # Note: enable_search is a custom field of this example's gateway,
    24. # not a standard OpenAI-compatible parameter. Remove it if unsupported.
    25. "enable_search": False,
    26. }
    27. try:
    28. response = requests.post(
    29. api_url,
    30. headers=headers,
    31. data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
    32. timeout=60,
    33. )
    34. response.raise_for_status()
    35. content = response.json()["choices"][0]["message"]["content"]
    36. return json.loads(content) # Validate that the model output is valid JSON
    37. except requests.exceptions.RequestException as e:
    38. print(f"API call failed: {e}")
    39. return None
    40. except (KeyError, IndexError, json.JSONDecodeError) as e:
    41. print(f"Response parsing failed: {e}")
    42. return None
    43. if __name__ == "__main__":
    44. instruction = "Extract the core event from the text and output it with three fields: event_name, date, and impact."
    45. user_input = "In October 2023, an open-source model was released, briefly crashing the server due to heavy traffic, with far-reaching impact on the industry."
    46. result = invoke_llm_with_instruction(
    47. "http://localhost:8000/v1/chat/completions",
    48. "YOUR_API_KEY", # In production, read from environment variables or a secret manager
    49. instruction,
    50. user_input,
    51. )
    52. print(f"Model output: {result}")

    Before going live, several common issues need handling. Model output may not be valid JSON—retry or fall back gracefully when parsing fails. Timeouts and retry counts must be capped. API keys should be stored in environment variables or a secret management service, never hardcoded or written to logs. Record the latency and token usage of every call to support later cost analysis.

    6. Selection and Launch Checklist

    When selecting a model, test instruction following, long-context understanding, and long-horizon task capabilities with real business samples first, then compare accuracy against cost. When deploying, estimate KV Cache capacity using the formula first, then decide on the parallelism strategy and quantization scheme. After launch, continuously monitor latency, error rate, and token cost. Once these three metrics are stable, gradually scale up traffic.