How rasbt/reasoning-from-scratch works
This is the companion code for a hands-on book about building a small reasoning LLM from a pretrained Qwen3 model. The principal workflow is model inference and evaluation, followed by inference-time scaling or reinforcement-learning training; generated reasoning data can also support distillation, and trained models can be used through Hugging Face. The graph preserves these documented branches and the chat and evaluation examples. Some relationships are only described at the book level, so those links are dashed; unsampled implementations are represented by their exact enclosing directories.
Main entry points: ch02.py Text Generation · ch04.py Inference Scaling · ch06.py RLVR Methods · 02_math500-verifier-scripts MATH-500 Evaluation
Components 21
Model Runtime
- Qwen3 Model
reasoning_from_scratch/qwen3.py - Batched Qwen3
reasoning_from_scratch/qwen3_batched.py - Optimized Qwen3
reasoning_from_scratch/qwen3_optimized.py - Text Generation
reasoning_from_scratch/ch02.py
Reasoning Methods
- Inference Scaling
reasoning_from_scratch/ch04.py - Self Refinement
reasoning_from_scratch/ch05.py
Training
- RLVR Methods
reasoning_from_scratch/ch06.py - GRPO Training
ch06/02_rlvr_grpo_scripts_intro/rlvr_grpo_original_no_kl.py - Distributed GRPO
ch06/02_rlvr_grpo_scripts_intro/rlvr_grpo_original_no_kl_batched_fsdp.py - Advanced GRPO
ch07/03_rlvr_grpo_scripts_advanced
Data And Deployment
- Reasoning Data Generation
ch08/02_generate_distillation_data - Distillation Training
ch08/04_train_with_distillation/distill_batched.py - Hugging Face Export
ch08/06_use_via_huggingface/export_approach/hf_export.py - Hugging Face Wrapper
ch08/06_use_via_huggingface/wrapper_approach/hf_wrapper.py
Evaluation And Interfaces
- Evaluation Utilities
reasoning_from_scratch/ch03.py - Advanced Parser
reasoning_from_scratch/bonus/parser.py - MATH-500 Evaluation
ch03/02_math500-verifier-scripts - LLM Benchmarks
chF - Chat Interfaces
chG/01_main-chapter-code
Other components
- Reader
- Model Providers
Connections 27
- Reader → Text Generation: runs inference
README.md - Text Generation → Qwen3 Model: runs model
reasoning_from_scratch/ch02.py - Text Generation → Batched Qwen3: supports batching
ch03/02_math500-verifier-scripts/evaluate_math500_batched.py - Text Generation → Optimized Qwen3: benchmarks variant
ch02/03_optimized-LLM/compare_inference.py - Reader → MATH-500 Evaluation: evaluates answers
README.md - MATH-500 Evaluation → Evaluation Utilities: uses utilities
ch03/02_math500-verifier-scripts/evaluate_math500_batched.py - MATH-500 Evaluation → Advanced Parser: uses parser
- Reader → Inference Scaling: scales inference
README.md - Inference Scaling → Text Generation: uses generation
reasoning_from_scratch/ch04.py - Inference Scaling → Evaluation Utilities: extracts answers
ch04/02_math500-inference-scaling-scripts/self_consistency_math500.py - Reader → Self Refinement: refines responses
README.md - Self Refinement → Inference Scaling: uses scaling methods
reasoning_from_scratch/ch05.py - Reader → GRPO Training: trains model
README.md - GRPO Training → RLVR Methods: uses RL methods
ch06/02_rlvr_grpo_scripts_intro/rlvr_grpo_original_no_kl.py - Distributed GRPO → RLVR Methods: uses RL methods
ch06/02_rlvr_grpo_scripts_intro/rlvr_grpo_original_no_kl_batched_fsdp.py - Advanced GRPO → RLVR Methods: uses RL methods
ch07/03_rlvr_grpo_scripts_advanced/7_6_plus_format_reward.py - RLVR Methods → Evaluation Utilities: grades answers
reasoning_from_scratch/ch06.py - Model Providers → Reasoning Data Generation: supplies completions
- Reader → Reasoning Data Generation: generates data
README.md - Reader → Distillation Training: distills model
README.md - Distillation Training → Batched Qwen3: trains batched model
ch08/04_train_with_distillation/distill_batched.py - Reader → Hugging Face Export: exports model
README.md - Reader → Hugging Face Wrapper: uses model
README.md - Reader → LLM Benchmarks: compares models
README.md - Reader → Chat Interfaces: chats with model
README.md - Chat Interfaces → Qwen3 Model: uses model
chG/01_main-chapter-code/qwen3_chat_interface_multiturn.py - Hugging Face Wrapper → Qwen3 Model: wraps model
ch08/06_use_via_huggingface/wrapper_approach/hf_wrapper.py