How a 7B Open-Source Math Model Approaches Top Closed-Source Performance

    This article analyzes how a 7B-parameter open-source model can achieve more than 50% accuracy on the competition-level MATH benchmark through domain-specific continued pretraining, high-quality data engineering, instruction tuning, and lightweight reinforcement learning. It explains the model family design, the iterative construction of a 120B-token mathematics corpus, the role of GRPO and tool-assisted reasoning, and provides a practical example for local deployment.

    1. Background: Why Mathematical Reasoning Is a Critical Benchmark for LLMs

    Mathematical reasoning is widely regarded as one of the most discriminating capabilities in large language model evaluations. Unlike open-ended question answering, mathematical problems typically have unique answers, long reasoning chains, and very limited tolerance for errors. A mistake in any intermediate step can invalidate the final result.

    For this reason, competition-level benchmarks such as the MATH dataset often provide a meaningful measure of a model’s symbolic reasoning, multi-step planning, and self-correction capabilities.

    For a long time, advanced mathematical reasoning was largely dominated by closed-source models with hundreds of billions of parameters. Open-source models faced a persistent challenge: although their parameter counts were substantial, their mathematical accuracy remained significantly behind that of leading proprietary systems.

    A recent approach has demonstrated a different path. Through domain-specific continued pretraining and reinforcement learning, a model with only 7 billion parameters can achieve more than 50% accuracy on the competition-level MATH benchmark without relying on external toolkits or majority voting from multiple samples. With tool assistance, such as programmatic problem solving, its accuracy can approach 60%.

    The significance of this result is that it shows how domain focus, data engineering, and training-strategy innovation can produce substantial capability gains at a relatively small parameter scale. The following sections examine the approach from three perspectives: model architecture and training stages, dataset construction, and optimization methods.

    2. Technical Approach: A Three-Stage Model Family

    This type of mathematics-specialized model is typically initialized from a general-purpose foundation model with strong coding capabilities. The choice is intentional. Mathematical reasoning and code generation share several core requirements: precise symbolic operations, strict dependencies between steps, and structured output.

    In practice, continuing pretraining from a code-focused model tends to produce better results for mathematical specialization than starting from a model trained primarily on natural language.

    The resulting training process generally consists of three progressive stages.

    2.1 Base Model

    The base model undergoes approximately 500 billion tokens of continued pretraining on a mixture of mathematics-related text selected from public web data, natural language, and code.

    With few-shot chain-of-thought prompting, this version achieves more than a 10-percentage-point absolute improvement over comparable open-source base models on the MATH dataset. It can even outperform general-purpose models with many times more parameters.

    2.2 Instruct Model

    The instruct model is built on top of the base model through instruction alignment. It learns to answer questions using step-by-step reasoning and produces outputs that are clearer and more consistent with human expectations.

    This version is better suited for direct integration into question-answering, tutoring, and other interactive applications.

    2.3 Reinforcement Learning Model

    The reinforcement learning version is the key stage for the largest capability improvement. It uses an algorithm known as Group Relative Policy Optimization, or GRPO.

    Unlike the conventional Proximal Policy Optimization (PPO) approach, which relies on a separate value network, GRPO estimates the advantage by comparing multiple sampled answers generated for the same problem. The relative performance within the group serves as the baseline.

    This eliminates the need for a value network with a scale comparable to the policy model, significantly reducing memory and compute requirements during training. The design is particularly relevant for teams operating with limited resources.

    2.4 Tool-Assisted Reasoning

    Because the model inherits strong coding capabilities, it can solve difficult mathematical problems by writing and executing programs. Examples include numerical integration, equation solving, and combinatorial counting.

    This approach transfers part of the reasoning burden to deterministic program execution. It is also a major reason why the reinforcement learning model can approach 60% accuracy with tool assistance.

    Importantly, continued pretraining does not substantially damage the model’s general capabilities. Its performance on natural language understanding, reasoning, and programming tasks remains broadly comparable to that of the original code-oriented foundation model. In other words, the model gains mathematical expertise without significant catastrophic forgetting.

    3. Data Engineering: Building a 120B-Token Mathematics Corpus Through Four Iterations

    The success of a domain-specific model depends heavily on its data. In this case, the most reusable engineering idea is an iterative seed-expansion pipeline.

    Step 1: Build an Initial Seed Dataset

    The process starts with a publicly available collection of high-quality mathematics webpages. A lightweight FastText classifier is trained to determine whether a webpage contains mathematical content.

    Step 2: Retrieve Relevant Pages from Common Crawl

    The classifier is then used to score and search a deduplicated Common Crawl webpage collection. Pages with a high probability of containing mathematical material are retrieved.

    Step 3: Analyze Domain Coverage

    The domain distribution of the retrieved pages is analyzed to identify potentially relevant mathematics websites that are not yet covered. These may include educational websites, discussion forums, lecture notes, and competition-problem repositories.

    Step 4: Manually Verify Candidate Sources

    URLs from the newly identified domains are manually labeled and verified. Relevant pages that were not included in the original dataset are then added to the seed collection.

    Step 5: Repeat the Cycle

    The complete process—classification, retrieval, analysis, and expansion—is repeated four times.

    Each iteration exposes the classifier to a broader range of positive examples, allowing both retrieval quality and domain coverage to improve progressively. The final dataset contains approximately 35.5 million mathematics webpages and around 120 billion tokens of high-quality domain-specific text.

    This corpus provides the data foundation for the subsequent 500-billion-token continued-pretraining process.

    The methodology is highly transferable. Teams building specialized models for law, medicine, finance, or other domains can reuse the same general pipeline:

    • A lightweight classifier
    • Large-scale corpus retrieval
    • Domain-distribution analysis
    • Manual verification
    • Iterative expansion

    This provides a relatively cost-effective way to extract high-quality domain data from massive general-purpose web collections.

    4. Getting Started: Local Deployment and Inference

    Open-source models of this type commonly provide three checkpoints: a base version, an instruct version, and a reinforcement learning version. They can typically be loaded with mainstream Transformer libraries for evaluation and application development.

    The following example demonstrates text completion with the base model:

    1. import torch
    2. from transformers import AutoTokenizer, AutoModelForCausalLM
    3. model_name = "<path to the open-source mathematics model repository>"
    4. tokenizer = AutoTokenizer.from_pretrained(model_name)
    5. model = AutoModelForCausalLM.from_pretrained(
    6. model_name,
    7. torch_dtype=torch.bfloat16,
    8. device_map="auto"
    9. )
    10. text = "The integral of x^2 from 0 to 2 is"
    11. inputs = tokenizer(text, return_tensors="pt").to(model.device)
    12. outputs = model.generate(**inputs, max_new_tokens=100)
    13. print(tokenizer.decode(outputs[0], skip_special_tokens=True))

    Practical Considerations

    • Precision and GPU memory: Loading a 7B model in bfloat16 requires approximately 14 GB of GPU memory. A single mainstream consumer GPU or entry-level data-center GPU may be sufficient. When memory is limited, 4-bit or 8-bit quantization can be considered.
    • Context length: Public versions generally support a sequence length of 4,096 tokens. Long problem statements and multi-step derivations may therefore be truncated if the context limit is exceeded.
    • Prompting strategy: The base model works well with few-shot chain-of-thought prompting, in which the prompt includes several examples with complete reasoning steps. The instruct and reinforcement learning versions can generally be queried directly with natural-language instructions and provide stronger step-by-step reasoning.
    • Tool augmentation: For complex calculations, a practical approach is to parse the model’s output into executable code, run it through an interpreter, and feed the result back into the reasoning process. This can reproduce performance close to 60% on the relevant benchmark when tools are used.

    5. Key Takeaways

    This work provides a clear blueprint for building domain-specific large language models.

    First, selecting the right initialization model can deliver substantial benefits. For mathematics, a code-focused foundation model is a particularly effective starting point.

    Second, data engineering is at least as important as model architecture. Iterative seed expansion offers a relatively low-cost way to build a large and high-quality domain corpus from general web data.

    Third, lightweight reinforcement learning methods such as GRPO make alignment training more accessible to small and medium-sized teams. By avoiding a separate value network comparable in size to the policy model, GRPO can reduce the memory and compute burden of reinforcement learning.

    For organizations and developers building specialized models, the four-stage workflow of domain-data construction, continued pretraining, instruction tuning, and reinforcement learning is already practical for real-world experimentation and deployment.

    When additional infrastructure is needed for large-scale training and inference, general-purpose cloud computing and container platforms, including services such as Baidu AI Cloud, can be used to support the experimentation and deployment workflow. This allows teams to focus their effort on data and algorithms.