> your AI agent picks dependencies from memory; give it dated facts — try starlog.dev ↗ vet your agent's deps ↗ vibe-coding is fine. vibe-importing isn’t. — try starlog.dev ↗ vibe-importing isn’t fine ↗ your agent has never seen your private packages — try starlog.dev ↗ facts for private packages ↗ a linter for the dependencies your AI agent picks — try starlog.dev ↗ a linter for agent deps ↗

Back to Articles

Teaching Language Models to Think: How TinyZero Reproduces DeepSeek R1's Reasoning for $30

[ View on GitHub ]

Teaching Language Models to Think: How TinyZero Reproduces DeepSeek R1's Reasoning for $30

Hook

What if you could teach a 3-billion parameter model to reason through problems step-by-step, verify its own answers, and develop search abilities—all without showing it a single example of correct reasoning? That's exactly what TinyZero accomplishes for the cost of a nice dinner.

Context

When DeepSeek released their R1-Zero model, they demonstrated something remarkable: large language models could develop sophisticated reasoning capabilities purely through reinforcement learning, without any supervised fine-tuning on reasoning examples. The model learned to generate chain-of-thought explanations, self-verify solutions, and even backtrack when it made mistakes—all emergent behaviors from the RL training process itself.

But R1-Zero required massive compute resources and industrial-scale infrastructure, putting it far beyond the reach of independent researchers, students, or hobbyists who wanted to understand how this reasoning emergence actually works. TinyZero emerged as a minimal reproduction that brings this capability down to earth: it demonstrates the same reasoning emergence phenomena using small models (0.5B-3B parameters) on simple synthetic tasks, with complete training runs costing under $30. Built on top of the veRL reinforcement learning library, it provides a clear, reproducible path for anyone to witness and experiment with how models learn to think.

Technical Insight

TinyZero's architecture centers on Proximal Policy Optimization (PPO), a policy gradient method that's become the workhorse of RLHF and reasoning training. The system uses three key components: a policy model (the language model being trained), a critic model (for value estimation to reduce variance), and vLLM for fast rollout generation during training.

The training loop works like this: the policy model generates reasoning traces for synthetic problems (like countdown tasks or multiplication), receives rewards based on whether it reaches the correct final answer, and updates through PPO to increase the probability of successful reasoning chains. Crucially, there's no supervision on the reasoning steps themselves—only sparse rewards on final outcomes. This forces the model to discover that step-by-step reasoning and self-verification improve its success rate.

Here's what a typical training configuration looks like:

# Configuration for training Qwen2.5-3B on countdown task
config = {
    "model": "Qwen/Qwen2.5-3B",
    "task": "countdown",
    "rollout_size": 512,  # Generate 512 reasoning traces per iteration
    "ppo_epochs": 4,
    "learning_rate": 1e-6,
    "kl_penalty": 0.02,  # Prevent diverging too far from initial model
    "max_sequence_length": 2048,
    "critic_warmup_steps": 100,
    "use_vllm": True,
    "tensor_parallel_size": 2  # For multi-GPU inference
}

The countdown task is deceptively simple but perfect for observing reasoning emergence. Given a target number and a set of starting numbers, the model must generate a sequence of arithmetic operations to reach the target. Early in training, models simply guess operations randomly. After a few thousand steps, something clicks: they start generating intermediate steps, checking their work, and even using phrases like "let me verify" without ever being told to do so.

One of TinyZero's most interesting findings is that base models (pre-trained but not instruction-tuned) actually learn reasoning faster and more reliably than their instruct-tuned counterparts. The hypothesis is that instruction tuning creates strong priors about output format and style that make exploration harder during RL—the model is less willing to experiment with novel reasoning approaches. This has implications for how we think about model alignment: pre-alignment might help for safety, but it could hinder learning in RL regimes.

The infrastructure leverages veRL's integration with vLLM for efficient rollout generation. During each PPO iteration, the system needs to generate hundreds of completions from the current policy. Using standard HuggingFace generation would be prohibitively slow; vLLM's paged attention and continuous batching make this feasible. The system uses Ray for distributed execution, allowing the rollout generation (inference-heavy) and PPO updates (training-heavy) to run on different GPU configurations.

Memory management is critical at this scale. For a 3B model, TinyZero uses gradient checkpointing to trade compute for memory, enabling training on consumer GPUs. The typical setup uses 2-4 A100 40GB GPUs or equivalent, though smaller models can run on more modest hardware:

# Enable memory optimizations for consumer hardware
training_args = {
    "gradient_checkpointing": True,
    "gradient_accumulation_steps": 4,
    "per_device_train_batch_size": 2,
    "max_grad_norm": 1.0,
    "bf16": True  # Mixed precision for memory efficiency
}

The reward function is intentionally sparse—1.0 for correct final answers, 0.0 otherwise. There's no intermediate reward shaping, no bonuses for using certain formats, no penalties for verbose reasoning. This minimalism is important: it proves that the reasoning structure emerges from the optimization dynamics itself, not from clever reward engineering. The model discovers that breaking problems into steps, maintaining a working memory of intermediate results, and double-checking calculations all instrumentally improve its ability to get that final 1.0 reward.

Gotcha

The most significant limitation is right there in the repository: TinyZero is deprecated. The maintainers explicitly state that the project served its purpose as a minimal reproduction and users should now work with veRL directly. This means no ongoing bug fixes, no new features, and limited support for newer model architectures or GPU configurations. It's educational infrastructure, not production code.

Scale matters more than you'd expect. While TinyZero nominally supports models from 0.5B to 3B parameters, the reality is that reliable reasoning emergence requires at least 1.5B parameters, and 3B is where it really shines. The Qwen2.5-0.5B experiments frequently fail to converge to reasoning behaviors—the model learns to game the reward in simpler ways that don't generalize. This suggests there's a minimum model capacity threshold for these emergent capabilities, which aligns with broader research on emergence. You can't just scale this approach down arbitrarily and expect magic. Additionally, GPU memory issues plague users on consumer hardware; even with gradient checkpointing, training 3B models with PPO pushes VRAM limits. The multi-GPU tensor parallelism helps but adds configuration complexity that can be finicky with Ray's distributed execution.

Verdict

Use TinyZero if you're a researcher, student, or curious ML engineer who wants to understand how reasoning emerges in language models through reinforcement learning, especially if you're working with limited compute budgets. The sub-$30 training cost and clear synthetic tasks make it perfect for educational exploration and building intuition about RL-based reasoning. It's an excellent starting point for prototyping ideas before committing to larger-scale experiments. Skip if you need production-ready infrastructure (the maintainers tell you to use veRL instead), if you're trying to train models smaller than 1.5B parameters (reasoning emergence is unreliable), or if you lack access to at least 40GB of GPU memory for the 3B model experiments. Also skip if you want ongoing maintenance and support—this is a snapshot of a research result, not an evolving tool. For serious reasoning research, treat TinyZero as the educational tutorial and graduate to veRL for the real work.