Open-Source LLMs: Mixture-of-Experts Architecture and Reinforcement Learning Post-Training in Practice

    This article explains how Mixture-of-Experts (MoE) architecture works in open-source large language models. It covers sparse activation, load balancing, training cost estimation, and reinforcement learning post-training. It also covers how to review open-source licenses, estimate inference memory, plan a serving architecture, and choose between deployment options.

    1. Why Open-Source Large Models Are Becoming an Engineering Option

    Open-source large models are usually delivered in three forms: open model weights, public technical reports, and API services that give developers access to the model’s capabilities. The combination of these three determines how much autonomy the user has.

    Open weights let a team deploy, fine-tune, and audit the model in its own environment, so data does not have to leave the internal network. Technical reports help teams understand the training methods, data strategy, and evaluation criteria, which makes it possible to judge whether a model suits a specific scenario. API services lower the barrier to trial and are suitable for quickly validating ideas.

    Selection requires answering three questions. Do data compliance requirements allow external calls? Does the team have the operations capability to run an inference cluster? Is long-term cost billed per call or amortized over hardware? The answers to these questions often determine the direction of a solution more than leaderboard rankings do.

    2. How Mixture-of-Experts (MoE) Works

    Mixture-of-Experts is a common design for today’s large-parameter models. It splits the feed-forward network into multiple parallel “expert” subnetworks. A router (gating network) then selects a small number of experts for each input token.

    The core of this design is sparse activation. A model can have a very large total parameter count, but each token passes through only a small subset of those parameters. As a result, the compute required for each inference step depends on the number of active parameters, not the total.

    Two concepts are important to distinguish:

    • Total parameters: all weights in the model. They determine storage footprint and the upper limit of model capacity.
    • Active parameters: the weights that actually take part in computing a single token. They determine inference speed and compute cost.

    The router usually selects the top-k experts. A common approach looks like this (pseudocode):

    1. function moe_forward(x):
    2. scores = router_linear(x) # one score per expert
    3. probs = softmax(scores)
    4. top_idx, top_w = select_top_k(probs, k)
    5. top_w = top_w / sum(top_w) # normalize weights
    6. out = 0
    7. for i, w in zip(top_idx, top_w):
    8. out += w * expert[i](x)
    9. return out

    Load imbalance is the most common problem in MoE training. If the router consistently favors a few experts, the rest receive insufficient training, and model capacity is wasted. Common remedies include:

    • Adding an auxiliary load-balancing term to the loss function that penalizes deviations in expert usage frequency.
    • Setting an expert capacity limit, with excess tokens dropped or rerouted.
    • Adding noise before the routing scores are computed to encourage exploration.

    3. Training Cost Components and Estimation

    Training cost mainly consists of three parts: compute, data, and engineering overhead. The compute portion can be roughly estimated with an empirical formula:

    Training compute C ≈ 6 × N × D

    Here, N is the number of parameters involved in computation. For MoE models, use the active parameter count. D is the number of training tokens.

    As an example, assume an active parameter count of N = 30B and a training token count of D = 1T. Then:

    C ≈ 6 × 3×10^10 × 10^12 = 1.8×10^23 FLOPs

    After you obtain the compute requirement, combine it with the actual hardware utilization to convert it into machine hours and cost. Actual utilization is often far below theoretical peak because of communication latency, pipeline bubbles, and data loading bottlenecks. For this reason, estimates should be conservative, and the budget should include room for debugging and retraining.

    Hidden engineering costs also matter:

    • Parallelism strategy: combining data, tensor, and expert parallelism requires tuning for the network topology.
    • Stability: large-scale training needs checkpointing and automatic recovery to handle gradient anomalies and hardware failures.
    • Data cleaning: deduplication, denoising, and quality filtering often consume large amounts of human effort and compute.

    4. Reinforcement Learning Post-Training

    Pretrained models usually have knowledge, but their reasoning, instruction following, and output formatting may not be reliable. The post-training stage closes this gap. The common process has three steps.

    Step 1 is supervised fine-tuning. It uses high-quality instruction and response examples to teach the model basic dialogue and format conventions. If data is limited, this step can also serve as a cold start for reinforcement learning, which prevents disorganized outputs early in training.

    Step 2 is reinforcement learning with verifiable rewards. For tasks such as math and coding problems, where answers can be checked automatically, rules can give the reward directly. This does not require a separately trained reward model. An example:

    1. function reward(prompt, response, reference):
    2. score = 0
    3. if format_is_valid(response): # format reward
    4. score += 0.1
    5. if extract_answer(response) == reference: # correctness reward
    6. score += 1.0
    7. return score

    Step 3 is policy optimization. One common approach samples a group of responses for each problem and estimates advantage values from their relative scores within the group. This avoids the cost of training a separate value network.

    Reinforcement learning has several typical risks to monitor:

    • Reward hacking: the model finds loopholes in the rules to earn high scores. For example, it may produce content that looks correct but is actually invalid. Diverse verification and manual spot checks can help detect this.
    • Language mixing: in multilingual settings, the model may switch languages during reasoning, which hurts readability. A language consistency constraint can be added to the reward.
    • Overly long outputs: pursuing accuracy alone can lead to verbose answers. A length penalty or a task-specific length budget can address this.

    5. Open-Source Licensing and Compliance Review

    Open weights do not mean unconditional use. The license sets the boundaries for commercial use, redistribution, modification, and attribution. Common license types include:

    • Permissive licenses: allow commercial use, modification, and redistribution. They usually require only that the copyright notice be retained.
    • Restrictive licenses: set conditions based on user scale, application domain, or output use.
    • Custom licenses: terms set individually by the publisher, which must be read clause by clause.

    Before deployment, complete these checks:

    1. Confirm that the license terms cover the intended use, including commercial use, derivative models, and external services.
    2. Review the model card and data documentation to assess copyright and privacy risks in the training data.
    3. Record the model version and license file for auditing and traceability.
    4. Establish a review process for generated content to prevent infringement and harmful output.

    6. Engineering Practice

    6.1 Estimating Inference Memory

    You can estimate the memory needed to load the weights alone with this formula:

    Memory (GB) ≈ parameter count (billions) × bytes per parameter

    Bytes per parameter depend on precision. FP16 uses 2 bytes, INT8 uses 1 byte, and INT4 uses about 0.5 bytes. For a 30B-parameter model, FP16 weights need about 60 GB, and INT4 quantization reduces that to about 15 GB. This figure covers only the weights. You must also reserve space for the KV cache, activations, and runtime overhead. In long-context scenarios, the KV cache is often the main additional cost.

    6.2 Serving Architecture

    In production, inference services usually consist of these common components:

    • Container platform: handles orchestration, scaling, and rolling upgrades of model instances.
    • Object storage: stores model weights, version files, and evaluation data.
    • Message queue: buffers requests to smooth traffic spikes and keep sudden load from overwhelming the inference cluster.
    • Logging, monitoring, and alerting: records latency, throughput, error rate, and memory usage, and triggers alerts when thresholds are crossed.

    At the inference engine level, dynamic batching and continuous batching can significantly improve GPU utilization. When request length distributions vary widely, schedule requests in length buckets to reduce padding waste.

    6.3 Private Evaluation System

    Public leaderboards reflect only general capability and do not represent specific business needs. We recommend that teams build a private evaluation set of at least several hundred items. It should cover real business questions, edge cases, and safety scenarios, and use a fixed evaluation protocol and random seeds. After each model upgrade or prompt change, rerun the evaluation and compare changes in accuracy, refusal rate, and latency.

    7. Selection Recommendations and Common Pitfalls

    The table below gives preliminary recommendations by scenario:

    Scenario Preferred Option Main Risk
    Highly sensitive data Self-hosted open weights High operations and hardware cost
    Rapid prototyping API service Data leaves the organization; call cost grows with volume
    Vertical domain customization Open weights plus fine-tuning Training data quality sets the ceiling
    Small teams with limited resources Smaller models or quantized versions Limited complex reasoning ability

    Common pitfalls include:

    • Looking only at total parameter count and ignoring active parameters and inference cost.
    • Adopting public leaderboard results without business-specific evaluation.
    • Ignoring license terms and discovering restrictions only after the product launches.
    • Treating reinforcement learning as a universal solution and neglecting the quality of data and reward design.

    Technology selection is fundamentally about trade-offs. Model capability, compliance requirements, operations capacity, and cost budget must be considered together. No single metric is enough to base a decision on.