{"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/memlong-memory-augmented-retrieval-for-long","title":"MemLong: Memory-Augmented Retrieval for Long Text Modeling","arxiv_id":"2408.16967","date":"2024-08-30","proceeding":null,"authors":["Weijie Liu","Zecheng Tang","Juntao Li","Kehai Chen","Min Zhang"],"abstract":"Recent advancements in Large Language Models (LLMs) have yielded remarkable success across diverse fields. However, handling long contexts remains a significant challenge for LLMs due to the quadratic time and space complexity of attention mechanisms and the growing memory consumption of the key-value cache during generation. This work introduces MemLong: Memory-Augmented Retrieval for Long Text Generation, a method designed to enhance the capabilities of long-context language modeling by utilizing an external retriever for historical information retrieval. MemLong combines a non-differentiable ``ret-mem'' module with a partially trainable decoder-only language model and introduces a fine-grained, controllable retrieval attention mechanism that leverages semantic-level relevant chunks. Comprehensive evaluations on multiple long-context language modeling benchmarks demonstrate that MemLong consistently outperforms other state-of-the-art LLMs. More importantly, MemLong can extend the context length on a single 3090 GPU from 4k up to 80k. Our code is available at https://github.com/Bui1dMySea/MemLong","url_abs":"https://arxiv.org/abs/2408.16967v1","url_pdf":"https://arxiv.org/pdf/2408.16967v1.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":"memlong-memory-augmented-retrieval-for-long","repo_url":"https://github.com/bui1dmysea/memlong","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"4k","task_name":"4k"},{"task_slug":"decoder","task_name":"Decoder"},{"task_slug":null,"task_name":"GPU"},{"task_slug":"information-retrieval","task_name":"Information Retrieval"},{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"text-generation","task_name":"Text Generation"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2408.16967","atlas_url":"https://app.syntology.ai/?focus=2408.16967","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2408.16967"}},"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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/bui1dmysea/memlong","reach":{"status":"ok"}}],"summary":{"ran_fixture":1,"ran_draft_wrong":2,"ran":2,"unverified":2},"by_repo_kind":{"official":{"samples":7,"ran":5,"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":7,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/icl/MemLong/modeling_llama.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/icl/MemLong/modeling_llama.py","link_basis":"harvester_set","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":"bac65c3dafaec040","entry":"apply_rotary_pos_emb","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/icl/MemLong/modeling_llama.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/icl/MemLong/modeling_llama.py","link_basis":"harvester_set","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":"65bc466999b923d6","entry":"group_texts","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/language_modeling/MemLong/utils.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/language_modeling/MemLong/utils.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":"65bc466999b923d6"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/icl/MemLong/modeling_llama.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/icl/MemLong/modeling_llama.py","link_basis":"harvester_set","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":"c78930a2d9e9be54","entry":"tokenize_fn","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/language_modeling/MemLong/utils.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/language_modeling/MemLong/utils.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":"c78930a2d9e9be54"}},{"code_sha256_prefix":"7ce77847b8f6ae5c","entry":"apply_rotary_pos_emb_for_relative_query","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/icl/MemLong/modeling_llama_position.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/icl/MemLong/modeling_llama_position.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":"7ce77847b8f6ae5c"}},{"code_sha256_prefix":"187d8d92b86625bd","entry":"convert_to_lora","repo":"bui1dmysea/memlong","repo_kind":"official","path":"eval/language_modeling/MemLong/utils.py","file_url":"https://github.com/bui1dmysea/memlong/blob/HEAD/eval/language_modeling/MemLong/utils.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":"187d8d92b86625bd"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}