DEV Community

Cover image for Unleashing the Power of LLMLingua: Prompt Compression Performance Testing
Shannon Lal
Shannon Lal

Posted on

Unleashing the Power of LLMLingua: Prompt Compression Performance Testing

Prompt compression has emerged as a powerful technique in the realm of large language models (LLMs) to optimize performance and reduce computational costs. LLMLingua (https://llmlingua.com/llmlingua2.html), a state-of-the-art prompt compression method, employs various techniques such as context filtering, sentence filtering, and token-level filtering to achieve high compression ratios while preserving semantic information. By reducing the number of tokens in a prompt, prompt compression significantly decreases the computational resources required for inference, making LLMs more accessible and cost-effective. As an AI developer working on integrating different LLMs, I wanted to explore the performance impact of adding prompt compression to my workflow and see if it could help reduce costs and speed up LLM processing times.

To evaluate the impact of prompt compression on LLM processing times and costs, I conducted experiments using LLMLingua on prompts of three different sizes: small (1-2k tokens), medium (4k tokens), and large (58k tokens). I applied various compression techniques, including context filtering, sentence filtering, token-level filtering, and a combination of all three, to assess their performance in terms of execution time and compression ratio. I ran these expirements using an NVIDIA L4 GPU with 24 GB of RAM. I used LLAMA 7B model for Token Level Filtering. The following is a summary of my tests:

Compression Technique Tokens Execution Time Original Tokens Compressed Tokens Compression Ratio Tokens Compressed/Seconds
Context Filtering Small 0.946 1395 692 2.36 743.1289641
Sentence Filtering Small 3.45 1395 636 2.3 220
Token Level Small 1.725 1395 421 3.27 564.6376812
All Small 3.043 1395 474 3.08 302.6618469
Context Filtering Medium 2.869 4146 1087 4.15 1066.225166
Sentence Filtering Medium 10.623 4146 1206 3.62 276.757978
Token Level Medium 6.02 4146 854 5.9 546.8438538
All Medium 6.701 4146 918 4.71 481.7191464
Context Filtering Large 21.358 58990 27937 2.11 1453.92827
Sentence Filtering Large 48.514 58990 11087 5.32 987.4056973
Token Level Large 57.653 58990 1224 48.19 1001.960002
All Large 70.258 58990 7570 7.79 731.8739503

The experiments conducted with LLMLingua provide valuable insights into the impact of prompt compression on LLM processing times and costs. The results demonstrate that prompt compression can quickly reduce the overall prompt size quickly which will result in faster LLM process and overall cost savings. Token-level filtering achieved the highest compression ratios, especially for large prompts, while context filtering emerged as the fastest technique, significantly reducing execution time while maintaining a reasonable compression ratio. However, it is crucial to consider the specific requirements of the application and strike a balance between compression ratio and execution time when selecting the appropriate compression technique. These findings serve as a foundation for further optimization and innovation in the field of prompt compression, paving the way for more accessible, efficient, and cost-effective LLM applications.

Top comments (0)