MikeDean commited on
Commit
9feb077
·
verified ·
1 Parent(s): af0bab0

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +185 -0
README.md ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ <div align="center">
4
+ <h1 align="center"> 👉 LightThinker 👈 </h1>
5
+ <b>LightThinker: Thinking Step-by-Step Compression</b>
6
+
7
+ [![Awesome](https://awesome.re/badge.svg)](https://github.com/zjunlp/LightThinker)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
9
+ ![](https://img.shields.io/github/last-commit/zjunlp/LightThinker?color=green)
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/zjunlp/lightthinker">Github</a> •
13
+ <a href="https://arxiv.org/abs/2502.15589">📄arXiv</a> •
14
+ <a href="https://x.com/zxlzr/status/1894729164609208338">𝕏 Blog</a>
15
+ </p>
16
+
17
+ </div>
18
+
19
+ ## Table of Contents
20
+
21
+ - 👀[Overview](#overview)
22
+ - 🔧[Installation](#installation)
23
+ - 🏃[Quick Start](#quick-start)
24
+ - 🎁[Acknowledgement](#acknowledgement)
25
+ - 🚩[Citation](#citation)
26
+
27
+ ## 👀Overview
28
+
29
+ LLMs have shown remarkable performance in complex reasoning tasks, but their efficiency is hindered by the substantial memory and computational costs associated with generating lengthy tokens. In this paper, we propose LightThinker, a novel method that enables LLMs to dynamically compress intermediate thoughts during reasoning. Inspired by human cognitive processes, LightThinker compresses verbose thought steps into compact representations and discards the original reasoning chains, thereby significantly reducing the number of tokens stored in the context window. This is achieved by training the model on when and how to perform compression through data construction, mapping hidden states to condensed gist tokens, and creating specialized attention masks.
30
+
31
+
32
+ ## 🔧Installation
33
+
34
+ ```bash
35
+ git clone https://github.com/zjunlp/LightThinker
36
+ cd LightThinker
37
+ conda create -n lightthinker python=3.9 -y
38
+ conda activate lightthinker
39
+ pip install -r requirements.txt
40
+ cd data && unzip data.zip && cd ..
41
+ ```
42
+
43
+
44
+ ## 🏃Quick Start
45
+
46
+ > First, we train the model to learn how to compress (step 1). Then, we perform inference on the test set to obtain output results (step 2). Finally, we evaluate the output results (step 3).
47
+
48
+ ### Step 1. Training
49
+
50
+ To execute the training, run the following command:
51
+
52
+ ```bash
53
+ bash train.sh
54
+ ```
55
+
56
+ Currently, the script's parameters are set to run on a machine with 4 A800 GPUs. If you encounter OOM (Out Of Memory) issues, please reduce the `micro_batch_size` and `max_length`. For other parameters in the script, please refer to the [documentation](./ARGS.md).
57
+
58
+ ### Step 2. Inference
59
+
60
+ To execute the inference, run the following command:
61
+
62
+ ```bash
63
+ bash inference.sh
64
+ ```
65
+
66
+ Here, you need to modify the script file's `model_tag`, `model_short_tag`, `ckpt`, `output_tag`, and `split_size`. For details regarding the script's parameters, please refer to the [documentation](./ARGS.md).
67
+
68
+
69
+ ### Step 3. Evaluation
70
+
71
+ > [!NOTE]
72
+ > If this is your **first time** conducting an evaluation, please execute the following code first:
73
+ ```bash
74
+ python evaluation/init.py
75
+ ```
76
+
77
+ To execute the evaluation, run the following command:
78
+
79
+ ```bash
80
+ method=""
81
+ tokenizer_path=""
82
+ comp_config=""
83
+ model_type=""
84
+ dataset=""
85
+ bos_token=""
86
+ eos_token=""
87
+ cache_size=1024
88
+ file1=""
89
+ file2=""
90
+ file3=""
91
+ file4=""
92
+ python evaluation/eval_file.py \
93
+ --method $method \
94
+ --tokenizer_path $tokenizer_path \
95
+ --comp_config $comp_config \
96
+ --model_type $model_type \
97
+ --dataset $dataset \
98
+ --files $file1 $file2 $file3 $file4 \
99
+ --cache_size $cache_size \
100
+ --bos_token $bos_token \
101
+ --eos_token $eos_token \
102
+ --interaction
103
+ ```
104
+
105
+ Please note that if you set `split_size>1` in the second step, the number of file i here should match the value of `split_size`. It should be noted that manual evaluation was conducted during the assessment. Use the `--interaction` flag to enable manual evaluation. The `cache_size` parameter is used for `H2O` and `SepLLM`, but not for `LightThinker` or `AnLLM`.
106
+
107
+ <details>
108
+ <summary><b>Evaluation Script Example</b></summary>
109
+
110
+ ```bash
111
+ # The optional values for the method argument are 'anchor-token', 'normal', 'kvcache', and 'anchor-thought'.
112
+ method="anchor-thought"
113
+ tokenizer_path="Qwen/Qwen2.5-7B-Instruct"
114
+ comp_config="configs/LightThinker/qwen/v1.json"
115
+ model_type="qwen"
116
+ dataset="gpqa"
117
+ bos_token="<|im_start|>"
118
+ eos_token="<|im_end|>"
119
+ cache_size=1024
120
+ folder=""
121
+ ckpt=1045
122
+ file1="inference_results/${folder}/${dataset}/${ckpt}/1-4qwen_7b.jsonl"
123
+ file2="inference_results/${folder}/${dataset}/${ckpt}/2-4qwen_7b.jsonl"
124
+ file3="inference_results/${folder}/${dataset}/${ckpt}/3-4qwen_7b.jsonl"
125
+ file4="inference_results/${folder}/${dataset}/${ckpt}/4-4qwen_7b.jsonl"
126
+ python evaluation/eval_file.py \
127
+ --method $method \
128
+ --tokenizer_path $tokenizer_path \
129
+ --comp_config $comp_config \
130
+ --model_type $model_type \
131
+ --dataset $dataset \
132
+ --files $file1 $file2 $file3 $file4 \
133
+ --cache_size $cache_size \
134
+ --bos_token $bos_token \
135
+ --eos_token $eos_token \
136
+ --interaction
137
+ ```
138
+ </details>
139
+
140
+ <details>
141
+ <summary><b>Manual Evaluation Instructions</b></summary>
142
+
143
+ When string matching fails, the output will be displayed in the format "Model Answer" <=> "Standard Answer". At this point, you can input "y" or "n" to evaluate this case. If you believe the model's answer extraction is incorrect, you can input "e" to print the model's complete output, and then input "y" or "n" to evaluate this case.
144
+ </details>
145
+
146
+
147
+
148
+ ## 🎁Acknowledgement
149
+
150
+ Our training dataset is derived from [Bespoke-Stratos-17k](https://huggingface.co/datasets/bespokelabs/Bespoke-Stratos-17k). We utilized the baseline code for H2O from the [Meta-llama](https://github.com/meta-llama/llama-cookbook)'s repository, the baseline code for SepLLM from the [HKUDS](https://github.com/HKUDS/SepLLM)'s repository. We extend our gratitude to the contributors for their outstanding work!
151
+
152
+
153
+ ## 🚩Citation
154
+
155
+ If this work is helpful, please kindly cite as:
156
+
157
+ ```bibtex
158
+ @article{DBLP:journals/corr/abs-2502-15589,
159
+ author = {Jintian Zhang and
160
+ Yuqi Zhu and
161
+ Mengshu Sun and
162
+ Yujie Luo and
163
+ Shuofei Qiao and
164
+ Lun Du and
165
+ Da Zheng and
166
+ Huajun Chen and
167
+ Ningyu Zhang},
168
+ title = {LightThinker: Thinking Step-by-Step Compression},
169
+ journal = {CoRR},
170
+ volume = {abs/2502.15589},
171
+ year = {2025},
172
+ url = {https://doi.org/10.48550/arXiv.2502.15589},
173
+ doi = {10.48550/ARXIV.2502.15589},
174
+ eprinttype = {arXiv},
175
+ eprint = {2502.15589},
176
+ timestamp = {Thu, 20 Mar 2025 13:28:42 +0100},
177
+ biburl = {https://dblp.org/rec/journals/corr/abs-2502-15589.bib},
178
+ bibsource = {dblp computer science bibliography, https://dblp.org}
179
+ }
180
+ ```
181
+
182
+
183
+
184
+
185
+