{"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/never-miss-a-beat-an-efficient-recipe-for","title":"An Efficient Recipe for Long Context Extension via Middle-Focused Positional Encoding","arxiv_id":"2406.07138","date":"2024-06-11","proceeding":null,"authors":["Tong Wu","Yanpeng Zhao","Zilong Zheng"],"abstract":"Recently, many methods have been developed to extend the context length of pre-trained large language models (LLMs), but they often require fine-tuning at the target length ($\\gg4K$) and struggle to effectively utilize information from the middle part of the context. To address these issues, we propose $\\textbf{C}$ontinuity-$\\textbf{R}$elativity ind$\\textbf{E}$xing with g$\\textbf{A}$ussian $\\textbf{M}$iddle ($\\texttt{CREAM}$), which interpolates positional encodings by manipulating position indices. Apart from being simple, $\\texttt{CREAM}$ is training-efficient: it only requires fine-tuning at the pre-trained context window (e.g., Llama 2-4K) and can extend LLMs to a much longer target context length (e.g., 256K). To ensure that the model focuses more on the information in the middle, we introduce a truncated Gaussian to encourage sampling from the middle part of the context during fine-tuning, thus alleviating the \"Lost-in-the-Middle\" problem faced by long-context LLMs. Experimental results show that $\\texttt{CREAM}$ successfully extends LLMs to the target length for both Base and Chat versions of $\\texttt{Llama2-7B}$ with \"Never Miss A Beat\". Our code is publicly available at https://github.com/bigai-nlco/cream.","url_abs":"https://arxiv.org/abs/2406.07138v2","url_pdf":"https://arxiv.org/pdf/2406.07138v2.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":"never-miss-a-beat-an-efficient-recipe-for","repo_url":"https://github.com/bigai-nlco/cream","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":null}],"tasks":[{"task_slug":"4k","task_name":"4k"}],"methods":[{"method_slug":"base","method_name":"BASE"},{"method_slug":"llama","method_name":"LLaMA"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2406.07138","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.07138"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+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/bigai-nlco/cream","reach":null}],"summary":{"ran":1,"ran_honours":4},"by_repo_kind":{"official":{"samples":5,"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":5,"samples":[{"code_sha256_prefix":"b6c738c248f2c092","entry":"LlamaYaRNScaledRotaryEmbedding","repo":"bigai-nlco/cream","repo_kind":"official","path":"src/my_flash_modeling_llama.py","file_url":"https://github.com/bigai-nlco/cream/blob/HEAD/src/my_flash_modeling_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b6c738c248f2c092"}},{"code_sha256_prefix":"55979cfafb52e292","entry":"_yarn_find_correction_dim","repo":"bigai-nlco/cream","repo_kind":"official","path":"src/my_flash_modeling_llama.py","file_url":"https://github.com/bigai-nlco/cream/blob/HEAD/src/my_flash_modeling_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"55979cfafb52e292"}},{"code_sha256_prefix":"865433623de706f3","entry":"_yarn_find_correction_range","repo":"bigai-nlco/cream","repo_kind":"official","path":"src/my_flash_modeling_llama.py","file_url":"https://github.com/bigai-nlco/cream/blob/HEAD/src/my_flash_modeling_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"865433623de706f3"}},{"code_sha256_prefix":"73912c53aaa16b02","entry":"_yarn_get_mscale","repo":"bigai-nlco/cream","repo_kind":"official","path":"src/my_flash_modeling_llama.py","file_url":"https://github.com/bigai-nlco/cream/blob/HEAD/src/my_flash_modeling_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"73912c53aaa16b02"}},{"code_sha256_prefix":"5c2707e010f48e5d","entry":"_yarn_linear_ramp_mask","repo":"bigai-nlco/cream","repo_kind":"official","path":"src/my_flash_modeling_llama.py","file_url":"https://github.com/bigai-nlco/cream/blob/HEAD/src/my_flash_modeling_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5c2707e010f48e5d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}