Text Generation
PEFT
Safetensors
English
llama
math
code
lora
adapter
autoscientist
adaption
conversational
Instructions to use flamiinngo/adaption_math_word_problems_solutions with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use flamiinngo/adaption_math_word_problems_solutions with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("togethercomputer/Meta-Llama-3.3-70B-Instruct-Reference") model = PeftModel.from_pretrained(base_model, "flamiinngo/adaption_math_word_problems_solutions") - Notebooks
- Google Colab
- Kaggle
Model card: 72-28 result, what produced the 12-point gain, limitations
Browse files
README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: llama3.3
|
| 3 |
+
base_model: meta-llama/Llama-3.3-70B-Instruct
|
| 4 |
+
datasets:
|
| 5 |
+
- flamiinngo/math-code-qa-v2
|
| 6 |
+
tags:
|
| 7 |
+
- math
|
| 8 |
+
- code
|
| 9 |
+
- lora
|
| 10 |
+
- peft
|
| 11 |
+
- adapter
|
| 12 |
+
- autoscientist
|
| 13 |
+
- adaption
|
| 14 |
+
language:
|
| 15 |
+
- en
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
library_name: peft
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Math & Code β Llama-3.3-70B LoRA
|
| 21 |
+
|
| 22 |
+
A LoRA adapter for **Llama-3.3-70B-Instruct**, fine-tuned to solve mathematical
|
| 23 |
+
problems β arithmetic word problems through algebra, geometry and combinatorics β
|
| 24 |
+
and answer short coding questions.
|
| 25 |
+
|
| 26 |
+
Trained with **Adaption Labs' AutoScientist** for the AutoScientist Challenge
|
| 27 |
+
(Math & Code category).
|
| 28 |
+
|
| 29 |
+
## Result
|
| 30 |
+
|
| 31 |
+
| Evaluation | Base | Adapted |
|
| 32 |
+
|---|---|---|
|
| 33 |
+
| Math category | 28 | **72** |
|
| 34 |
+
| In-distribution test set | 52 | 48 |
|
| 35 |
+
|
| 36 |
+
Wins in a paired comparison, not accuracy percentages.
|
| 37 |
+
|
| 38 |
+
The rows disagree, which is worth explaining. On the narrow in-distribution set a
|
| 39 |
+
judge slightly prefers the base model's phrasing. Across the wider category β
|
| 40 |
+
including problems well outside the training distribution β the adapted model wins
|
| 41 |
+
decisively. The mathematical substance generalised further than the answer style.
|
| 42 |
+
|
| 43 |
+
## What produced the 12-point gain
|
| 44 |
+
|
| 45 |
+
An earlier version of this model scored **60β28** on the same category evaluation.
|
| 46 |
+
The difference was a single filter in the training data.
|
| 47 |
+
|
| 48 |
+
v1 capped every solution at 18β75 words. In the upstream corpus, MATH-level
|
| 49 |
+
solutions have a **median length of 121β156 words**, while grade-school word
|
| 50 |
+
problems sit at 89β101. The cap therefore kept only the shortest, easiest examples
|
| 51 |
+
from the hard sources β the model trained almost entirely on arithmetic and was
|
| 52 |
+
then evaluated across the full difficulty range.
|
| 53 |
+
|
| 54 |
+
Setting the word budget per source (30β150 for algebra and geometry, 18β80 for
|
| 55 |
+
word problems) raised solution p90 from 77 words to 133, and the category win rate
|
| 56 |
+
from 60 to 72.
|
| 57 |
+
|
| 58 |
+
## Usage
|
| 59 |
+
|
| 60 |
+
The adapter is stored unpacked and loads directly.
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
import torch
|
| 64 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 65 |
+
from peft import PeftModel
|
| 66 |
+
|
| 67 |
+
BASE = "meta-llama/Llama-3.3-70B-Instruct"
|
| 68 |
+
ADAPTER = "flamiinngo/adaption_math_word_problems_solutions"
|
| 69 |
+
|
| 70 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE)
|
| 71 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 72 |
+
BASE, torch_dtype=torch.bfloat16, device_map="auto"
|
| 73 |
+
)
|
| 74 |
+
model = PeftModel.from_pretrained(model, ADAPTER)
|
| 75 |
+
model.eval()
|
| 76 |
+
|
| 77 |
+
messages = [{"role": "user", "content":
|
| 78 |
+
"Mrs Thompson has 7 Harry Potter books, 6 Twilight books and 5 Hunger Games "
|
| 79 |
+
"books. Each series must stay together on the shelf. How many orderings are "
|
| 80 |
+
"there?"}]
|
| 81 |
+
inputs = tokenizer.apply_chat_template(
|
| 82 |
+
messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 83 |
+
|
| 84 |
+
out = model.generate(inputs, max_new_tokens=400, do_sample=False)
|
| 85 |
+
print(tokenizer.decode(out[0][inputs.shape[-1]:], skip_special_tokens=True))
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
**Hardware:** the 70B base needs roughly 140 GB in bf16, or about 40 GB with 4-bit
|
| 89 |
+
quantisation. The adapter is 3.3 GB.
|
| 90 |
+
|
| 91 |
+
**Output style:** brief worked steps, then the result stated explicitly as
|
| 92 |
+
"The answer is X."
|
| 93 |
+
|
| 94 |
+
**Note on the base model name.** `adapter_config.json` records
|
| 95 |
+
`togethercomputer/Meta-Llama-3.3-70B-Instruct-Reference`, the base as served during
|
| 96 |
+
training. Same architecture β load against `meta-llama/Llama-3.3-70B-Instruct`.
|
| 97 |
+
|
| 98 |
+
## Training
|
| 99 |
+
|
| 100 |
+
| Parameter | Value |
|
| 101 |
+
|---|---|
|
| 102 |
+
| Base | `meta-llama/Llama-3.3-70B-Instruct` |
|
| 103 |
+
| Rank (`r`) | 64 |
|
| 104 |
+
| `lora_alpha` | 128 |
|
| 105 |
+
| Target modules | all-linear |
|
| 106 |
+
| Epochs | 3 |
|
| 107 |
+
| Peak learning rate | 1e-4, cosine |
|
| 108 |
+
|
| 109 |
+
## Dataset
|
| 110 |
+
|
| 111 |
+
[**flamiinngo/math-code-qa-v2**](https://huggingface.co/datasets/flamiinngo/math-code-qa-v2)
|
| 112 |
+
β 5,297 rows (4,197 math, 1,100 code), every math answer ending in a result
|
| 113 |
+
verified against the upstream `expected_answer` column. Derived from
|
| 114 |
+
[nvidia/OpenMathInstruct-2](https://huggingface.co/datasets/nvidia/OpenMathInstruct-2)
|
| 115 |
+
and [sahil2801/CodeAlpaca-20k](https://huggingface.co/datasets/sahil2801/CodeAlpaca-20k),
|
| 116 |
+
both CC-BY-4.0.
|
| 117 |
+
|
| 118 |
+
Also on Kaggle:
|
| 119 |
+
[model](https://www.kaggle.com/models/flamiinngo/adaption_math-41946c32-256d-4d24-a1ee-6effb91b690c) Β·
|
| 120 |
+
[dataset](https://www.kaggle.com/datasets/flamiinngo/math-code-qa-v2)
|
| 121 |
+
|
| 122 |
+
## Limitations
|
| 123 |
+
|
| 124 |
+
- **It can produce confident wrong reasoning.** The training solutions are
|
| 125 |
+
model-generated upstream; only their final answers were verified. Errors in
|
| 126 |
+
algebraic reasoning exist in the data and this model reproduces that style of
|
| 127 |
+
mistake. Check any result that matters.
|
| 128 |
+
- **Not a calculator.** Fine-tuning improved the working, not arithmetic guarantees.
|
| 129 |
+
- **Scope is school through early-undergraduate.** Not olympiad or research
|
| 130 |
+
mathematics.
|
| 131 |
+
- **Code output is untested.** The code training data was filtered for length,
|
| 132 |
+
not executed. Treat generated code as a draft.
|
| 133 |
+
- **Win rate is not accuracy.** It measures preference against one base model on
|
| 134 |
+
one evaluation.
|
| 135 |
+
- **English only.**
|
| 136 |
+
|
| 137 |
+
## License
|
| 138 |
+
|
| 139 |
+
The adapter is a derivative of Llama-3.3-70B-Instruct and is subject to the
|
| 140 |
+
**Llama 3.3 Community License**. The training data is CC-BY-4.0.
|
| 141 |
+
|
| 142 |
+
## Acknowledgements
|
| 143 |
+
|
| 144 |
+
- **Adaption Labs** β AutoScientist platform and the challenge
|
| 145 |
+
- **NVIDIA** and **sahil2801** β upstream open datasets
|
| 146 |
+
- **Meta** β Llama 3.3 base model
|