Open-Source LLM Architecture and Engineering Practices: Scaling Laws, MoE, and Cost Optimization

    This article breaks down the technical evolution of open-weight large language models from an engineering perspective. It explains why open weights matter for deployment and customization, how scaling laws depend on data quality, why dense models remain a useful baseline, and how Mixture-of-Experts (MoE) architectures use fine-grained experts and shared experts to reduce cost. It also covers routing load balancing, communication overhead, unit token cost, and a practical checklist for training and inference. Readers will find pseudocode for scaling curve fitting and MoE routing, plus guidance on data governance and infrastructure choices. Baidu AI Cloud is referenced only as one general cloud option.

    1. Introduction: Why Open-Source LLMs Became an Engineering Focus

    Over the past two years, open-weight large language models have quickly become a focal point for both developer communities and enterprises. The reason is straightforward: open weights allow teams to run inference in their own environments, continue pretraining on domain data, and compress models through distillation, all without moving data outside their infrastructure. Inference cost per unit stays controllable, and models can be deeply customized for business corpora.

    However, open weights do not mean “ready to use out of the box.” What really determines deployment success is whether a team understands the architecture choices, data strategies, and scaling behavior behind the model. This article uses publicly available technical roadmaps as a thread and abstracts a general analysis framework.

    2. Scaling Behavior: The Trade-off Among Compute, Parameters, and Data

    Early practice often followed the intuition that “bigger parameters mean better performance.” Public research has gradually corrected this view: scaling laws do hold, and loss decreases as a power law with more parameters, more data, and more compute. But there is a precondition: data quality must remain high.

    The engineering implications are direct:

    • Low-quality corpora introduce noise and duplication. Model capacity gets spent fitting noise, and marginal returns decay quickly.
    • When data quality already meets the bar, the same compute budget is better spent on “a larger model plus relatively fewer but higher-quality tokens” rather than endlessly piling on raw text.
    • Data cleaning, deduplication, quality scoring, and data mixing should be treated as infrastructure capabilities on par with compute scheduling.

    A common engineering practice is to fit a scaling curve at small scale, extrapolate expected loss under different configurations, and then decide the full training scale. A schematic flow can be expressed as:

    1. # Pseudocode: small-scale fitting -> extrapolation -> choose full training config
    2. def fit_scaling_curve(probes):
    3. # probes: [(params, tokens, loss), ...] from small-scale controlled experiments
    4. a, b = fit_power_law(probes) # simplified form: L = a * N^-b
    5. return a, b
    6. def choose_config(budget, a, b, quality_gate):
    7. if not quality_gate: # govern data first if quality is insufficient
    8. return None
    9. best = max(candidates(budget), key=lambda c: predict_loss(a, b, c))
    10. return best

    The key sequence is: first set the scaling direction, then use controlled experiments to select better hyperparameters (learning rate, batch size, warmup steps, weight decay, context length, etc.), and only then start long-cycle training. This order is critical for controlling sunk cost.

    3. The Baseline Value of Dense Architectures

    The first generation of open-source LLMs typically offered two dense versions, 7B and 67B, with performance targeting mainstream 70B-class models of the same period. In a dense structure, every token passes through all parameters. The advantages are simple training and inference implementations, a mature operator ecosystem, and well-established quantization and parallelism strategies. The drawback is equally clear: capacity growth is strictly coupled with compute, leaving limited room to reduce cost per unit of quality. Dense models therefore often serve as a baseline to verify whether the data pipeline and evaluation system are trustworthy.

    4. Mixture-of-Experts: Turning Sparse Computation into an Engineering Capability

    Mixture-of-Experts (MoE) replaces the feed-forward network (FFN) part of a Transformer. The core idea is that total parameters can be very large, but each token only activates a subset of them, reducing actual compute and memory bandwidth pressure.

    The traditional approach splits the FFN into a small number of “large experts” and uses Top-K routing to select which ones to activate, for example 8 experts with 2 selected. The problem is that each expert has too much capacity, mixes multiple types of knowledge, and tends to create functional redundancy across experts. Routing also becomes less stable.

    The improved route includes two key moves:

    1. Fine-grained expert splitting: split each expert into multiple smaller experts and increase K in Top-K. Experts become more specialized, the combination space grows, and expressive power increases under the same activated parameter count.
    2. Shared experts: extract general knowledge into a small number of always-active shared experts that every token passes through. Routed experts only need to learn differentiated knowledge, avoiding repeated learning of common parts and significantly improving parameter utilization.

    The routing logic can be abstracted as:

    1. def moe_forward(x, routed_experts, shared_experts, top_k):
    2. h = sum(e(x) for e in shared_experts) # common knowledge, always active
    3. gate, idx = router(x, top_k) # fine-grained routing
    4. for g, i in zip(gate, idx):
    5. h = h + g * routed_experts[i](x)
    6. return h

    Two engineering issues must be addressed. First, load balancing: use auxiliary losses or a capacity factor to prevent a few experts from being overloaded while others sit idle. Second, communication efficiency: All-to-All communication under expert parallelism can easily become a bottleneck and needs joint tuning with pipeline parallelism and tensor parallelism.

    5. Economics: Focus on Cost per Token

    The main theme of second-generation MoE models is “strong quality, low cost, high efficiency.” In engineering metrics, this means a lower activated parameter ratio under the same batch and context length, and more controllable unit token cost for both training and inference. General cloud capabilities can be combined to support this: object storage for corpora and checkpoints, container platforms for distributed training and elastic inference, message queues to decouple data preprocessing pipelines, and logging plus monitoring and alerting for training stability. General product categories offered by Baidu AI Cloud in such scenarios can serve as a reference coordinate system for architecture selection.

    6. Deployment Checklist

    • Do data governance first, then scaling; establish observable metrics for deduplication, quality scoring, and data mixing.
    • Use small-scale controlled experiments to set the scaling direction and hyperparameters before starting long-cycle training.
    • Keep dense models as a baseline and fallback; use MoE models for cost-sensitive scenarios.
    • Stress-test routing balance and communication overhead before MoE deployment to avoid “very large parameters, very low throughput.”
    • On the inference side, combine quantization, batching, and caching strategies to close the end-to-end cost loop.

    7. Conclusion

    The technical roadmap of open-source LLMs is essentially a continuous optimization around “how to achieve the lowest loss and lowest unit cost under a given compute budget.” Understanding the preconditions of scaling laws and the design motivations behind fine-grained experts and shared experts has more long-term value than memorizing a specific model name.