A causal language model fine-tuned to generate conceptual explanations in the style of Richard Feynman, combining supervised warm-up with on-policy reinforcement learning (Group Relative Proximal Optimization, GRPO) and accelerated inference via vLLM. The model excels at breaking down complex ideas into first-principles intuitions, concrete analogies, and short, clear paragraphs.
-
Supervised Fine-Tuning (SFT)
- ~750 carefully designed prompt–completion pairs.
- Each pair follows a Feynman-style teaching pattern:
- simple language,
- layered explanation,
- everyday analogies,
- checks for understanding.
- Implemented with LoRA adapters for efficient parameter updates.
-
Reinforcement Learning with GRPO
- Reward Model: trained on GPT-4o-mini preference judgments between candidate completions.
- Objective: maximize adherence to “first-principle reasoning” and clarity of explanation.
- Algorithm: Group Relative Proximal Optimization (GRPO), a variant of PPO adapted for group-based baselines.
- On-policy rollouts were generated using the SFT-warm model, with iterative policy updates guided by the reward model.
-
Merging and Optimization
- LoRA adapters from SFT and RLHF stages were merged into the base model.
- Final model optimized for inference with vLLM, reducing latency and improving throughput.
1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
3model_id = "KhushalM/Qwen2.5-1.5-Feynman-GRPO-vLLM-Merged"
4tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
5model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="auto", trust_remote_code=True)
6
7generator = pipeline(
8 "text-generation",
9 model=model,
10 tokenizer=tokenizer,
11 device="cuda" # or "cpu"
12)
13
14prompt = "Explain quantum entanglement from first principles."
15output = generator(prompt, max_new_tokens=200, temperature=0.7, top_p=0.9)
16print(output[0]["generated_text"])