How to Build Strong Math Reasoning in Large Language Models: A System-Level Approach

    This article outlines a system-level approach to building math reasoning in large language models, covering the three common bottlenecks in pretraining data, supervised fine-tuning, and reward signals. It explains a two-stage paradigm of high-quality pretraining plus reinforcement learning refinement, including corpus quality layering, difficulty-based curriculum sampling, process supervision data, relative policy optimization under sparse rewards, layered reward design, and training stability checks. It also covers independent evaluation, cost optimization, and common pitfalls to avoid.

    1. Why Math Reasoning Is the Litmus Test for LLMs

    In general-purpose LLM engineering, math and logical reasoning are often the first capabilities to expose weaknesses. The reason is that these tasks do not reward answers that merely “look reasonable”; they require a verifiable process and a unique conclusion. Once a model makes a sign error, drops a condition, or skips a reasoning step in the middle, the final answer is almost certainly wrong, and the error compounds along the chain.

    From a technical perspective, the bottlenecks usually concentrate in three areas:

    • Pretraining corpora lack sufficient density of high-quality, structured reasoning samples.
    • Supervised fine-tuning teaches the model an answer distribution rather than a search process.
    • Reward signals are sparse, since traditional methods rely on whether the final answer is correct, leaving almost no usable gradient early in training.

    Around these three points, the industry has gradually converged on a two-stage paradigm: high-quality pretraining as the foundation, followed by reinforcement learning for refinement. A math reasoning project led by a researcher is a representative practice of this route, and the relative policy optimization method it proposed has since been widely adopted as a common industry technique.

    2. First Pillar: High-Quality Pretraining and Corpus Engineering

    2.1 Quality Over Scale

    In math, the natural distribution of corpora is highly uneven: a large amount of web text contains “problem + answer” pairs with no complete derivation. Scraping it directly introduces serious noise, including wrong answers, missing steps, messy formatting, and redundant duplicates. A practical approach is to establish quality tiers first, then use a small model for quality scoring and deduplication, concentrating the budget on samples in the high-score range.

    A simplified data governance pipeline looks like this:

    1. # Pseudocode: layering and filtering of math corpora
    2. def build_math_corpus(raw_docs):
    3. docs = normalize_format(raw_docs) # Unify formula and symbol notation
    4. docs = dedup_by_embedding(docs, thr=0.92) # Semantic-level deduplication
    5. scores = quality_scorer(docs) # Quality scoring (small model)
    6. keep = [d for d, s in zip(docs, scores) if s > 0.7]
    7. return balance_by_difficulty(keep) # Rebalance by difficulty tiers

    2.2 Difficulty Tiering and Curriculum-Style Mixing

    A corpus with a single difficulty level tends to cause the model to overfit easy problems and fail to converge on hard ones late in training. A more robust strategy is to bucket samples by difficulty and dynamically adjust sampling ratios, keeping the model in a zone slightly above its current ability, which aligns with curriculum learning. In practice, it is also necessary to retain a proportion of general text to avoid catastrophic forgetting and degradation of language ability.

    2.3 Constructing Process Supervision Data

    To teach a model “how to think,” you must provide complete reasoning chains. Viable sources include generating steps backward from verifiable problems, performing step-level verification and rewriting of existing solutions, and consistency filtering (sampling multiple times and keeping trajectories with stable conclusions and valid steps). The key principle is that every step can be checked by a program or rule, rather than relying only on human intuition.

    3. Second Pillar: Reinforcement Learning Refinement and Reward Design

    3.1 Relative Advantage Under Sparse Rewards

    With only a 0/1 reward for the final answer, the model is almost entirely wrong early in training, within-group variance is zero, and gradients vanish. The core improvement of relative policy optimization is to sample a group of responses for the same problem and replace the absolute value function with within-group relative scores (normalized advantage values), removing the value network and significantly reducing memory usage and engineering complexity. Its advantage function can be abstracted as:

    1. A_i = (r_i - mean(r_1..r_n)) / std(r_1..r_n)

    where r_i is the reward of the i-th sampled trajectory. This design naturally fits math tasks that can be verified automatically, and makes training scripts easier to reproduce under limited compute.

    3.2 Layered Rewards: From Outcome to Process

    A more robust engineering choice is a layered reward combination:

    • Outcome reward: a positive reward when the final answer is equivalent to the reference answer.
    • Format reward: complete reasoning steps, with standard units and symbols.
    • Process reward: correct key intermediate conclusions, used to alleviate sparsity in long chains.
    • Length and redundancy penalties: suppress meaningless repetition and control reasoning cost.

    3.3 Training Stability Checklist

    The most common failure modes in the reinforcement learning stage are entropy collapse and reward hacking. Recommended monitoring metrics include policy entropy, within-group reward variance, average response length, and format compliance rate. It is also advisable to set up early stopping and rollback mechanisms, keeping the best checkpoint. If you use cloud container platforms and task scheduling capabilities, you can decouple sampling from training, buffer trajectory data with a message queue, archive checkpoints in object storage, and track the metrics above with logging and monitoring alerts.

    4. Evaluation: Avoid Marking Your Own Homework

    Evaluation must be independent of the training distribution. At minimum, it should cover four types of sets: competition-style problems, subject exam questions, application problems requiring multi-step tool collaboration, and robustness tests with distracting conditions. Beyond accuracy, metrics should include process correctness rate, proportion of invalid steps, average reasoning length, and unit cost. Pay special attention to answer equivalence判定: differences in representation such as fractions, radicals, and intervals should not be judged wrong, otherwise the reward signal is polluted.

    5. Engineering Deployment and Cost Optimization

    Once reasoning capability goes live, cost often becomes the main constraint. A combination of general techniques can be used: route simple requests to smaller models, enable a longer reasoning budget for hard problems, cache results for high-frequency questions, and use elastic compute for batch offline tasks. If built on general capabilities from Baidu AI Cloud, you can use a container platform to host inference services, object storage to hold datasets and model artifacts, and a monitoring and alerting system to track latency and failure rates, achieving an operable closed loop without binding to specific APIs.

    6. Common Pitfalls and How to Avoid Them

    1. Piling up data without quality layering, letting noise dominate training.
    2. Rewarding only the final answer, so long-chain tasks fail to converge.
    3. Ignoring general language ability, resulting in better reasoning but degraded expression.
    4. Using an evaluation set from the same source as the training set, inflating metrics.
    5. Lacking a rollback mechanism, so one unstable run overwrites a usable version.

    7. Conclusion

    Improving math and logical reasoning is not a single trick but a system engineering effort spanning data, training, rewards, evaluation, and operations. Build the foundation with high-quality pretraining, climb steadily under sparse rewards with relative policy optimization, and ensure sustainable iteration with independent evaluation and cost governance. Only then can reasoning capability truly become productive for the business, forming a reproducible, observable, and continuously optimizable engineering loop on general cloud infrastructure such as Baidu AI Cloud.