{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/hierarchical-context-merging-better-long","title":"Hierarchical Context Merging: Better Long Context Understanding for Pre-trained LLMs","arxiv_id":"2404.10308","date":"2024-04-16","proceeding":null,"authors":["Woomin Song","Seunghyuk Oh","Sangwoo Mo","Jaehyung Kim","Sukmin Yun","Jung-Woo Ha","Jinwoo Shin"],"abstract":"Large language models (LLMs) have shown remarkable performance in various natural language processing tasks. However, a primary constraint they face is the context limit, i.e., the maximum number of tokens they can process. Previous works have explored architectural changes and modifications in positional encoding to relax the constraint, but they often require expensive training or do not address the computational demands of self-attention. In this paper, we present Hierarchical cOntext MERging (HOMER), a new training-free scheme designed to overcome the limitations. HOMER uses a divide-and-conquer algorithm, dividing long inputs into manageable chunks. Each chunk is then processed collectively, employing a hierarchical strategy that merges adjacent chunks at progressive transformer layers. A token reduction technique precedes each merging, ensuring memory usage efficiency. We also propose an optimized computational order reducing the memory requirement to logarithmically scale with respect to input length, making it especially favorable for environments with tight memory restrictions. Our experiments demonstrate the proposed method's superior performance and memory efficiency, enabling the broader use of LLMs in contexts requiring extended context. Code is available at https://github.com/alinlab/HOMER.","url_abs":"https://arxiv.org/abs/2404.10308v1","url_pdf":"https://arxiv.org/pdf/2404.10308v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"hierarchical-context-merging-better-long","repo_url":"https://github.com/alinlab/homer","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"long-context-understanding","task_name":"Long-Context Understanding"},{"task_slug":"token-reduction","task_name":"Token Reduction"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2404.10308","atlas_url":"https://app.syntology.ai/?focus=2404.10308","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2404.10308"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/alinlab/HOMER","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/alinlab/homer","reach":{"status":"ok"}}],"summary":{"ran_fixture":1,"ran":7,"ran_draft_wrong":4,"unverified":3},"by_repo_kind":{"official":{"samples":15,"ran":12,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"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"},"n_pointer_only_for_licence":15,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/modeling_llama.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/modeling_llama.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30d7eec482ebf6b1"}},{"code_sha256_prefix":"3c5613c7d1dccdba","entry":"Chunk","repo":"alinlab/homer","repo_kind":"official","path":"src/homer/patch_llama.py","file_url":"https://github.com/alinlab/homer/blob/HEAD/src/homer/patch_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3c5613c7d1dccdba"}},{"code_sha256_prefix":"bac65c3dafaec040","entry":"apply_rotary_pos_emb","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/modeling_llama.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/modeling_llama.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bac65c3dafaec040"}},{"code_sha256_prefix":"3c92c963bb0cbb73","entry":"find_correction_dim","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/embedding.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/embedding.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3c92c963bb0cbb73"}},{"code_sha256_prefix":"763ecb554c17d2fe","entry":"find_correction_range","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/embedding.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/embedding.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"763ecb554c17d2fe"}},{"code_sha256_prefix":"a38e3baabc117a17","entry":"gather_logits","repo":"alinlab/homer","repo_kind":"official","path":"src/perplexity.py","file_url":"https://github.com/alinlab/homer/blob/HEAD/src/perplexity.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a38e3baabc117a17"}},{"code_sha256_prefix":"fb2e60e07eb16197","entry":"generate_plain","repo":"alinlab/HOMER","repo_kind":"official","path":"src/passkey.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/passkey.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"fb2e60e07eb16197"}},{"code_sha256_prefix":"fe1fb261101f64ef","entry":"get_accumulated_perplexity","repo":"alinlab/homer","repo_kind":"official","path":"src/perplexity.py","file_url":"https://github.com/alinlab/homer/blob/HEAD/src/perplexity.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"fe1fb261101f64ef"}},{"code_sha256_prefix":"5034871c1d2783cf","entry":"linear_ramp_mask","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/embedding.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/embedding.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5034871c1d2783cf"}},{"code_sha256_prefix":"9f58f79f8bcad64f","entry":"llamadecoderlayer_forward","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/patch_llama.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/patch_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9f58f79f8bcad64f"}},{"code_sha256_prefix":"924e90912400c67d","entry":"parse_answer","repo":"alinlab/HOMER","repo_kind":"official","path":"src/passkey.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/passkey.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"924e90912400c67d"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/modeling_llama.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/modeling_llama.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"c827204815a2ce17","entry":"_merge","repo":"alinlab/homer","repo_kind":"official","path":"src/homer/patch_llama.py","file_url":"https://github.com/alinlab/homer/blob/HEAD/src/homer/patch_llama.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c827204815a2ce17"}},{"code_sha256_prefix":"42dbbee90fbe5feb","entry":"create_homer_prefix","repo":"alinlab/HOMER","repo_kind":"official","path":"src/homer/patch_llama.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/homer/patch_llama.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"42dbbee90fbe5feb"}},{"code_sha256_prefix":"f102f8067bf8111b","entry":"generate_homer","repo":"alinlab/HOMER","repo_kind":"official","path":"src/passkey.py","file_url":"https://github.com/alinlab/HOMER/blob/HEAD/src/passkey.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f102f8067bf8111b"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}