{"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/extending-context-window-of-large-language","title":"Extending Context Window of Large Language Models via Positional Interpolation","arxiv_id":"2306.15595","date":"2023-06-27","proceeding":null,"authors":["Shouyuan Chen","Sherman Wong","Liangjian Chen","Yuandong Tian"],"abstract":"We present Position Interpolation (PI) that extends the context window sizes of RoPE-based pretrained LLMs such as LLaMA models to up to 32768 with minimal fine-tuning (within 1000 steps), while demonstrating strong empirical results on various tasks that require long context, including passkey retrieval, language modeling, and long document summarization from LLaMA 7B to 65B. Meanwhile, the extended model by Position Interpolation preserve quality relatively well on tasks within its original context window. To achieve this goal, Position Interpolation linearly down-scales the input position indices to match the original context window size, rather than extrapolating beyond the trained context length which may lead to catastrophically high attention scores that completely ruin the self-attention mechanism. Our theoretical study shows that the upper bound of interpolation is at least $\\sim 600 \\times$ smaller than that of extrapolation, further demonstrating its stability. Models extended via Position Interpolation retain its original architecture and can reuse most pre-existing optimization and infrastructure.","url_abs":"https://arxiv.org/abs/2306.15595v2","url_pdf":"https://arxiv.org/pdf/2306.15595v2.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":"extending-context-window-of-large-language","repo_url":"https://github.com/chrisociepa/allamo","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"extending-context-window-of-large-language","repo_url":"https://github.com/hkunlp/chunkllama","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"extending-context-window-of-large-language","repo_url":"https://github.com/jzhang38/longmamba","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"extending-context-window-of-large-language","repo_url":"https://github.com/lululuyi/longheads","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"extending-context-window-of-large-language","repo_url":"https://github.com/pku-yuangroup/open-sora-plan","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"extending-context-window-of-large-language","repo_url":"https://github.com/yangjianxin1/longqlora","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"extending-context-window-of-large-language","repo_url":"https://github.com/ymcui/chinese-llama-alpaca-2","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"document-summarization","task_name":"Document Summarization"},{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":null,"task_name":"Position"},{"task_slug":"retrieval","task_name":"Retrieval"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2306.15595","atlas_url":"https://app.syntology.ai/?focus=2306.15595","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2306.15595"}},"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/yangjianxin1/longqlora","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/chrisociepa/allamo","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/pku-yuangroup/open-sora-plan","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/lululuyi/longheads","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ymcui/chinese-llama-alpaca-2","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/jzhang38/longmamba","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/hkunlp/chunkllama","reach":null}],"summary":{"ran_fixture":3,"ran":4,"ran_draft_wrong":4,"ran_honours":2,"unverified":2},"by_repo_kind":{"listed":{"samples":13,"ran":11,"repositories":5}},"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":8,"samples":[{"code_sha256_prefix":"f725bc2d76076485","entry":"apply_rotary_pos_emb","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"f725bc2d76076485"}},{"code_sha256_prefix":"adb0da12fb38486f","entry":"apply_rotary_pos_emb_for_relative_keys","repo":"lululuyi/longheads","repo_kind":"listed","path":"modeling_longheads/modeling_llama.py","file_url":"https://github.com/lululuyi/longheads/blob/HEAD/modeling_longheads/modeling_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"adb0da12fb38486f"}},{"code_sha256_prefix":"c168ab0101094c68","entry":"calculate_md5","repo":"chrisociepa/allamo","repo_kind":"listed","path":"allamo/train_utils.py","file_url":"https://github.com/chrisociepa/allamo/blob/HEAD/allamo/train_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c168ab0101094c68"}},{"code_sha256_prefix":"7cfe5dec1a04ab86","entry":"estimate_mfu","repo":"chrisociepa/allamo","repo_kind":"listed","path":"allamo/train_utils.py","file_url":"https://github.com/chrisociepa/allamo/blob/HEAD/allamo/train_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7cfe5dec1a04ab86"}},{"code_sha256_prefix":"24732fd7312ff4a8","entry":"evaluate","repo":"yangjianxin1/longqlora","repo_kind":"listed","path":"script/evaluate/evaluate.py","file_url":"https://github.com/yangjianxin1/longqlora/blob/HEAD/script/evaluate/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"24732fd7312ff4a8"}},{"code_sha256_prefix":"8fa7d4f410dbb734","entry":"format_seconds_as_time","repo":"chrisociepa/allamo","repo_kind":"listed","path":"allamo/train_utils.py","file_url":"https://github.com/chrisociepa/allamo/blob/HEAD/allamo/train_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8fa7d4f410dbb734"}},{"code_sha256_prefix":"b47f5a611055da10","entry":"generate_prompt","repo":"ymcui/chinese-llama-alpaca-2","repo_kind":"listed","path":"scripts/inference/inference_hf.py","file_url":"https://github.com/ymcui/chinese-llama-alpaca-2/blob/HEAD/scripts/inference/inference_hf.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b47f5a611055da10"}},{"code_sha256_prefix":"2a07d4a8772a06b1","entry":"generate_prompt_landmark","repo":"lululuyi/longheads","repo_kind":"listed","path":"passkey_retrieval/passkey_retrieval.py","file_url":"https://github.com/lululuyi/longheads/blob/HEAD/passkey_retrieval/passkey_retrieval.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2a07d4a8772a06b1"}},{"code_sha256_prefix":"94e2c02bdd3fbfa3","entry":"get_fn_init_data","repo":"chrisociepa/allamo","repo_kind":"listed","path":"allamo/model/lra.py","file_url":"https://github.com/chrisociepa/allamo/blob/HEAD/allamo/model/lra.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"94e2c02bdd3fbfa3"}},{"code_sha256_prefix":"f530e017034693d2","entry":"get_mscale","repo":"hkunlp/chunkllama","repo_kind":"listed","path":"chunkllama_attn_replace.py","file_url":"https://github.com/hkunlp/chunkllama/blob/HEAD/chunkllama_attn_replace.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":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f530e017034693d2"}},{"code_sha256_prefix":"51ee91de5e3fdcaa","entry":"iceildiv","repo":"yangjianxin1/longqlora","repo_kind":"listed","path":"script/evaluate/evaluate.py","file_url":"https://github.com/yangjianxin1/longqlora/blob/HEAD/script/evaluate/evaluate.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":"51ee91de5e3fdcaa"}},{"code_sha256_prefix":"1a574afcd22201fe","entry":"is_number_in_range","repo":"lululuyi/longheads","repo_kind":"listed","path":"passkey_retrieval/passkey_retrieval.py","file_url":"https://github.com/lululuyi/longheads/blob/HEAD/passkey_retrieval/passkey_retrieval.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1a574afcd22201fe"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"410511f95749dd69","entry":"merge_attn_outputs","repo":"hkunlp/chunkllama","repo_kind":"listed","path":"chunkllama_attn_replace.py","file_url":"https://github.com/hkunlp/chunkllama/blob/HEAD/chunkllama_attn_replace.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"410511f95749dd69"}},{"code_sha256_prefix":"41f1bbe0e5a8eaee","entry":"passkey_retrieval_test","repo":"lululuyi/longheads","repo_kind":"listed","path":"passkey_retrieval/passkey_retrieval.py","file_url":"https://github.com/lululuyi/longheads/blob/HEAD/passkey_retrieval/passkey_retrieval.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":"41f1bbe0e5a8eaee"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}