realDeclan commited on
Commit
d69b763
·
verified ·
1 Parent(s): 5eb4c15

Add LeanReasoning results and usage documentation

Browse files
Files changed (1) hide show
  1. README.md +127 -20
README.md CHANGED
@@ -1,39 +1,146 @@
1
  ---
2
  base_model: Qwen/Qwen3-1.7B
 
3
  pipeline_tag: text-generation
4
  library_name: transformers
5
  tags:
6
  - qwen3
 
7
  - reasoning-compression
8
  - merged-lora
 
9
  ---
10
- # Reasoning-compressed Qwen3-1.7B — local export candidate
11
 
12
- A derivative of Qwen/Qwen3-1.7B incorporating the project's five-update
13
- `marker_003` LoRA adapter (concise supervised fine-tuning plus a contextual
14
- unlikelihood penalty of 0.03). Original weights were modified by merging the
15
- trained adapter in BF16. No additional training occurs during export.
16
 
17
- This is a complete Transformers checkpoint, not an adapter-only download.
18
- The tokenizer and generation configuration are included. The concise instruction
19
- is NOT encoded as an automatic prompt or guaranteed behaviour.
20
 
21
- For the evaluated mathematical configuration, append this exact text to the
22
- question and use the tokenizer's chat template with enable_thinking=True:
23
 
24
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  Please reason step by step, and put your final answer within \boxed{}.
26
  Reason concisely. Avoid repeating calculations or checks that have already confirmed the result.
27
  ```
28
 
29
- Sampling: temperature 0.6, top_p 0.95, top_k 20, min_p 0, repetition_penalty 1,
30
- max_new_tokens 8192, do_sample=True. Evaluation uses Math-Verify final answers.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- Evaluation and public release documentation are pending. This export does not
33
- claim general-purpose improvements or guaranteed accuracy preservation.
34
- Base model: https://huggingface.co/Qwen/Qwen3-1.7B
35
- Project: https://github.com/Rufus-Maxwell/Reasoning-Compression
36
 
37
- The bundled LICENSE preserves the upstream Apache 2.0 terms. No new release
38
- licence for the project's modifications has been selected by this export.
39
- This file is a local release draft, not a publication action.
 
1
  ---
2
  base_model: Qwen/Qwen3-1.7B
3
+ base_model_relation: finetune
4
  pipeline_tag: text-generation
5
  library_name: transformers
6
  tags:
7
  - qwen3
8
+ - reasoning
9
  - reasoning-compression
10
  - merged-lora
11
+ - math
12
  ---
13
+ # LeanReasoning
14
 
15
+ **Shorter reasoning. Faster answers.**
 
 
 
16
 
17
+ LeanReasoning is a fine-tuned Qwen3-1.7B model designed to reduce unnecessary reasoning while retaining comparable mathematical accuracy.
 
 
18
 
19
+ With the evaluated concise prompt, it used **76% fewer thinking tokens** and **75% less batched generation time** than the original model with the standard prompt. Accuracy was **89% versus 90%**, rounded.
 
20
 
21
+ This is a **complete BF16 Transformers checkpoint** with the trained adapter merged into its weights. Load it directly: no separate adapter or PEFT loading step is required.
22
+
23
+ [Project and research archives](https://github.com/Rufus-Maxwell/Reasoning-Compression) · [Detailed report](https://github.com/Rufus-Maxwell/Reasoning-Compression/blob/main/docs/project-report-2026-11-04.md) · [Base model](https://huggingface.co/Qwen/Qwen3-1.7B)
24
+
25
+ ## Results
26
+
27
+ Each configuration covers the same 600 final-evaluation questions, with three sampled responses per question: **1,800 responses per row**.
28
+
29
+ | Configuration | Correct | Accuracy | Mean thinking tokens | Batched generation time |
30
+ |---|---:|---:|---:|---:|
31
+ | Original Qwen3-1.7B — standard prompt | 1,622/1,800 | 90.11% | 1,940 | 12h 00m |
32
+ | Original Qwen3-1.7B — concise prompt | 1,624/1,800 | 90.22% | 1,036 | 7h 14m |
33
+ | **LeanReasoning — concise prompt, merged** | **1,599/1,800** | **88.83%** | **466** | **2h 58m** |
34
+
35
+ Against the original model with the **same concise prompt**, LeanReasoning used **55% fewer thinking tokens and 59% less generation time**. No responses in the merged-model evaluation reached the 8,192-token cap.
36
+
37
+ The main headline combines training, concise prompting and merged deployment. The exact observed accuracy difference was −1.28 percentage points against the standard baseline and −1.39 against the concise baseline; unchanged accuracy has not been established.
38
+
39
+ The model configuration was selected on development data before the first held-out evaluation. This merged-model measurement is a fresh-seed repeat on those same final questions, with no additional training. The original-model controls come from the first evaluation.
40
+
41
+ Timing covers generation in batches of four on a single RTX 3090. It excludes model loading, training, export, scoring and network overhead. It measures complete-workload runtime, **not individual-response latency**. Three responses to one question are correlated observations.
42
+
43
+ ## Use the evaluated prompt
44
+
45
+ Append these two lines to the question:
46
+
47
+ ```text
48
  Please reason step by step, and put your final answer within \boxed{}.
49
  Reason concisely. Avoid repeating calculations or checks that have already confirmed the result.
50
  ```
51
 
52
+ Use the included tokenizer's chat template with `enable_thinking=True`.
53
+
54
+ **The concise instruction is supplied by the caller.** It is not automatically inserted by the model or its tokenizer. The reported combined result depends on using it.
55
+
56
+ ## Run with Transformers
57
+
58
+ The study used Transformers 4.56.2 and PyTorch 2.8.0+cu126. The example below targets a CUDA GPU with BF16 support and sufficient memory. It demonstrates single-response use, not the batched timing benchmark.
59
+
60
+ ```python
61
+ import torch
62
+ from transformers import AutoModelForCausalLM, AutoTokenizer
63
+
64
+ model_id = "realDeclan/LeanReasoning"
65
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
66
+ model = AutoModelForCausalLM.from_pretrained(
67
+ model_id,
68
+ dtype=torch.bfloat16,
69
+ attn_implementation="sdpa",
70
+ ).to("cuda").eval()
71
+
72
+ question = "A shop sells 12 notebooks at £3 each. What is the total revenue?"
73
+ prompt = (
74
+ question
75
+ + "\nPlease reason step by step, and put your final answer within \\boxed{}."
76
+ + "\nReason concisely. Avoid repeating calculations or checks that have already confirmed the result."
77
+ )
78
+ text = tokenizer.apply_chat_template(
79
+ [{"role": "user", "content": prompt}],
80
+ tokenize=False,
81
+ add_generation_prompt=True,
82
+ enable_thinking=True,
83
+ )
84
+ inputs = tokenizer(
85
+ text,
86
+ add_special_tokens=False,
87
+ return_tensors="pt",
88
+ ).to(model.device)
89
+
90
+ with torch.inference_mode():
91
+ outputs = model.generate(
92
+ **inputs,
93
+ do_sample=True,
94
+ temperature=0.6,
95
+ top_p=0.95,
96
+ top_k=20,
97
+ min_p=0.0,
98
+ repetition_penalty=1.0,
99
+ max_new_tokens=8192,
100
+ use_cache=True,
101
+ pad_token_id=tokenizer.eos_token_id,
102
+ )
103
+
104
+ new_tokens = outputs[0, inputs["input_ids"].shape[-1]:]
105
+ print(tokenizer.decode(new_tokens, skip_special_tokens=False))
106
+ ```
107
+
108
+ While this repository is private, authenticate with an account that has access before loading it. To use an existing local copy, set `model_id` to that folder's path.
109
+
110
+ The example prints the generated reasoning and answer. Sampling, batch size and software/hardware differences can change individual outputs; it is not an exact replay of the saved evaluation schedule.
111
+
112
+ ## Training and export
113
+
114
+ LeanReasoning incorporates the project's `marker_003` LoRA adapter:
115
+
116
+ - Concise supervised fine-tuning on 20 selected positive traces.
117
+ - A contextual unlikelihood penalty of 0.03 at 20 annotated negative positions across 10 questions.
118
+ - Five optimiser updates; LoRA rank 16, alpha 32, dropout 0.
119
+ - BF16 merging into the original model, followed by saving, verification and reloading for evaluation.
120
+
121
+ The penalty discourages selected unwanted continuations in their annotated contexts. It is not a global ban on words such as “wait”, “but” or “alternatively”. The project owner reviewed the annotations.
122
+
123
+ This work was inspired by UkisAI's Swift research. It is an independent project, not an official Qwen or UkisAI release.
124
+
125
+ ## Evaluation and scope
126
+
127
+ Final-answer correctness was scored using Hugging Face Math-Verify 0.9.0. Development, discovery/training and final question partitions were kept separate. The report contains the earlier separate-adapter results, development comparisons, uncertainty estimates and supporting diagnostics.
128
+
129
+ The measured improvement concerns mathematical reasoning under the stated prompts and generation settings. Broader improvements in coding, conversation, factual knowledge or other tasks have not been established.
130
+
131
+ Shorter runtime reduces GPU time required for this workload and can lower time-based hosting costs. Electricity consumption was not directly measured, so no numerical energy-saving claim is made.
132
+
133
+ ## Files
134
+
135
+ The checkpoint contains two weight shards:
136
+
137
+ - `model-00001-of-00002.safetensors`
138
+ - `model-00002-of-00002.safetensors`
139
+
140
+ The accompanying index, model configuration, generation configuration, tokenizer and chat template are required parts of the export. Download the repository as a model folder.
141
+
142
+ ## Licence and attribution
143
 
144
+ Base model: [Qwen/Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B).
 
 
 
145
 
146
+ The bundled LICENSE preserves the upstream Apache 2.0 terms. This derivative modifies the original weights through fine-tuning and merging. The project's release licence for its modifications has not yet been selected; this card does not assign a new one.