---
title: "DeepMath: A lightweight math reasoning Agent with smolagents"
description: "DeepMath fine-tunes Qwen3-4B Thinking with GRPO so it emits short Python snippets for intermediate math steps, runs them in a sandbox (module allow-list, no file I/O or network, per-snippet timeouts), and feeds results back into its reasoning."
url: "https://swe.quest/articles/deepmath-a-lightweight-math-reasoning-agent-with-smolagents-e010b89eb984330e"
canonical: "https://huggingface.co/blog/intel-deepmath"
source: "Hugging Face"
published: "2025-12-04"
difficulty: "hard"
kind: "Research"
reading_minutes: 5
tags: ["model-training","ai-agents","llms","evals","sandboxing"]
---

# DeepMath: A lightweight math reasoning Agent with smolagents

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-12-04, 5 min read, Research. Original: [https://huggingface.co/blog/intel-deepmath](https://huggingface.co/blog/intel-deepmath)

## Summary

DeepMath fine-tunes Qwen3-4B Thinking with GRPO so it emits short Python snippets for intermediate math steps, runs them in a sandbox (module allow-list, no file I/O or network, per-snippet timeouts), and feeds results back into its reasoning. The agent is built on smolagents with vLLM inference, and TRL's vLLM client/server was modified so GRPO candidates are generated by the agent. Rewards cover correctness and code use, completions are capped at 5k tokens, temperature is scheduled linearly from 1.2 to 0.7, and training uses the OpenMathReasoning TIR subset. On MATH500, AIME, HMMT and HLE, agentic inference alone cuts output length by up to 66% with mixed accuracy, and combining it with GRPO training gives the best accuracy with shorter traces.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Evaluation](https://swe.quest/tags/evals.md) (AI & ML)
- [Sandboxing & isolation](https://swe.quest/tags/sandboxing.md) (Security)

## Prerequisites

- LLM reinforcement learning fine-tuning ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- GRPO
- tool-calling agents ([easy posts on AI agents](https://swe.quest/tags/ai-agents.md?difficulty=easy))

## Keywords

DeepMath, GRPO, Qwen3-4B, smolagents, TRL, vLLM, OpenMathReasoning, MATH500

## Related posts

- [Open R1: Update #2](https://swe.quest/articles/open-r1-update-2-8012bcb3a4bd440c.md): Hugging Face · 2025-02-10 · Hard · 14 min read · Model training, LLMs, Evaluation, Inference & serving
  OpenR1-Math-220k is a math reasoning dataset built by generating 800k DeepSeek R1 traces for 400k NuminaMath 1.5 problems on 512 local H100s.
- [Jupyter Agents: training LLMs to reason with notebooks](https://swe.quest/articles/jupyter-agents-training-llms-to-reason-with-notebooks-1236432acb183b7c.md): Hugging Face · 2025-09-10 · Hard · 14 min read · AI agents, Model training, LLMs, Evaluation, Data pipelines
  Fine-tuning Qwen3-4B on 51k synthetic Jupyter notebook traces, combined with a minimal ~200-line two-tool scaffold (code execution plus final\_answer), raised its DABStep easy-split accuracy from 38.67% to 75%.
- [Mini-R1: Reproduce Deepseek R1 „aha moment“ a RL tutorial](https://swe.quest/articles/mini-r1-reproduce-deepseek-r1-aha-moment-a-rl-tutorial-a09c9653360cce5a.md): Hugging Face · 2025-01-31 · Hard · 15 min read · Model training, LLMs, Python
  Recreates DeepSeek R1's "aha moment" by training Qwen2.5-3B-Instruct with GRPO on the Countdown numbers game, using rule-based format and accuracy rewards in TRL with DeepSpeed ZeRO-3 and vLLM generation on 4x H100s.
- [How NuminaMath Won the 1st AIMO Progress Prize](https://swe.quest/articles/how-numinamath-won-the-1st-aimo-progress-prize-09d841e240fdf35d.md): Hugging Face · 2024-07-11 · Hard · 16 min read · Model training, LLMs, Inference & serving, Evaluation
  NuminaMath 7B TIR won the first AIMO Progress Prize by solving 29 of 50 private test problems, using a DeepSeekMath-Base 7B model fine-tuned in two stages: first on several hundred thousand chain-of-thought math solutions, then on about 60k GPT-4-generated tool-integrated reasoning traces that interleave rationales, Python code and execution output.
- [Beat GPT-4o at Python by searching with 100 dumb LLaMAs](https://swe.quest/articles/beat-gpt-4o-at-python-by-searching-with-100-dumb-llamas-907f6997678a8d61.md): Modal · 2024-08-05 · Medium · 7 min read · LLMs, Inference & serving, Evaluation, AI for coding, Serverless
  Sampling LLaMA 3.1 8B Instruct many times and checking each candidate against HumanEval's unit tests raises pass@k from 66.4% at k=1 to 90.5% at k=100, matching GPT-4o's reported 90.2% pass@1, and to 95.1% at k=1000.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
