Pretraining and Evaluation Practices for Math-Specialized Language Models
Mathematical reasoning is a key measure of large language model intelligence. This article presents a reproducible workflow for building math-specialized models, covering data engineering, continued pretraining from a code-oriented base model, chain-of-thought instruction tuning, group-relative reinforcement learning, and controlled evaluation. It also discusses tool-assisted reasoning, general capability preservation, and practical deployment considerations.
Overview
Mathematical reasoning has become one of the core indicators of general intelligence in large language models. Continuing large-scale training on mathematical corpora from a code-pretrained base, followed by instruction tuning and reinforcement learning, can substantially improve accuracy on competition-level problems and the stability of step-by-step reasoning.
This article presents a complete and reproducible technical workflow across four areas: data engineering, continued pretraining, post-training optimization, and evaluation.
Data Engineering for Mathematical Corpora
Data engineering is critical to the success of a math-specialized model. High-quality mathematical content is often buried in large collections of general web data, and using raw web pages directly typically results in excessive noise.
In practice, a four-round iterative filtering strategy can be used:
- Start with an existing collection of mathematical webpages and use it to train a lightweight text classifier.
- Retrieve candidate pages from a large, deduplicated web corpus.
- Identify potential mathematical websites through domain-level statistical analysis, then supplement the results with manually labeled URLs and previously uncovered links.
- Repeat the process for four rounds.
This workflow can ultimately produce tens of millions of mathematical webpages and a specialized corpus containing hundreds of billions of tokens. It balances coverage and data purity while avoiding the false positives commonly associated with simple keyword matching.
Continued Pretraining
During continued pretraining, the model is initialized from a code-pretrained base and trained on a mixture of mathematical webpages, natural language, and code. The training corpus contains approximately 500 billion tokens.
A code-oriented initialization gives the model strong program-generation capabilities and creates a natural foundation for tool-assisted mathematical reasoning, such as writing code to verify calculations or explore a problem. The training process uses a sequence length of 4,096 tokens, mixed-precision training, and efficient parallelization strategies to support sufficient training iterations under limited compute resources.
After this stage, the model shows clear improvements over a general-purpose base model of comparable size in three areas:
- Mathematical reasoning
- Tool use
- Formal proof
At the same time, natural language understanding and coding capabilities remain balanced, with no apparent catastrophic forgetting.
Instruction Tuning for Step-by-Step Reasoning
Instruction tuning further strengthens the model’s ability to reason through problems step by step. Competition problems are annotated with chain-of-thought solutions, teaching the model to decompose complex tasks into intermediate steps that can be checked and verified.
After fine-tuning, the model can produce complete derivations under few-shot prompting rather than returning only a final answer. This capability is especially important for subsequent reinforcement learning, because reward signals can be applied more precisely to the quality of individual reasoning steps.
Reinforcement Learning with Group-Relative Optimization
The reinforcement learning stage uses a group-relative policy optimization algorithm. By comparing outputs within the same group, the method reduces variance and further improves accuracy in tool-assisted scenarios.
In practice, the model is allowed to call programs for intermediate calculations or symbolic verification. On competition-level mathematics benchmarks, it eventually reaches an accuracy close to 60%, substantially outperforming open-source models from the same period.
The complete post-training pipeline demonstrates that three factors are essential:
- High-quality data
- The prior knowledge provided by code pretraining
- Relative policy optimization during reinforcement learning
Removing any one of these components can limit the final performance of the math-specialized model.
Evaluation Methodology
Evaluation must strictly control experimental variables. For competition-level mathematics benchmarks, the recommended setup uses few-shot chain-of-thought prompting while prohibiting external tool packages and majority voting. This better reflects the model’s intrinsic reasoning ability.
Results indicate that a math-specialized model with 700 million parameters can approach the performance of much larger closed-source models. Tool-use evaluation should be conducted separately to verify the effectiveness of the program-generation and execution loop.
A broader capability evaluation should also cover:
- Natural language understanding
- Logical reasoning
- Code generation
This ensures that improvements in mathematical reasoning do not come at the cost of general-purpose capabilities.
Deployment Considerations
For practical use, developers can load model checkpoints directly through mainstream deep learning frameworks.
In text-completion scenarios, an incomplete mathematical expression can be provided as input and the model can generate a continuation. In conversational scenarios, a system prompt can guide the model toward a step-by-step reasoning mode.
The recommended deployment settings include:
- Keep the sequence length consistent with training at 4,096 tokens.
- Use
bfloat16to balance numerical precision and memory usage. - Store checkpoints in object storage for easier management.
- Use container platforms to support elastic scaling.
- Record reasoning traces through logging services to enable observability and rollback.
Conclusion
The success of a math-specialized language model depends on several closely connected components: iterative data refinement, transfer of code-based priors, chain-of-thought shaping through instruction tuning, and relative optimization through reinforcement learning.
The workflow described above has been validated on public benchmarks and provides a reusable technical approach for both academic and industrial development. Future work can focus on longer context windows, multimodal understanding of mathematical charts and diagrams, and deeper integration with formal proof systems to continue advancing the limits of mathematical reasoning.
