MikeDean commited on
Commit
d6f33d2
·
verified ·
1 Parent(s): b1e4457

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +191 -0
README.md ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 when to compress and 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
+ <details>
61
+ <summary><b>Inference with a downloaded model</b></summary>
62
+
63
+ If you are downloading a trained model from Huggingface, please set the `model_path` parameter in `inference.sh` to the absolute path of the model. The values of other parameters `ckpt` and `model_tag` will be ignored.
64
+ </details>
65
+
66
+ To execute the inference, run the following command:
67
+
68
+ ```bash
69
+ bash inference.sh
70
+ ```
71
+
72
+ 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).
73
+
74
+
75
+ ### Step 3. Evaluation
76
+
77
+ > [!NOTE]
78
+ > If this is your **first time** conducting an evaluation, please execute the following code first:
79
+ ```bash
80
+ python evaluation/init.py
81
+ ```
82
+
83
+ To execute the evaluation, run the following command:
84
+
85
+ ```bash
86
+ method=""
87
+ tokenizer_path=""
88
+ comp_config=""
89
+ model_type=""
90
+ dataset=""
91
+ bos_token=""
92
+ eos_token=""
93
+ cache_size=1024
94
+ file1=""
95
+ file2=""
96
+ file3=""
97
+ file4=""
98
+ python evaluation/eval_file.py \
99
+ --method $method \
100
+ --tokenizer_path $tokenizer_path \
101
+ --comp_config $comp_config \
102
+ --model_type $model_type \
103
+ --dataset $dataset \
104
+ --files $file1 $file2 $file3 $file4 \
105
+ --cache_size $cache_size \
106
+ --bos_token $bos_token \
107
+ --eos_token $eos_token \
108
+ --interaction
109
+ ```
110
+
111
+ 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`.
112
+
113
+ <details>
114
+ <summary><b>Evaluation Script Example</b></summary>
115
+
116
+ ```bash
117
+ # The optional values for the method argument are 'anchor-token', 'normal', 'kvcache', and 'anchor-thought'.
118
+ method="anchor-thought"
119
+ tokenizer_path="Qwen/Qwen2.5-7B-Instruct"
120
+ comp_config="configs/LightThinker/qwen/v1.json"
121
+ model_type="qwen"
122
+ dataset="gpqa"
123
+ bos_token="<|im_start|>"
124
+ eos_token="<|im_end|>"
125
+ cache_size=1024
126
+ folder=""
127
+ ckpt=1045
128
+ file1="inference_results/${folder}/${dataset}/${ckpt}/1-4qwen_7b.jsonl"
129
+ file2="inference_results/${folder}/${dataset}/${ckpt}/2-4qwen_7b.jsonl"
130
+ file3="inference_results/${folder}/${dataset}/${ckpt}/3-4qwen_7b.jsonl"
131
+ file4="inference_results/${folder}/${dataset}/${ckpt}/4-4qwen_7b.jsonl"
132
+ python evaluation/eval_file.py \
133
+ --method $method \
134
+ --tokenizer_path $tokenizer_path \
135
+ --comp_config $comp_config \
136
+ --model_type $model_type \
137
+ --dataset $dataset \
138
+ --files $file1 $file2 $file3 $file4 \
139
+ --cache_size $cache_size \
140
+ --bos_token $bos_token \
141
+ --eos_token $eos_token \
142
+ --interaction
143
+ ```
144
+ </details>
145
+
146
+ <details>
147
+ <summary><b>Manual Evaluation Instructions</b></summary>
148
+
149
+ 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.
150
+ </details>
151
+
152
+
153
+
154
+ ## 🎁Acknowledgement
155
+
156
+ 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!
157
+
158
+
159
+ ## 🚩Citation
160
+
161
+ If this work is helpful, please kindly cite as:
162
+
163
+ ```bibtex
164
+ @article{DBLP:journals/corr/abs-2502-15589,
165
+ author = {Jintian Zhang and
166
+ Yuqi Zhu and
167
+ Mengshu Sun and
168
+ Yujie Luo and
169
+ Shuofei Qiao and
170
+ Lun Du and
171
+ Da Zheng and
172
+ Huajun Chen and
173
+ Ningyu Zhang},
174
+ title = {LightThinker: Thinking Step-by-Step Compression},
175
+ journal = {CoRR},
176
+ volume = {abs/2502.15589},
177
+ year = {2025},
178
+ url = {https://doi.org/10.48550/arXiv.2502.15589},
179
+ doi = {10.48550/ARXIV.2502.15589},
180
+ eprinttype = {arXiv},
181
+ eprint = {2502.15589},
182
+ timestamp = {Thu, 20 Mar 2025 13:28:42 +0100},
183
+ biburl = {https://dblp.org/rec/journals/corr/abs-2502-15589.bib},
184
+ bibsource = {dblp computer science bibliography, https://dblp.org}
185
+ }
186
+ ```
187
+
188
+
189
+
190
+
191
+