Papers › Discovering the Gems in Early Layers: Accelerating Long-Context LLMs with 1000x Input...

Discovering the Gems in Early Layers: Accelerating Long-Context LLMs with 1000x Input Token Reduction

25 Sep 2024arXiv:2409.17422archive 2025-07-28

Zhenmei Shi, Yifei Ming, Xuan-Phi Nguyen, YIngyu Liang, Shafiq Joty

Large Language Models (LLMs) have demonstrated remarkable capabilities in handling long context inputs, but this comes at the cost of increased computational resources and latency. Our research introduces a novel approach for the long context bottleneck to accelerate LLM inference and reduce GPU memory consumption. Our research demonstrates that LLMs can identify relevant tokens in the early layers before generating answers to a query. Leveraging this insight, we propose an algorithm that uses early layers of an LLM as filters to select and compress input tokens, significantly reducing the context length for subsequent processing. Our method, GemFilter, demonstrates substantial improvements in both speed and memory efficiency compared to existing techniques, such as standard attention and SnapKV/H2O. Notably, it achieves a 2.4× speedup and 30\% reduction in GPU memory usage compared to SOTA methods. Evaluation on the Needle in a Haystack task shows that GemFilter significantly outperforms standard attention, SnapKV and demonstrates comparable performance on the LongBench challenge. GemFilter is simple, training-free, and broadly applicable across different LLMs. Crucially, it provides interpretability by allowing humans to inspect the selected input sequence. These findings not only offer practical benefits for LLM deployment, but also enhance our understanding of LLM internal mechanisms, paving the way for further optimizations in LLM design and inference. Our code is available at \url{https://github.com/SalesforceAIResearch/GemFilter}.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2409.17422")

Code

Syntology Ran 13 of 13 code samples harvested from 1 repository linked to this paper; 0 have no recorded run. Of those that ran: 1 ran · honoured contract; 1 ran · violated contract; 2 ran · our draft was wrong; 9 ran with no contract checked.

By repository: official repository: 13 samples from 1 repository, 13 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

salesforceairesearch/gemfilter officialmentioned in papermentioned on GitHubpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

13 samples harvested; 13 ran; 1 honoured the contract we drafted; 0 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · honoured contract
1ran · violated contract
2ran · our draft was wrong
9ran

Licence: 0 of the 13 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from salesforceairesearch/gemfilter. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

build_chat salesforceairesearch/gemfilter/eval/LongBench/pred.py official repository ran Apache-2.0 (permissive) · 8339145374a403f3 · report
count_score salesforceairesearch/gemfilter/eval/LongBench/metrics.py official repository ran · honoured contract fingerprinted Apache-2.0 (permissive) · b349b79d9cc2934b · report
get_layer_context salesforceairesearch/gemfilter/my_utils/my_generation.py official repository ran Apache-2.0 (permissive) · 8023b20549593b60 · report
insert_needle salesforceairesearch/gemfilter/eval/needle/utils.py official repository ran Apache-2.0 (permissive) · ce3c4802be48b9d2 · report
load_context salesforceairesearch/gemfilter/eval/needle/utils.py official repository ran Apache-2.0 (permissive) · 6af3fc7115dbdfad · report
my_forward salesforceairesearch/gemfilter/my_utils/load_model.py official repository ran Apache-2.0 (permissive) · 74f9afa035c0616b · report
normalize_answer salesforceairesearch/gemfilter/eval/LongBench/metrics.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · e7e75981cb464788 · report
normalize_zh_answer salesforceairesearch/gemfilter/eval/LongBench/metrics.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · 8c5c581f9264c810 · report
parse_args salesforceairesearch/gemfilter/eval/LongBench/pred.py official repository ran Apache-2.0 (permissive) · 7e76d6613e17885d · report
post_process salesforceairesearch/gemfilter/eval/LongBench/pred.py official repository ran · violated contract fingerprinted Apache-2.0 (permissive) · 4489113b536ca6eb · report
recover_layer salesforceairesearch/gemfilter/my_utils/my_generation.py official repository ran Apache-2.0 (permissive) · 7492f636f610e78b · report
reduce_layer salesforceairesearch/gemfilter/my_utils/my_generation.py official repository ran Apache-2.0 (permissive) · 9fbfc530cceb902f · report
standard_dis_index salesforceairesearch/gemfilter/my_baseline/GemFilter/gem_filter_utils.py official repository ran Apache-2.0 (permissive) · 1d164ab515de6ff5 · report

Tasks

Token Reduction

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AttentionSPEEDSoftmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections