microsoft / microsoft/LLMLingua
[Bug]: Achieved compression rate with (Long)LLMLingua overshot
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 428
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 1
Description
I was evaluating how well the (Long)LLMLingua is able to achieve the requested compression rate (focusing on the rate parameter, not target_tokens) and came to these conclusions:
- For smaller prompts (< 150 tokens) barely any compression can be achieved, if any at all
- Requested compression rate is best achieved for prompts around 2000 tokens
- For longer prompts (>5000 tokens) the requested rate is overshot (or undershot)
More detailed results are below.
My question is, am doing something wrong when invoking LLMLingua, or is this behaviour normal?
I adhered to the usage examples in README.md:
Code snippet
compressor = PromptCompressor(
model_name="NousResearch/Llama-2-7b-hf", # or "openai-community/gpt2"
device_map="balanced"
)
...
def compress(prompt, rate, question=""):
if longllmlingua:
res = compressor.compress_prompt(
[prompt],
question=question,
rate=rate,
condition_in_question="after_condition",
reorder_context="sort",
dynamic_context_compression_ratio=0.3,
condition_compare=True,
rank_method="longllmlingua",
)
else:
res = compressor.compress_prompt(prompt, rate=rate)
return res
I tested with the default Llama 2 7b as well as with GPT-2. It seems that with the smaller model the deviation overall is smaller than with the bigger model.
(Prompt lengths measured using the GPT-3.5 tokenizer)
LLMLingua with Llama 2
LLMLingua with GPT-2
LongLLMLingua with Llama 2
LongLLMLingua with GPT-2
In contrast, LLMLingua-2 adheres to the requested compression rate quite well, only slightly overshooting the requested rate:
LLMLingua-2
The prompts I used are truncated from the longest prompt in the LongBench GovReport task (link).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue body's compress_prompt calls with the listed Llama 2 and GPT-2 models, varying prompt length and the rate parameter. Compare requested and achieved compression rates, then determine whether the deviations are expected behavior or indicate a correction; the issue is resolved when this is documented or addressed with evidence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- huggingface, python
- Domain
- machine-learning, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100