Home

Awesome

Compression Represents Intelligence Linearly

<p align="left"> πŸ€— <a href="https://huggingface.co/datasets/hkust-nlp/llm-compression" target="_blank">HuggingFace Datasets</a> β€’ πŸ“ƒ <a href="https://arxiv.org/abs/2404.09937" target="_blank">Paper</a> </p>

This is the repository for the paper "Compression Represents Intelligence Linearly".

We find that LLMs’ intelligence – reflected by benchmark scores – almost linearly correlates with their ability to compress external text corpora. Our findings suggest that compression efficiency, as an unsupervised metric derived from raw text corpora, serves as a reliable evaluation measure that is linearly associated with the model capabilities. In this repo, we release the compression corpora we used in the paper, the code to compute compression efficiency, as well as our compression corpora collection and processing piplines. <img src="resources/overview.png" alt="overview" style="zoom: 5%;" />

News

Table of Contents

Compression Leaderboard

We focus on three key abilities: knowledge and commonsense, coding, and mathematical reasoning and colloct new corpora from Common Crawl, GitHub, and Arxiv, respectively. Below are models’ compression efficiency on three external corpora. We report the average bits per character (BPC) as the metric. For more details, please refer to our paper.

ModelCommon CrawlPythonArxiv-MathAverage
Llama-3-70b0.4960.2040.3760.359
Mixtral-8x22B-v0.10.5260.2500.3610.379
Qwen2-72B0.5500.2070.3900.383
Qwen1.5-110B0.5310.2240.4100.388
DeepSeek-V20.5290.2430.4000.391
Mixtral-8x7B0.5590.2740.3940.409
Qwen-72b0.5570.2560.4150.409
Qwen-1.5-72b0.5600.2560.4170.411
Llama-2-70b0.5270.2870.4290.415
Qwen-1.5-32b0.5910.2570.4070.418
Deepseek-llm-67b0.5680.2800.4300.426
Llama-3-8b0.5820.2680.4300.427
Yi-34b0.5720.2970.4210.430
Llama-1-65b0.5570.3080.4410.435
Qwen-1.5-14b0.6460.2750.4300.450
Qwen-14b0.6200.2850.4500.451
Llama-1-30b0.5770.3210.4560.452
Mistral-7b0.6050.3100.4430.453
Llama-2-13b0.5810.3340.4750.463
Falcon-40b0.5930.3200.4820.465
Qwen-1.5-7b0.6660.2920.4490.469
Qwen-7b0.6450.3090.4830.479
Llama-1-13b0.6090.3560.4870.484
Llama-2-7b0.6120.3540.5000.488
Yi-6b0.6380.3510.4830.491
Deepseek-llm-7b0.6350.3380.5000.491
Llama-1-7b0.6290.3790.5100.506
Falcon-7b0.6490.3930.5410.528

Compression Corpora Datasets

We focus on three key abilities: knowledge and commonsense, coding, and mathematical reasoning. The corpora we used are sourced from Common Crawl, GitHub, and Arxiv, and are respectively named: cc, python, and arxiv_math respectively. The data can be obtained through Huggingface Datasets:

from datasets import load_dataset
dataset = load_dataset(r"hkust-nlp/llm-compression",name="python")
print(dataset['test'][0])

Below is our data structure, containing three fields: content, subset, meta. Specifically, "content" refers to the evaluation text data, and "meta" contains data-specific meta-information related to its subset.

"content": "A photo journal about returning...", 
"subset": "cc" | "python" | "arxiv_math", 
"meta": {}

Evaluating Compression

We utilize Bits Per Character (BPC) as the evaluation metric, implementing both Context Window Unification and a sliding window approach for assessing compression performance. The Python code for this evaluation is accessible in the code/evaluation directory and necessitates the specified basic environment:

transformers
datasets
tqdm

After installing the necessary dependencies, execute the evaluation script code/evaluation/main.py with these optional arguments:

--task_name # specifies the subset to eval (cc|python|arxiv_math)
--model_name # specifies the model name
--block_size # specifies the context window
--stride   # specifies the stride of sliding window approach
--batch_size # specifies the batch size
--file_num  # specifies the number of examples to eval, useful for debugging
--flash      # enable this to use flash attention (requires the flash-attn package)
--gpu        # specifies the id of gpu
--cache_dir  # specifies the cache dir for huggingface

Example:

cd code/evlauation
python -u main.py\
    --model_name deepseek-ai/deepseek-llm-7b-base\
    --task_name cc\
    --block_size 1900\
    --stride 512\
    --batch_size 8\
    --flash

Use Through OpenCompass

Now, you can evaluate model on llm-compression through OpenCompass, which is a framework for LLM evaluation. The dataset name is llm_compression. For example, to evaluate a model hosted on the HuggingFace Hub (e.g. llama-7b) ,you can use the following command:

python run.py --datasets llm_compression --hf-path huggyllama/llama-7b --model-kwargs use_flash_attention_2=True  

Please refer to OpenCompass for more details.

Data Pipeline

We provide data collection pipelines to facilitate future data updates and research, which include:

For details, please refer to the corresponding pages.

Licenses

MIT license

This work is licensed under a MIT License.

CC BY-NC-SA 4.0

Our dataset is primarily licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. When the data source mandates a stricter licensing agreement, we comply with those terms.

Citation

@inproceedings{
   huang2024compression,
   title={Compression Represents Intelligence Linearly},
   author={Yuzhen Huang and Jinghan Zhang and Zifei Shan and Junxian He},
   booktitle={First Conference on Language Modeling},
   year={2024},
   url={https://openreview.net/forum?id=SHMj84U5SH}
}