Update README.md
Browse files
README.md
CHANGED
|
@@ -1,118 +1,149 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
<accuracy>TODO % <!-- replace with your final number after eval rerun --></accuracy>
|
| 59 |
-
<note>Accuracy uses the integer after the “####” line as ground truth.</note>
|
| 60 |
-
</evaluation>
|
| 61 |
-
|
| 62 |
-
<intended-uses>
|
| 63 |
-
<primary>
|
| 64 |
-
• Tutoring or explanation of basic arithmetic word problems.
|
| 65 |
-
• As a reward‑model or verifier for chain‑of‑thought tasks.
|
| 66 |
-
</primary>
|
| 67 |
-
<out-of-scope>
|
| 68 |
-
• High‑stakes numeric reasoning (finance, medicine).
|
| 69 |
-
• Non‑English math word problems (not in training set).
|
| 70 |
-
• Any use that violates the LLAMA 3 or GSM8K licenses.
|
| 71 |
-
</out-of-scope>
|
| 72 |
-
</intended-uses>
|
| 73 |
-
|
| 74 |
-
<limitations>
|
| 75 |
-
• Still hallucinates reasoning steps; only the final integer is enforced.
|
| 76 |
-
• Trained solely on short grade‑school problems (< 10 sentences).
|
| 77 |
-
• No exposure to multi‑digit multiplication/division beyond GSM8K scope.
|
| 78 |
-
• English‑only; performance on other languages unverified.
|
| 79 |
-
</limitations>
|
| 80 |
-
|
| 81 |
-
<ethical-considerations>
|
| 82 |
-
• The chain‑of‑thought text may leak private reasoning if used on sensitive
|
| 83 |
-
user queries; consider stripping <thinking> tags in production.
|
| 84 |
-
• GSM8K is MIT‑licensed public data, but it contains synthetic examples that
|
| 85 |
-
may reflect unintended cultural bias.
|
| 86 |
-
</ethical-considerations>
|
| 87 |
-
|
| 88 |
-
<how-to-use>
|
| 89 |
-
< trained using **Group Relative Policy Optimization (GRPO)** to enable autonomous mathematical reasoning capabilities. Unlike traditional supervised fine-tuning approaches, this model learned to reason through reinforcement learning without requiring pre-labeled reasoning examples or teacher model distillation.
|
| 6 |
+
|
| 7 |
+
## Key Features
|
| 8 |
+
|
| 9 |
+
- **Structured Reasoning**: Generates step-by-step mathematical reasoning enclosed in `<thinking>` tags
|
| 10 |
+
- **Formatted Answers**: Provides final numerical answers in `<answer>` tags
|
| 11 |
+
- **Autonomous Learning**: Trained using reward functions rather than human-annotated reasoning examples
|
| 12 |
+
- **Mathematical Focus**: Optimized for grade school math word problems requiring multi-step reasoning
|
| 13 |
+
|
| 14 |
+
## Training Details
|
| 15 |
+
|
| 16 |
+
### Training Method
|
| 17 |
+
- **Algorithm**: Group Relative Policy Optimization (GRPO)
|
| 18 |
+
- **Base Model**: meta-llama/Meta-Llama-3.1-8B-Instruct
|
| 19 |
+
- **Fine-tuning**: LoRA with NF4 quantization
|
| 20 |
+
- **Dataset**: GSM8K (Grade School Math 8K)
|
| 21 |
+
|
| 22 |
+
### Training Configuration
|
| 23 |
+
- **LoRA rank**: 8
|
| 24 |
+
- **LoRA alpha**: 32
|
| 25 |
+
- **Learning rate**: 2e-4
|
| 26 |
+
- **Batch size**: 32 (effective)
|
| 27 |
+
- **Generations per prompt**: 2-4
|
| 28 |
+
- **Max completion length**: 128-256 tokens
|
| 29 |
+
- **Temperature**: 0.7
|
| 30 |
+
|
| 31 |
+
### Reward Functions
|
| 32 |
+
The model was trained using multiple custom reward functions:
|
| 33 |
+
1. **Format compliance**: Ensures proper `<thinking>` and `<answer>` tag structure
|
| 34 |
+
2. **Answer correctness**: Validates numerical accuracy against ground truth
|
| 35 |
+
3. **Integer validation**: Confirms answers are properly formatted integers
|
| 36 |
+
4. **Output cleanliness**: Penalizes extraneous text after answer tags
|
| 37 |
+
|
| 38 |
+
## Usage
|
| 39 |
+
|
| 40 |
+
### Required Format
|
| 41 |
+
The model expects a specific system prompt to maintain the structured output format:
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
SYSTEM_PROMPT = """
|
| 45 |
+
Respond in the following format and make sure the entire response is wrapped in <reasoning> and <answer> tags with no other text outside of these tags:
|
| 46 |
+
<thinking>
|
| 47 |
+
your reasoning goes here and do not use newlines so that the entire reasoning becomes a single paragraph
|
| 48 |
+
</thinking>
|
| 49 |
+
<answer>
|
| 50 |
+
your answer goes here
|
| 51 |
+
</answer>
|
| 52 |
+
"""
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
### Example Usage
|
| 56 |
+
|
| 57 |
+
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 59 |
|
| 60 |
+
model = AutoModelForCausalLM.from_pretrained("your-username/llama3-grpo-math-reasoning")
|
| 61 |
+
tokenizer = AutoTokenizer.from_pretrained("your-username/llama3-grpo-math-reasoning")
|
| 62 |
+
|
| 63 |
+
messages = [
|
| 64 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 65 |
+
{"role": "user", "content": "Mark is looking to buy a total of 12 pieces of fruit at the store. He has already chosen 3 apples. He has also selected a bunch of bananas containing 4 bananas. How many oranges does he need to pick out to have 12 total pieces of fruit?"}
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
|
| 69 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 70 |
+
|
| 71 |
+
with torch.no_grad():
|
| 72 |
+
outputs = model.generate(
|
| 73 |
+
**inputs,
|
| 74 |
+
max_new_tokens=128,
|
| 75 |
+
temperature=0.7,
|
| 76 |
+
top_p=0.9,
|
| 77 |
+
do_sample=True
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 81 |
+
print(response)
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
**Expected Output:**
|
| 85 |
+
```
|
| 86 |
+
<thinking>
|
| 87 |
+
Mark wants 12 total pieces of fruit. He already has 3 apples and 4 bananas, which gives him 3 + 4 = 7 pieces of fruit. To reach 12 total pieces, he needs 12 - 7 = 5 more pieces of fruit, which would be oranges.
|
| 88 |
+
</thinking>
|
| 89 |
+
<answer>
|
| 90 |
+
5
|
| 91 |
+
</answer>
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## Performance
|
| 95 |
+
|
| 96 |
+
- **Dataset**: GSM8K test split (1,319 examples)
|
| 97 |
+
- **Evaluation Metric**: Exact match accuracy on final numerical answers
|
| 98 |
+
- **Performance**: [Insert actual accuracy from your evaluation]
|
| 99 |
+
|
| 100 |
+
## Technical Details
|
| 101 |
+
|
| 102 |
+
### Model Architecture
|
| 103 |
+
- **Base**: Llama 3.1-8B-Instruct
|
| 104 |
+
- **Parameters**: ~8B total, ~21M trainable (LoRA)
|
| 105 |
+
- **Quantization**: NF4 with double quantization
|
| 106 |
+
- **Precision**: bfloat16
|
| 107 |
+
|
| 108 |
+
### GRPO Specifics
|
| 109 |
+
- **Group size**: 2-4 completions per prompt
|
| 110 |
+
- **KL coefficient (β)**: 0.02
|
| 111 |
+
- **Advantage normalization**: Group-based mean/std normalization
|
| 112 |
+
- **Policy updates**: Advantage-weighted importance sampling
|
| 113 |
+
|
| 114 |
+
## Limitations
|
| 115 |
+
|
| 116 |
+
- **Domain**: Primarily trained on grade school mathematics; may not generalize to advanced mathematical concepts
|
| 117 |
+
- **Format dependency**: Requires specific system prompt for optimal performance
|
| 118 |
+
- **Language**: English only
|
| 119 |
+
- **Reasoning scope**: Optimized for multi-step arithmetic rather than complex mathematical proofs
|
| 120 |
+
|
| 121 |
+
## Ethical Considerations
|
| 122 |
+
|
| 123 |
+
- **Educational use**: Designed to assist with mathematical learning, not replace mathematical education
|
| 124 |
+
- **Accuracy**: While trained for correctness, users should verify mathematical solutions for critical applications
|
| 125 |
+
- **Bias**: Inherits potential biases from the base Llama model and GSM8K dataset
|
| 126 |
+
|
| 127 |
+
## Citation
|
| 128 |
+
|
| 129 |
+
If you use this model, please cite:
|
| 130 |
+
|
| 131 |
+
```bibtex
|
| 132 |
+
@misc{llama3-grpo-math-reasoning,
|
| 133 |
+
title={Llama 3.1-8B Mathematical Reasoning via Group Relative Policy Optimization},
|
| 134 |
+
author={[Your Name]},
|
| 135 |
+
year={2025},
|
| 136 |
+
howpublished={\\url{https://huggingface.co/your-username/llama3-grpo-math-reasoning}}
|
| 137 |
+
}
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
## Acknowledgments
|
| 141 |
+
|
| 142 |
+
- Meta AI for the Llama 3.1 base model
|
| 143 |
+
- OpenAI for the GSM8K dataset
|
| 144 |
+
- Hugging Face TRL library for GRPO implementation
|
| 145 |
+
- The reinforcement learning and mathematical reasoning research communities
|
| 146 |
+
|
| 147 |
+
## License
|
| 148 |
+
|
| 149 |
+
This model inherits the license from meta-llama/Meta-Llama-3.1-8B-Instruct. Please refer to the [original model's license](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct) for usage terms.
|