Scaling Laws and MoE: Two Design Threads for Open-Source Large Models

    This article reviews two design threads that have shaped open-source large models: scaling laws for allocating training budgets and mixture-of-experts (MoE) architectures for expanding model capacity through sparse activation. It explains how scaling laws are fitted and used, compares the Kaplan and Chinchilla recipes, discusses training-optimal versus inference-optimal choices, and highlights data quality and engineering checks. It then introduces MoE routing, presents pseudocode for a sparse MoE layer, and notes capacity factors, load balancing, and challenges in conventional MoE designs.

    Scaling Laws and MoE: Two Design Threads for Open-Source Large Models

    Much of the progress in open-source large models comes from two things. The first is using scaling laws to guide the allocation of training budgets. The second is using mixture-of-experts (MoE) architectures to expand model capacity without significantly increasing the compute required per token. The former answers “how large should the model be, and how much data should it use?” The latter answers “how can parameters be used efficiently during inference?” The sections below discuss each in turn.

    1. Scaling Laws: An Empirical Basis for Training Decisions

    1.1 What Is a Scaling Law?

    A scaling law describes the power-law relationship between model loss and the number of parameters, the amount of data, and the training compute. Over a fairly wide range of scales, this relationship is quite stable. Teams can fit a curve using a set of small-scale experiments and then extrapolate it to the target scale, so they can estimate approximate performance and cost before committing to a full training run.

    This is an empirical regularity, not something strictly derived from theory. Fitted results depend on the experimental setup, data distribution, training recipe, and evaluation methodology. If the data or learning-rate strategy changes, the fitted coefficients may change as well.

    1.2 Two Main Recipes: Kaplan and Chinchilla

    Kaplan et al. (2020) tended to allocate more budget to model parameters while relatively reducing training data. Later, the Chinchilla study by Hoffmann et al. (2022), using a more systematic experimental design, concluded that model parameter count and training token count should grow roughly in similar proportions. Under this conclusion, many large models at the time were considered to have too little training data.

    The difference between the two conclusions mainly comes from experimental settings and fitting methods. Therefore, no single number should be treated as a universal constant. The roughly 20 tokens per parameter given by Chinchilla is only a reference value for estimation. In practice, the choice should be verified against the target task, the amount of high-quality data available, and subsequent inference costs.

    1.3 Training-Optimal and Inference-Optimal May Differ

    When training compute is fixed, the optimal combination of parameters and data is determined by the objective function. If the goal is to minimize total training cost, the conclusion may differ from the goal of minimizing inference cost after deployment. A model with fewer parameters and more training data may not be the most economical during training, but it has lower per-inference overhead in large-scale serving. Therefore, the optimization target should be defined before model selection:

    • Training-compute optimal: pursue the lowest loss under a given training budget, using a compute-optimal allocation;
    • Inference-cost optimal: trade more training data for a smaller model to reduce long-term serving cost;
    • A trade-off between the two: choose between them based on expected call volume and deployment lifetime.

    1.4 Data Quality Is a Prerequisite for Scaling Relationships

    Scaling laws are valid only when training data remains reasonably high quality. When data quality is poor, increasing data volume does not necessarily produce the expected loss reduction, and returns may diminish. Noise and error patterns from low-quality samples consume model capacity. Data cleaning, deduplication, and quality filtering are therefore necessary steps in the training pipeline, not optional cleanup at the end.

    1.5 Engineering Checklist

    Before formal training, the following items can be checked one by one:

    • The optimization target has been defined as either training-compute optimal or inference-cost optimal;
    • Scaling curves have been fitted with small-scale experiments, and the data distribution and training recipe used for fitting have been recorded;
    • The target data-to-parameter ratio has been verified against the available amount of high-quality data, rather than directly applying a single constant;
    • Key hyperparameters such as learning rate and batch size have been validated on proxy models and confirmed to transfer to the target scale;
    • Data cleaning, deduplication, and quality evaluation pipelines have been established, with reproducible evaluation metrics.

    2. MoE: Expanding Model Capacity with Sparse Activation

    2.1 Basic Structure of MoE

    A mixture-of-experts (MoE) model typically replaces the feed-forward network (FFN) layers in a Transformer with multiple parallel expert sub-networks. A router computes a score for each expert for every token and selects only the few experts with the highest scores to participate in computation. The total parameter count of the model can be large, while the number of parameters actually activated per token is smaller.

    The pseudocode below shows the basic flow of a single layer and omits details used in real implementations:

    1. def moe_layer(x, experts, router, top_k):
    2. # x: [batch, seq_len, hidden_dim]; routing is performed token by token
    3. logits = router(x) # score of each expert for each token
    4. gates = softmax(logits, dim=-1)
    5. topk_w, topk_ids = top_k_select(gates, k=top_k) # select top_k experts for each token
    6. topk_w = topk_w / topk_w.sum(dim=-1, keepdim=True) # renormalize selected weights
    7. output = zeros_like(x)
    8. for expert_id in range(len(experts)):
    9. # find (token, slot) pairs that selected this expert, and compute only for those tokens
    10. token_idx, slot = where(topk_ids == expert_id)
    11. if token_idx.numel() == 0:
    12. continue
    13. # real implementations limit each expert's capacity (capacity factor); overflow tokens are dropped or skipped, not expanded here
    14. out = experts[expert_id](x[token_idx])
    15. output[token_idx] += topk_w[token_idx, slot].unsqueeze(-1) * out
    16. return output

    Code notes:

    • router outputs a score for each expert for every token, so routing is performed per token;
    • top_k controls how many experts each token activates; common values are small, such as 1, 2, or 8;
    • The capacity factor limits how many tokens an expert can process at once. Tokens beyond the limit are dropped or passed through only via the residual connection;
    • Training also requires a load-balancing loss. Without it, a small number of experts may be selected for a long time while other experts are not trained sufficiently.

    2.2 Common Issues with Conventional MoE

    Conventional approaches usually use “a small number of large experts plus Top-K routing”—for example, eight large experts with two selected per token. Under some conditions, this design can be prone to certain issues.