{"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/ring-attention-with-blockwise-transformers","title":"Ring Attention with Blockwise Transformers for Near-Infinite Context","arxiv_id":"2310.01889","date":"2023-10-03","proceeding":null,"authors":["Hao liu","Matei Zaharia","Pieter Abbeel"],"abstract":"Transformers have emerged as the architecture of choice for many state-of-the-art AI models, showcasing exceptional performance across a wide range of AI applications. However, the memory demands imposed by Transformers limit their ability to handle long sequences, thereby posing challenges in utilizing videos, actions, and other long-form sequences and modalities in complex environments. We present a novel approach, Ring Attention with Blockwise Transformers (Ring Attention), which leverages blockwise computation of self-attention and feedforward to distribute long sequences across multiple devices while fully overlapping the communication of key-value blocks with the computation of blockwise attention. Our approach enables training and inference of sequences that are up to device count times longer than those achievable by prior memory-efficient Transformers, without resorting to approximations or incurring additional communication and computation overheads. Extensive experiments on language modeling and reinforcement learning tasks demonstrate the effectiveness of our approach in allowing millions of tokens context size and improving performance.","url_abs":"https://arxiv.org/abs/2310.01889v4","url_pdf":"https://arxiv.org/pdf/2310.01889v4.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":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/forhaoliu/ringattention","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"jax","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/chengzeyi/paraattention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"NOASSERTION"}},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/exists-forall/striped_attention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"jax","reach":null},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/haonan3/anchorcontext","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/jzhang38/EasyContext","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/sandai-org/magiattention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/seongho608/ringformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"ring-attention-with-blockwise-transformers","repo_url":"https://github.com/wan-video/wan2.1","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2310.01889","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2310.01889"}},"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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/exists-forall/striped_attention","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/seongho608/ringformer","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/haonan3/anchorcontext","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/jzhang38/EasyContext","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/forhaoliu/ringattention","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/wan-video/wan2.1","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/chengzeyi/paraattention","reach":{"status":"ok","spdx":"NOASSERTION"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/sandai-org/magiattention","reach":null}],"summary":{"ran":2,"ran_violates":3,"ran_draft_wrong":2,"ran_honours":3,"ran_fixture":3,"unverified":15},"by_repo_kind":{"official":{"samples":3,"ran":1,"repositories":1},"listed":{"samples":25,"ran":12,"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":0,"samples":[{"code_sha256_prefix":"7f87411d8cd00fb8","entry":"below_or_on_diag","repo":"forhaoliu/ringattention","repo_kind":"official","path":"ringattention/ringattention_jax.py","file_url":"https://github.com/forhaoliu/ringattention/blob/HEAD/ringattention/ringattention_jax.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7f87411d8cd00fb8"}},{"code_sha256_prefix":"a41cb31b42e919b1","entry":"calc_same_padding","repo":"seongho608/ringformer","repo_kind":"listed","path":"conformer/conformer.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/conformer/conformer.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a41cb31b42e919b1"}},{"code_sha256_prefix":"2e94fa2078ca5f7c","entry":"construct_prompt","repo":"jzhang38/EasyContext","repo_kind":"listed","path":"eval_needle.py","file_url":"https://github.com/jzhang38/EasyContext/blob/HEAD/eval_needle.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"2e94fa2078ca5f7c"}},{"code_sha256_prefix":"59ae0708b1e8d94b","entry":"convert_pad_shape","repo":"seongho608/ringformer","repo_kind":"listed","path":"commons.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/commons.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"59ae0708b1e8d94b"}},{"code_sha256_prefix":"60fff7c3c400d7ff","entry":"default","repo":"seongho608/ringformer","repo_kind":"listed","path":"conformer/conformer.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/conformer/conformer.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"60fff7c3c400d7ff"}},{"code_sha256_prefix":"aa5486a3650902d8","entry":"exists","repo":"seongho608/ringformer","repo_kind":"listed","path":"conformer/conformer.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/conformer/conformer.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"aa5486a3650902d8"}},{"code_sha256_prefix":"a26f85d7c72ef39a","entry":"get_padding","repo":"seongho608/ringformer","repo_kind":"listed","path":"commons.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/commons.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a26f85d7c72ef39a"}},{"code_sha256_prefix":"83526663aea6f3a5","entry":"load_haystack","repo":"jzhang38/EasyContext","repo_kind":"listed","path":"eval_needle.py","file_url":"https://github.com/jzhang38/EasyContext/blob/HEAD/eval_needle.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"83526663aea6f3a5"}},{"code_sha256_prefix":"8ba2ad2a8cd08a1e","entry":"new_decoder_forward","repo":"haonan3/anchorcontext","repo_kind":"listed","path":"anchor_context/ulysses_attn/monkey_patch.py","file_url":"https://github.com/haonan3/anchorcontext/blob/HEAD/anchor_context/ulysses_attn/monkey_patch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8ba2ad2a8cd08a1e"}},{"code_sha256_prefix":"5bc133115aa98fa4","entry":"permute_tokens","repo":"exists-forall/striped_attention","repo_kind":"listed","path":"bpt.py","file_url":"https://github.com/exists-forall/striped_attention/blob/HEAD/bpt.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5bc133115aa98fa4"}},{"code_sha256_prefix":"50fa7e0250016b3d","entry":"reorder_before_reduce_scatter","repo":"sandai-org/magiattention","repo_kind":"listed","path":"exps/dist_attn/baselines/ring_attn.py","file_url":"https://github.com/sandai-org/magiattention/blob/HEAD/exps/dist_attn/baselines/ring_attn.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"50fa7e0250016b3d"}},{"code_sha256_prefix":"70a7614b3b3eb41f","entry":"unconstrained_rational_quadratic_spline","repo":"seongho608/ringformer","repo_kind":"listed","path":"transforms.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/transforms.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":"70a7614b3b3eb41f"}},{"code_sha256_prefix":"987eb0efeb759f2b","entry":"unpermute_outputs","repo":"exists-forall/striped_attention","repo_kind":"listed","path":"bpt.py","file_url":"https://github.com/exists-forall/striped_attention/blob/HEAD/bpt.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"987eb0efeb759f2b"}},{"code_sha256_prefix":"896f7aae82a62114","entry":"discriminator_loss","repo":"seongho608/ringformer","repo_kind":"listed","path":"losses.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/losses.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"896f7aae82a62114"}},{"code_sha256_prefix":"24e8b4731dc3e070","entry":"feature_loss","repo":"seongho608/ringformer","repo_kind":"listed","path":"losses.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/losses.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"24e8b4731dc3e070"}},{"code_sha256_prefix":"24313489651a82bb","entry":"generate_cu_seqlens_kv_ag_causal","repo":"sandai-org/magiattention","repo_kind":"listed","path":"exps/dist_attn/baselines/ring_attn.py","file_url":"https://github.com/sandai-org/magiattention/blob/HEAD/exps/dist_attn/baselines/ring_attn.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":"24313489651a82bb"}},{"code_sha256_prefix":"c01a3efb274ff778","entry":"intersperse","repo":"seongho608/ringformer","repo_kind":"listed","path":"commons.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/commons.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c01a3efb274ff778"}},{"code_sha256_prefix":"79242eb900957f26","entry":"latest_checkpoint_path","repo":"seongho608/ringformer","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"79242eb900957f26"}},{"code_sha256_prefix":"2ad367dd5097b12f","entry":"load_checkpoint","repo":"seongho608/ringformer","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2ad367dd5097b12f"}},{"code_sha256_prefix":"9543346026e2f58e","entry":"phase_loss","repo":"seongho608/ringformer","repo_kind":"listed","path":"losses.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/losses.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9543346026e2f58e"}},{"code_sha256_prefix":"ba6cafc4d658c14f","entry":"piecewise_rational_quadratic_transform","repo":"seongho608/ringformer","repo_kind":"listed","path":"transforms.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/transforms.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ba6cafc4d658c14f"}},{"code_sha256_prefix":"c486bdb7634db737","entry":"ring_attention","repo":"exists-forall/striped_attention","repo_kind":"listed","path":"bpt.py","file_url":"https://github.com/exists-forall/striped_attention/blob/HEAD/bpt.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":"c486bdb7634db737"}},{"code_sha256_prefix":"b9b682336560ca14","entry":"ring_attention","repo":"forhaoliu/ringattention","repo_kind":"official","path":"ringattention/ringattention_jax.py","file_url":"https://github.com/forhaoliu/ringattention/blob/HEAD/ringattention/ringattention_jax.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":"b9b682336560ca14"}},{"code_sha256_prefix":"157e6d4b3de1fc27","entry":"ring_attention_inference","repo":"forhaoliu/ringattention","repo_kind":"official","path":"ringattention/ringattention_jax_inference.py","file_url":"https://github.com/forhaoliu/ringattention/blob/HEAD/ringattention/ringattention_jax_inference.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":"157e6d4b3de1fc27"}},{"code_sha256_prefix":"492b11f3eb615458","entry":"scan_checkpoint","repo":"seongho608/ringformer","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"492b11f3eb615458"}},{"code_sha256_prefix":"e85d747983c4f5d8","entry":"searchsorted","repo":"seongho608/ringformer","repo_kind":"listed","path":"transforms.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/transforms.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e85d747983c4f5d8"}},{"code_sha256_prefix":"6f15bd47f3cbb1ef","entry":"stft","repo":"seongho608/ringformer","repo_kind":"listed","path":"stft.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/stft.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6f15bd47f3cbb1ef"}},{"code_sha256_prefix":"0c0b5a033fe98758","entry":"weight_norm_modules","repo":"seongho608/ringformer","repo_kind":"listed","path":"attentions.py","file_url":"https://github.com/seongho608/ringformer/blob/HEAD/attentions.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0c0b5a033fe98758"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}