A Practical Guide to Deploying Open-Source LLMs: Model Selection, Costs, and Production Rollout
When evaluating open-source large language models for production, most engineering teams face three core questions: which scenarios justify switching from closed-source APIs, how to calculate the real costs, and how to implement common use cases. This guide addresses each question in turn, providing practical decision frameworks you can apply directly, including a break-even calculation method and tuning starting points for RAG-based knowledge bases and developer productivity tools.
When teams adopt open-source LLMs in production, the main concerns are usually whether they are worth using, how to calculate the costs, and what to do when things go wrong. This article works through these questions in order, and each section provides a judgment method you can apply directly.
1. Which Scenarios Favor Open-Source Models Over Closed-Source APIs?
Open-source models typically offer clear advantages in three types of use cases. The first is high-volume workloads with relatively fixed input and output patterns, such as batch summarization, tag classification, and code completion. The second is scenarios where data cannot leave the internal network, common in finance, healthcare, and government systems. The third is cases where you need to fine-tune on proprietary business data and want full control over model weights.
For low-volume use cases, rapidly changing requirements, or tasks that demand the strongest general-purpose capabilities, sticking with a closed-source API is often the simpler choice. Before switching, evaluate candidate open-source models against your current closed-source model using the same set of business samples, then decide the scope of migration based on the results.
2. How to Calculate Costs?
Closed-source APIs are billed by token, so costs grow roughly linearly with usage. Some providers use tiered pricing, where the unit price drops once usage exceeds a certain threshold. Self-hosting an open-source model converts this into fixed costs, mainly GPU purchase or rental fees, electricity, data center or container platform costs, and operations staffing.
To compare the two approaches, gather the following inputs:
- Average monthly usage in tokens, separating input and output.
- GPU unit price, number of cards, and monthly running hours.
- GPU utilization. Raising utilization from 30% to 70% on the same hardware significantly reduces the per-token cost, so estimate utilization from real load-testing data.
- Operations staffing, plus overhead for monitoring, storage, and related services.
- The frequency of model version upgrades and re-evaluation.
Here is an illustrative calculation with hypothetical numbers. Assume a self-hosted cluster costs 30,000 RMB (roughly 4,200 USD) per month in fixed costs, and the closed-source API charges 20 RMB (roughly 2.8 USD) per million tokens. The break-even point is:
Break-even monthly usage = fixed costs ÷ unit price = 30,000 ÷ 20 = 1,500 million tokens, or about 1.5 billion tokens per month.
These figures are for demonstrating the calculation only; actual pricing depends on vendor quotes. If your monthly usage stays well below the break-even point, self-hosting will cost more per token than the API.
3. How to Implement Developer Productivity and Knowledge Base Use Cases?
The following uses a hypothetical internal developer assistant project to illustrate the technical essentials of these two scenarios. All numbers are for illustration only and do not represent real results.
The core of a developer productivity system is providing the model with sufficiently accurate context. The system can parse the syntax tree of the file the developer is currently editing, extract function definitions, imported dependencies, and relevant types near the cursor, then assemble this information with the task instruction into a prompt. Since code completion is latency-sensitive, use streaming output and dynamic batching to keep first-token latency under control during traffic peaks. For evaluation, build an internal code completion benchmark and track acceptance rate, unit test pass rate, and average response time, comparing data before and after the switch within a pilot period. Only after defining sample size, measurement period, and metric definitions can improvement figures be reported externally.
A typical enterprise knowledge base pipeline works as follows: business documents are split into chunks, embedded, and stored in a vector database; when a user asks a question, the system retrieves relevant chunks first, then passes them as context to the model to generate an answer. The following parameters serve as reasonable tuning starting points:
- Chunk size: a common starting point is 300 to 500 tokens, with 10% to 20% overlap between adjacent chunks. For documents with clear structure, chunk by section or paragraph.
- Retrieval count: fetch the top 5 to 10 results, then filter them through a reranking model before sending to the generation model.
- Generation parameters: for factual Q&A, lower the Temperature and use Top-P to constrain the sampling range.
Evaluation should cover at least…
