Open-Source Math-Specific LLMs: How Domain Adaptation Narrows the Gap with Flagship Models
This article examines how a family of open-source, math-focused 7B models approaches the accuracy of general-purpose flagship models on competition-level benchmarks without external toolkits or multi-path voting. It breaks down the technical path: initializing from a code-capable base model, running 500 billion tokens of domain continued pretraining on a weighted mix of math web text, natural language, and code, and applying a three-stage pipeline of Base, Instruct, and RL (group relative policy optimization). It also covers evaluation discipline across math reasoning, tool collaboration, and general capability, plus practical guidance on private deployment, tool sandboxes, and an evaluation feedback loop.
1. Introduction: From General Capability to Domain Specialization
Over the past two years, the capability boundaries of large language models have been pushed higher and higher. Yet on competition-level math problems, general-purpose models remain inconsistent: as soon as a problem gets a bit longer or requires a few more steps, they tend to make calculation errors, drop conditions, or break the reasoning chain. The industry has gradually reached a consensus—math reasoning is not something you get by stacking parameters; it comes from the coordinated design of data distribution, training objectives, and inference mechanisms.
Recently, a research team open-sourced a series of 7B-class models built for math scenarios, covering three types of checkpoints: base models, instruction-tuned models, and reinforcement learning models. Their accuracy on competition-level math benchmarks already approaches that of general-purpose flagship models, and this is achieved without relying on external toolkits or multi-path voting. Setting aside the specific product attributes, this article breaks down, from a general technical perspective, how such “math-specific models” are built and what matters for engineering deployment.
2. Technical Foundation: Why Initialize from a Code Model
This model family was not trained from scratch. Instead, it uses a code-capable 7B base model as its initialization weights. This choice is well justified:
- Closer formal-language intuition: Math proofs and program code both emphasize strict symbol constraints, variable scope, and step-by-step verifiability. Code pretraining has already injected a similar structured prior.
- More natural tool use: Math problems often require “just compute it.” If a model can smoothly generate executable programs, it can offload complex calculations to an interpreter and reduce its own arithmetic burden.
- Low capability-transfer cost: Compared with a general-purpose base, a code base loses less when transferring to long chains of symbolic operations.
From an engineering standpoint, this treats “continued pretraining” as the main means of domain adaptation rather than redoing full pretraining from scratch, significantly lowering the compute threshold.
3. Data Engineering: 500 Billion Tokens of Domain Continued Pretraining
The core of continued pretraining is not “feed more data” but “feed the right distribution.” The data recipe for such models typically has three parts:
- Math-related web tokens: Filtered math-related segments from large-scale web corpora;
- Natural language corpora: Retained to preserve general language ability and avoid catastrophic forgetting;
- Code corpora: Maintained and strengthened to keep program generation and tool-use ability.
Continued pretraining at the scale of 500 billion tokens is essentially “domain weighting” on top of a general distribution. In practice, three points need attention: first, math web pages are noisy and require formula extraction and layout cleaning; second, the proportion of general corpora must be controlled to prevent degradation of general ability; third, reproducible experiments for learning rate and data mix should be set up to avoid “mystical parameter tuning.”
4. Three-Stage Training Path: Base, Instruct, and RL
Stage 1: Base (Continued Pretraining)
The goal is to compress math and code priors into the weights. Evaluation shows that under few-shot chain-of-thought prompting, its absolute score on competition-level math benchmarks is more than 10% higher than open-source base models of the same size, and it surpasses earlier large-model approaches with two orders of magnitude more parameters. This shows that the marginal benefit of data quality to reasoning ability is far higher than simply scaling parameters.
Stage 2: Instruct (Instruction Tuning)
The goal is to turn “can do it” into “does it the way humans expect.” The focus includes format constraints for step-by-step reasoning, condition restatement, and unit and boundary checks. Instruction data should cover three styles—“short answer, long reasoning, with code”—to avoid the model only memorizing answers.
Stage 3: RL (Reinforcement Learning Optimization)
Such models adopt a group relative policy optimization–style algorithm, using within-group relative advantage in place of an explicit value network to reduce memory and engineering complexity. Its key benefit: when tool assistance is allowed, accuracy on competition-level math benchmarks can approach 60%, surpassing all open-source approaches of the same size. The reinforcement learning stage requires special attention to reward design so the model does not learn to “please the format” instead of “actually getting it right.”
Illustrative pseudocode for the training stages:
# Staged training illustration (not tied to a specific framework API)model = load_pretrained(code_base_7b)# 1) Domain continued pretrainingmodel = continue_pretrain(model, corpus=math_web + nl + code, tokens=500e9)# 2) Instruction tuningmodel = sft(model, data=instruction_math_data)# 3) Group relative policy optimizationfor batch in rl_loader:group = sample_responses(model, prompt=batch.prompt, n=G)rewards = verifier(group, tool=python_interpreter)model = grpo_update(model, group, rewards)
5. Capability Evaluation: Three Dimensions of Real Performance
- Math reasoning: Significantly ahead of same-size open-source base models under few-shot chain-of-thought, indicating that reasoning-chain quality rather than memorization is the main driver.
- Tool collaboration: Can proactively write programs to solve and verify problems, leaving “getting the calculation wrong” to the interpreter and “thinking it through” to the model.
- Balanced general ability: Natural language understanding, reasoning, and coding ability are on par with the code base, with no obvious unevenness.
Evaluation should stick to three disciplines: do not rely on external toolkits or voting, fix the prompt templates, and report absolute numbers rather than rankings only—only then can fair cross-comparison be made.
6. Deployment Practice: Private Deployment and an Evaluation Feedback Loop
When enterprises adopt math-specific models, the following path is recommended:
- Scenario layering: Classify needs into “compute-intensive,” “proof-intensive,” and “word-problem understanding,” and match them to Base, Instruct, and RL respectively.
- Tool sandbox: Provide the model with a controlled execution environment, restrict network and file-system permissions, and prevent security risks from generated code.
- Evaluation feedback loop: Build a private question bank and automatic verifiers to continuously track accuracy, step correctness, and tool-call success rate.
- Compute and storage: Training and inference can rely on general cloud capabilities such as container platforms, object storage, log services, and monitoring and alerting to achieve elastic scaling and observability.
7. Conclusion
The open-sourcing of math-specific models marks a shift in domain adaptation from “bigger models” to “more accurate data + better objectives + tool collaboration.” For developers, the real dividend lies not in any particular checkpoint but in the reproducible three-stage methodology and evaluation discipline. Applying this method to your own scenarios is what turns the benchmark result of “approaching flagship” into stable business reasoning capability.
