Evaluating Mathematical Reasoning in LLMs and Optimizing Inference Throughput
A practical guide to building a reliable math reasoning benchmark for large language models and optimizing inference throughput. Covers layered test sets, standardized evaluation pipelines, chain-of-thought quality analysis, common interpretation pitfalls, and throughput measurement and optimization strategies.
Evaluating Mathematical Reasoning in LLMs and Optimizing Inference Throughput
Why Systematic Evaluation of Math Reasoning Matters
Mathematical reasoning is a common yardstick for a large language model’s logical ability. Unlike open-domain Q&A, math problems typically have verifiable answers, which makes evaluation results relatively objective. In practice, however, many teams judge models based on a handful of examples or subjective impressions. Such conclusions are easily skewed by the difficulty distribution of the problems, prompt wording, and sampling parameters, and are hard to reproduce.
A reliable evaluation scheme needs to answer three questions: which categories of problems can the model solve, within which difficulty range is its performance stable, and is its reasoning process trustworthy. The sections below address each in turn.
Building a Layered Problem Set
- Difficulty layering. Split problems into basic, intermediate, and advanced tiers based on source and number of solution steps. Basic covers algebraic simplification and simple counting; intermediate involves multi-step derivations and case analysis; advanced includes constructive proofs or problems requiring cross-domain knowledge.
- Decontamination. Problems should postdate the model’s training data cutoff as much as possible, and the set should be screened for near-duplicates. If an answer already appears in the training corpus, scores will be inflated.
- Unified answer formats. Specify a fixed answer form for each problem—integer, fully reduced fraction, or canonical expression—so scoring can be automated.
- Sample size. Keep at least dozens of problems per tier to reduce variance caused by any single problem.
The problem set needs version numbers and a change log. Whenever problems are modified, historical scores must be recomputed; otherwise results from different periods cannot be compared.
Standardizing the Evaluation Pipeline and Scoring
Comparability depends on a fixed pipeline. Standardize the following:
- Prompt template. All models use the same instruction, with an explicit requirement on the format of the final answer.
- Sampling parameters. Record temperature, max output length, and so on. Math tasks usually call for a low temperature—note this in the report.
- Repeated sampling. Sample each problem multiple times and take a majority vote or average pass rate to reduce randomness.
- Scoring method. Use rule-based matching for parseable answers; use a symbolic computation library for equivalence checks on expressions; proofs require human or expert review.
Example code (pseudocode—replace query_model, extract_final_answer, and check_equivalence with your own model invocation and validation functions):
from collections import Counterdef evaluate_item(problem, answer_key, query_model, extract_final_answer,check_equivalence, n_samples=5):"""Sample one problem multiple times and return the majority-vote verdict."""answers = []for _ in range(n_samples):raw = query_model(problem, temperature=0.2, max_tokens=2048)answers.append(extract_final_answer(raw))majority, _ = Counter(answers).most_common(1)[0]return check_equivalence(majority, answer_key)def run_benchmark(dataset, query_model, extract_final_answer, check_equivalence):results = {}for level, items in dataset.items():correct = sum(evaluate_item(it["problem"], it["answer"], query_model,extract_final_answer, check_equivalence)for it in items)results[level] = correct / len(items)return results
extract_final_answer should extract the answer only from the agreed marker at the end of the output, to avoid mistaking intermediate steps for the conclusion.
Analyzing Chain-of-Thought Quality
A correct final answer does not mean the reasoning is sound. Analyze chain-of-thought quality from these angles:
- Step completeness: Are key derivations justified, or are necessary conditions skipped?
- Self-correction: Can the model detect and fix intermediate errors?
- Redundancy: Longer reasoning does not necessarily improve accuracy—it can increase both the chance of error and inference cost.
Sample a subset of outputs and have domain experts score them against a fixed rubric, then compare with automated scoring. If the two diverge consistently, the automatic scoring rules need revision.
Common Pitfalls in Interpreting Results
- Single leaderboards mislead. Different problem sets have different difficulty distributions; ranking gaps may simply reflect problem selection.
- Ignoring cost. At the same accuracy, inference latency and token consumption can differ substantially—include cost in model comparisons.
- Confusing capability with configuration. Sampling parameters, external tool calls, and context length all affect results; reports must state the full configuration.
- Too few samples. Conclusions drawn from a few problems carry wide confidence intervals. Use a binomial distribution to compute confidence intervals for accuracy and judge whether differences between two models are significant.
Measuring and Optimizing Inference Throughput
In math-heavy applications, long reasoning chains significantly increase output token counts, so throughput directly affects user experience and cost. Common metrics include:
- First-token latency: time from request submission to the first output token, which shapes perceived responsiveness.
- Output throughput: tokens generated per second, measuring generation speed for a single request or the whole service.
- Effective throughput under constraints: the number of requests completed per unit time within a target latency bound.
When measuring, fix input length, output length, and concurrency—never compare numbers across different test conditions. A simple approach: record each request’s start time, first-token time, and end time, then compute means and percentiles (e.g., P50, P95) based on output length.
Typical optimization directions:
- Batch scheduling: Merge requests sensibly to improve hardware utilization while keeping queueing latency under control.
- Cache reuse: Reuse intermediate computations for requests sharing the same prefix to avoid redundant work.
- Quantization and parallelism: Reduce memory footprint where precision is acceptable, and choose tensor parallelism or pipeline parallelism based on hardware topology.
- Output length control: Use sensible task decomposition and stopping conditions to avoid wasted long outputs.
Single-machine peak throughput does not equal production experience. Request length distribution, traffic bursts, and tail latency in real workloads all change the conclusions, so validate under load tests that approximate your production environment.
Practical Recommendations
- Build an internal benchmark first: fixed problem set, fixed configuration, fixed scoring pipeline—producing reproducible evaluation reports.
- Select models per scenario: tutoring, code-related computation, and research-level derivation differ in their requirements for accuracy, explainability, and latency; set thresholds for each.
- Monitor continuously: rerun the benchmark after model updates, prompt changes, or service configuration changes.
- Tie evaluation results to business metrics, such as user acceptance rate or human review workload, rather than a single score.
Math capability evaluation and inference performance optimization are two parts of the same engineering system. The former determines whether the model can solve problems correctly; the latter determines whether results are delivered on time and at acceptable cost. Both require reproducible data and clear decision criteria to support long-term technical choices.
