Pretraining and Reinforcement Learning for Open-Source Math-Specialized LLMs: A Practical Path from Code Base to Competition-Level Reasoning

    This article walks through how a math-specialized open-source language model is built and evaluated: choosing a code-strong mid-sized base, continuing pretraining on hundreds of billions of math tokens, iteratively mining a high-quality math web corpus, evaluating in three layers (no-tool chain-of-thought, tool-assisted execution, and general capability retention), and applying group relative policy optimization to improve long-chain correctness. It also covers checkpoint release, inference reproducibility, cloud infrastructure needs, and safety/compliance controls, closing with four recommendations for R&D teams. Readers get a reusable blueprint showing how a roughly 7B-parameter open model can approach top-tier competition-level results without closed-source scale or majority-voting tricks.

    Why Math Reasoning Breaks General-Purpose LLMs

    Math reasoning imposes requirements on large language models that everyday question answering does not: intermediate steps must be verifiable, symbolic transformations cannot simply “look right,” and the model frequently has to work alongside program execution and formal proof systems. Models pretrained on general corpora produce fluent natural language, yet on competition-level problems they skip steps, compute incorrectly, or fail to translate a natural-language intent into runnable code.

    A clear path has emerged in practice: start from a mid-sized base model that already has genuine programming ability, continue pretraining on large-scale math-related tokens, then apply instruction tuning and reinforcement learning to turn “can compute” into “computes step by step according to a specification and calls tools to verify.”

    Base Model Selection: Code and Math Are Highly Isomorphic

    Math and code are structurally close. Algebraic simplification, equation solving, combinatorial counting, and proof construction are all fundamentally constraint satisfaction and search over symbolic sequences.

    A practical initialization is a model of roughly seven billion parameters that has been thoroughly pretrained on code, followed by continued training on hundreds of billions of tokens drawn from math web pages, natural-language explanations, and code mixtures. This preserves program synthesis ability while injecting domain knowledge.

    The goal of continued pretraining is not simply “seeing more problems.” It is to align three distributions inside the same parameter space: theorem statements and proof phrasing in plain text, formulas and derivation structure on web pages, and numeric and symbolic computation in executable scripts. In practice, sequence length is commonly set to a little over four thousand tokens so that longer proofs and multi-turn tool-calling trajectories fit.

    Data Quality Sets the Ceiling

    Math content on the public web is sparse, noisy, and badly formatted. A more reliable engineering approach is multi-round iterative retrieval:

    1. Train a lightweight text classifier on an existing collection of math web pages.
    2. Recall candidate pages from a large deduplicated web corpus.
    3. Use statistical features of domains and paths to narrow down likely math sites.
    4. Have humans label highly relevant links, merge pages not yet ingested into the seed set, and repeat.

    After several rounds, this yields a dedicated corpus on the order of tens of millions of math web pages and hundreds of billions of tokens.

    Key control points include: aligning formulas with surrounding prose, preserving problem-solution pairs, deduplicating to avoid evaluation leakage, and tuning the mixture ratio against natural-language and code data so the model does not lose general understanding or programming ability. With a well-chosen ratio, natural-language understanding, commonsense reasoning, and coding metrics remain on par with the original code base after math continued pretraining, avoiding the degradation of “specialized in math but cannot write programs.”

    Evaluate in Layers

    Layer 1 — no-tool few-shot chain-of-thought. On competition-level math benchmarks, using only stepwise natural-language reasoning, an open-source 7B-class math base already opens an absolute gap of more than about ten percentage points over previous open-source bases, and surpasses some larger early science-specialized models. Data and continued pretraining alone can therefore raise the pure-reasoning ceiling substantially.

    Layer 2 — tool collaboration. The model is asked to write programs for numeric computation, symbolic simplification, or exhaustive verification, then write the execution results back into the proof. Because the base comes from code pretraining, this ability is inherited rather than learned from scratch.

    Layer 3 — combined capability. This layer confirms that math reinforcement has not sacrificed general conversation or code completion. In the advanced version, the instruction-tuned model places more emphasis on a well-formed stepwise derivation format; after reinforcement learning of the group relative policy optimization family, competition-level accuracy under a tool-assisted setting can climb further into the roughly sixty percent range, approaching the level of the leading closed-source models at the time under conditions of no external toolkits and no majority voting.

    The evaluation protocol must state clearly whether a code interpreter is allowed, whether self-consistency sampling and voting are used, and the number of few-shot examples and the prompt template. Otherwise the numbers cannot be compared across systems.

    Reinforcement Learning: Relative Comparison Over Absolute Reward Modeling

    The core of the RL stage is relative comparison rather than absolute reward modeling. Sample multiple solution trajectories for the same problem, group and score them by final correctness and process soundness, and update the policy using within-group relative advantage. This reduces reward model bias and stabilizes long-chain reasoning training.

    Implementation details matter: truncation limits on trajectory length and number of tool calls, use of negative samples from failed programs, and safeguards against the model learning to “fill in a template without computing correctly.”

    After training, keep both paths available at inference time — chain-of-thought and optional tools — and trade off latency against accuracy.

    Engineering and Deployment

    Checkpoints are typically released under an open-source license in three versions: base, instruction-tuned, and reinforcement-learned, which makes academic reproduction and commercial integration easier. Load them with a mainstream open-source model library, verify tokenizer consistency for mathematical symbols, and disable unnecessary sampling randomness at inference for reproducibility.

    For continued pretraining or RL on the cloud, the general capabilities you need are object storage for corpora and checkpoints, a container platform for elastic multi-node scheduling, logging and monitoring to track loss and evaluation curves, and message queues to pull tool execution results asynchronously. No vendor-specific interface is required; a standard distributed training and evaluation pipeline is enough.

    On safety and compliance, filter out competition problem leakage, avoid ingesting entire pages of unlicensed textbooks, and perform symbol-level verification of generated content so that “confidently wrong proofs” do not reach production.

    Four Recommendations for R&D Teams

    1. Prefer a code-strong mid-sized base. The marginal return of math continued pretraining is higher.
    2. Iterate the corpus with humans in the loop, multiple rounds. Classifier recall and manual domain labeling are both indispensable.
    3. Report two evaluation curves — no-tool chain-of-thought and tool-assisted execution — and fix prompts and decoding parameters.
    4. Layer instruction tuning and relative policy optimization. Instruction tuning solves format and alignment; relative policy optimization solves long-range correctness. They stack rather than replace each other.

    Along this path, open-source math-specialized models have shown that a 7B-parameter model can approach top-tier results on competition-level benchmarks without relying on closed-source scale or external voting tricks, while providing a reusable capability foundation for formal proof, symbolic computation in intelligent programming, and related scenarios.