A Practical Guide to Scaling Laws for Open-Source LLMs

    This article translates the core ideas behind scaling laws into an engineering workflow for open-source LLM development. It covers why a long-term view matters, how to run small-scale proxy experiments and fit power-law curves, a three-stage data pipeline built on roughly two trillion tokens, tokenizer and architecture choices, parallel training configuration, two-stage alignment with SFT and DPO, and a multi-dimensional evaluation pipeline. It closes with a reusable checklist for planning model scaling.

    1. Why a Long-Term View Is a Prerequisite for Scaling Open-Source Models

    With large models iterating quickly, many teams fall into a short-term race to adopt new architectures and new data. From a long-term perspective, what really determines whether an open-source model keeps delivering value is how deeply the team understands scaling laws, and whether the engineering system is reusable and extensible.

    Scaling law research can be reduced to one question: given a fixed compute budget, how should model parameters and training tokens be allocated to achieve the best result? Early studies consistently found that loss decreases in an approximately power-law fashion as parameters, data, and compute grow. Later work argued that spending more compute on the data side is often the better deal, and that hyperparameters such as the learning rate need to be recalibrated accordingly.

    The takeaway for engineering teams: do not bet the entire budget on a “bigger model” up front. Build small-scale proxy experiments first, fit the scaling curve, and then extrapolate to the target scale. The snippet below is illustrative code for recording several small-scale runs and fitting a simple power-law relationship:

    1. import numpy as np
    2. # Record compute, parameters, tokens, and validation loss from small-scale proxy runs
    3. runs = [
    4. # (compute_flops, params, tokens, val_loss)
    5. (1e18, 7e8, 2e10, 2.85),
    6. (4e18, 1.4e9, 4e10, 2.61),
    7. (1.6e19, 2.8e9, 8e10, 2.42),
    8. ]
    9. log_c = np.log([r[0] for r in runs])
    10. log_loss = np.log([r[3] for r in runs])
    11. # Fit loss = a * compute^b
    12. b, log_a = np.polyfit(log_c, log_loss, 1)
    13. print("scale exponent:", b, "coef:", np.exp(log_a))
    14. def predict_loss(compute):
    15. return np.exp(log_a) * compute ** b

    Keep in mind that the power law only describes a trend. Real training is also affected by data quality, tokenizer efficiency, parallelism strategy, and hardware utilization, so extrapolated results must leave a safety margin.

    2. The Data Side: Two Trillion Tokens Across Three Stages

    Data is the first lever of scaling. The original work built a bilingual Chinese-English corpus of roughly two trillion tokens and processed it in three stages, all aimed at the same goal: a controllable balance between quantity and quality.

    Stage one is deduplication. Repeated text amplifies memorization and lowers effective information density. Common practices include exact document-level deduplication, paragraph-level near-duplicate removal (for example, nearest-neighbor retrieval based on locality-sensitive hashing), and global frequency statistics over the training corpus to suppress high-frequency template text.

    Stage two is filtering. Rule-based filters remove obvious noise such as garbled text, extremely short lines, and ad templates, while model-based filtering uses a small classifier to score text quality and keep high-information-density content. In practice, it helps to make filtering thresholds configuration items so the same data version can be reused across experiments at different scales.

    Stage three is re-mixing. Different domains (code, math, encyclopedic text, dialogue) contribute differently to final capabilities, so sampling weights are used to tune the mix. A practical approach is to determine domain weights from small-scale experiments, then fix the mixture at the target scale, avoiding a “data recipe” that drifts during training.

    On tokenization, the work uses byte-level byte pair encoding (BBPE) with a vocabulary size of 102400. A larger vocabulary shortens sequences and improves effective context utilization, but increases embedding parameters and memory overhead, so it has to be weighed against model size.

    3. Architecture and Parallelism: From Micro Components to Macro Depth

    At the micro-architecture level, the work follows the mainstream combination of normalization, gated activation, and rotary position embeddings: RMSNorm for pre-normalization, SwiGLU as the feed-forward activation, and RoPE for relative position awareness. This combination is well validated and low risk, which makes it a good fit for an open-source base model.

    For attention, the 7B scale uses multi-head attention (MHA), while the 67B scale switches to grouped-query attention (GQA). By letting multiple query heads share a set of key-value heads, GQA substantially reduces key-value cache overhead at inference time, which is especially friendly to long contexts and high-concurrency serving.

    At the macro level, depth is the main scaling dimension: 30 layers at 7B and 95 layers at 67B. Deeper networks often yield stronger levels of abstraction at the same parameter budget, but they also place higher demands on residual stability, learning rate scheduling, and parallel partitioning.

    For the training framework, the work uses an in-house framework that integrates data, tensor, sequence, and pipeline parallelism, plus efficient attention operators to improve hardware utilization. Parallelism can be abstracted into a configuration matrix so the setup can be switched quickly when cluster topology changes:

    1. parallel:
    2. data_parallel: 8
    3. tensor_parallel: 4
    4. pipeline_parallel: 2
    5. sequence_parallel: true
    6. optimizer:
    7. zero_stage: 2
    8. grad_accum_steps: 16
    9. attention:
    10. fused_kernel: true
    11. recompute: selective

    In practice, validate the parallel partitioning and numerical consistency on a small cluster before scaling up. Activation recomputation, mixed precision, and gradient accumulation work well as knobs for trading memory against throughput.

    4. Alignment and Evaluation: Two-Stage Alignment and Multi-Dimensional Benchmarks

    Alignment uses a two-stage strategy. The first stage is supervised fine-tuning on roughly 1.5 million instruction samples covering instruction following, format constraints, and multi-turn dialogue. The second stage applies Direct Preference Optimization (DPO), optimizing the policy directly on pairwise preference data. This removes the separate reward model, making the pipeline shorter and more stable.

    Evaluation needs to cover multiple capabilities: mathematical reasoning, code generation, combined Chinese-English performance, and open-ended dialogue, with a separate safety assessment. It helps to turn evaluation into a pipeline with fixed prompt templates and decoding parameters, and to record variance so a single benchmark run does not lead to a wrong conclusion. Illustrative pseudocode:

    1. def evaluate(model, suite):
    2. report = {}
    3. for task in suite: # math / code / Chinese-English / dialogue
    4. scores = [run_once(model, task) for _ in range(3)]
    5. report[task.name] = {
    6. "mean": sum(scores) / len(scores),
    7. "std": np.std(scores),
    8. }
    9. return report

    According to the published results, the 67B version of this series surpasses mainstream open-source models of comparable size on math, code, and reasoning benchmarks, and performs close to or better than earlier commercial models in open-ended dialogue evaluations; the safety assessment found no obvious risks. This suggests that systematic optimization of the data recipe, compute allocation, and alignment pipeline often delivers more stable gains than a single architectural innovation.

    5. A Reusable Deployment Checklist

    • Run small-scale proxy experiments and fit the scaling curve before deciding the parameter and data mix.
    • Version the data: keep configurations and statistics reports for the deduplication, filtering, and re-mixing stages.
    • Tune the tokenizer vocabulary jointly with model size, watching the balance between sequence length and memory usage.
    • Make parallelism configurable, and verify numerical consistency before scaling up.
    • Keep the two alignment stages separate, and keep preference data pairwise and de-noised.
    • Pipeline the evaluation, fix decoding parameters, and record variance across multiple runs.

    If you are planning a scaling roadmap for an open-source model, you can build your experiment and training pipelines on Baidu AI Cloud using general-purpose capabilities such as container platforms, object storage, and monitoring and alerting, turning scaling experiments, data versions, and evaluation results into reproducible engineering assets.