The Advanced Path of Open-Source Math Reasoning Models

    This article explains how to build an open-source math reasoning model, covering why domain-specific models are needed, a three-stage training pipeline (continued pre-training, instruction tuning, and reinforcement learning), tool integration for calculation, evaluation design, deployment and cost optimization, common pitfalls, and practical recommendations. Readers will learn how to improve step-by-step reasoning accuracy and build a reproducible workflow that can transfer to other vertical domains.

    1. Why Domain-Specific Math Models Matter

    General-purpose large models perform well on open-ended conversation and knowledge Q&A, but they often struggle with competition-level math tasks in three typical ways. First, during long reasoning chains, the early steps may be correct while later steps suffer from symbol drift. Second, when facing multi-step word problems, the model may select the wrong solution framework. Third, models often lack verification awareness and cannot self-check their final answers. Converging model capability toward the vertical domain of math essentially means focusing parameter capacity and training distribution more tightly on formal expression, symbolic transformation, and logical constraints.

    From an engineering perspective, the value of a math-specific model is not only reflected in benchmark scores, but also in three reusable capabilities: stable step-by-step reasoning, awareness of calling external computation tools, and critical review of conclusions. These three capabilities are equally applicable in enterprise scenarios such as financial calculations, capacity planning, and algorithm regression validation.

    2. Technical Roadmap: A Three-Stage Training Paradigm

    A reproducible math model training pipeline typically consists of three stages, each with a different objective. The stages cannot replace one another.

    2.1 Continued Pre-Training: Injecting the Domain Distribution

    Starting from an existing general code or base model and continuing training on domain-relevant corpora is the most cost-effective starting point. The key lies in corpus selection and mixing ratios:

    1. Domain corpus = highly relevant math tokens (highest proportion)
    2. + natural language corpus (prevents general capability degradation)
    3. + code corpus (supports tool-based problem solving)

    An imbalanced mix causes two types of degradation. A pure math corpus reduces language understanding and instruction-following ability, while too high a proportion of natural language dilutes the domain gains. In practice, it is advisable to retain a certain proportion of high-quality code data, because code bridges natural language problem statements and executable verification.

    The data cleaning stage needs to handle noise from formula extraction, duplicate problem statements, and answer leakage. If the evaluation set overlaps with the training corpus, scores will be inflated and will not transfer. Therefore, deduplication and contamination detection must be moved forward to the data stage rather than patched at the evaluation stage.

    2.2 Instruction Tuning: Aligning Problem-Solving Expression

    After continued pre-training, the model has domain knowledge but unstable output formats. The instruction tuning stage should construct samples covering multiple problem types, with emphasis on the standardization of step-by-step expression:

    1. Problem statement → condition extraction → solution selection → step-by-step derivation → conclusion → back-substitution check

    For sample construction, it is recommended to retain multiple reasoning paths with different solutions for the same problem, so the model learns the diversity of solution selection rather than memorizing a single template. Refusal and not-applicable samples should also be mixed in to prevent the model from forcing a conclusion when information is insufficient.

    2.3 Reinforcement Learning: Rewarding Answer Correctness

    After instruction tuning, methods such as Group Relative Policy Optimization can further improve accuracy. The idea is to sample multiple candidate answers for the same problem and construct relative advantages using verifiable signals such as answer correctness, reducing reliance on an additional value network and thereby saving GPU memory and engineering complexity. Key points for reward design:

    • Use automatically verifiable answer correctness as the main reward, avoiding subjective scoring that introduces noise;
    • Apply light penalties for format violations and overly long, redundant outputs;
    • Retain a small number of general task samples in training to suppress catastrophic forgetting.

    3. Tool Collaboration: Teaching the Model to Call Computation

    Competition-level problems often involve large-number arithmetic, symbolic simplification, and enumeration search. Pure language models are prone to errors when generating digits token by token. A feasible approach is to externalize computation: the model generates a call snippet, the runtime executes it, backfills the result, and reasoning continues:

    1. def solve_with_tool(model, prompt, executor, max_steps=6):
    2. state = prompt
    3. for _ in range(max_steps):
    4. out = model.generate(state)
    5. if "<calc>" in out:
    6. expr = out.split("<calc>")[1].split("</calc>")[0]
    7. result = executor(expr) # local or sandbox execution
    8. state = out + f"\nResult={result}\n"
    9. else:
    10. return out.split("<answer>")[1]
    11. return None

    Engineering practice must include sandbox isolation, timeout limits, and resource quotas to avoid security and stability risks from untrusted expressions. Tool calls decouple “computing accurately” from “explaining clearly” and are one of the main sources of the accuracy jump from the mid-fifties to nearly sixty percent.

    4. How to Build a Trustworthy Evaluation System

    A single benchmark is not enough to support a launch decision. It is recommended to build a three-layer evaluation:

    1. Competition-level benchmarks: measure the upper bound of high-difficulty multi-step reasoning. When reporting, clearly state whether tools are allowed, whether majority voting is used, and whether it is zero-shot or few-shot chain-of-thought. Results with different settings cannot be compared directly.
    2. Business distribution set: construct a private problem set sampled from real scenarios, covering unit conversion, boundary conditions, and abnormal inputs.
    3. Regression and robustness set: include synonym rewrites, numerical perturbations, and missing-condition samples to test stability.

    In addition to accuracy, it is recommended to track the consistency rate of step-by-step processes, tool call success rate, and average reasoning length. Abnormal growth in reasoning length is often an early signal that the model is stuck in a loop.

    5. Deployment and Cost: Compute Scheduling Essentials

    The output length of math reasoning is significantly higher than that of ordinary conversation, and GPU memory and throughput pressure concentrate in the decoding stage. Practical optimization methods include: using half precision or lower-bit quantization to compress weight memory; adopting paged key-value cache management to improve concurrency; dynamically controlling the number of sampling candidates, reducing sampling for easier problems to save compute; and decoupling tool execution from model reasoning into independent services, using message queues to smooth peaks.

    If using cloud resources, a common combination is a container platform hosting inference services, object storage holding model checkpoints and corpora, and logging and monitoring services tracking latency and failure rates. Elastic scaling should be triggered based on queue latency rather than average utilization, in order to avoid long-tail request pileup.

    6. Common Pitfalls

    • Looking only at total scores without considering the evaluation setup: whether tools are used or voting is applied can change conclusions by nearly ten percentage points.
    • Ignoring data contamination: mixing evaluation problem statements into the training corpus will distort all subsequent decisions.
    • Overly narrow reinforcement learning rewards: rewarding only the final answer may teach the model to guess rather than derive.
    • Ignoring general capability regression: after vertical optimization, language understanding and coding ability must be re-tested.

    7. Implementation Recommendations

    For teams that want to build math capabilities in-house, the recommended path is: first complete corpus governance and a private evaluation set, then perform continued pre-training based on your own base model, followed by instruction tuning to unify output structure, and finally introduce reinforcement learning centered on answer correctness along with tool calls. Throughout the process, keep reproducible data versions, training configurations, and evaluation scripts so that the effect of each iteration can be attributed. Following this path, achieving performance close to mainstream high-level closed-source models on competition-level math benchmarks is an expected engineering outcome, and the longer-term value lies in accumulating a reasoning optimization methodology that can transfer to other vertical domains.