{"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/block-recurrent-transformers","title":"Block-Recurrent Transformers","arxiv_id":"2203.07852","date":"2022-03-11","proceeding":null,"authors":["DeLesley Hutchins","Imanol Schlag","Yuhuai Wu","Ethan Dyer","Behnam Neyshabur"],"abstract":"We introduce the Block-Recurrent Transformer, which applies a transformer layer in a recurrent fashion along a sequence, and has linear complexity with respect to sequence length. Our recurrent cell operates on blocks of tokens rather than single tokens during training, and leverages parallel computation within a block in order to make efficient use of accelerator hardware. The cell itself is strikingly simple. It is merely a transformer layer: it uses self-attention and cross-attention to efficiently compute a recurrent function over a large set of state vectors and tokens. Our design was inspired in part by LSTM cells, and it uses LSTM-style gates, but it scales the typical LSTM cell up by several orders of magnitude. Our implementation of recurrence has the same cost in both computation time and parameter count as a conventional transformer layer, but offers dramatically improved perplexity in language modeling tasks over very long sequences. Our model out-performs a long-range Transformer XL baseline by a wide margin, while running twice as fast. We demonstrate its effectiveness on PG19 (books), arXiv papers, and GitHub source code. Our code has been released as open source.","url_abs":"https://arxiv.org/abs/2203.07852v3","url_pdf":"https://arxiv.org/pdf/2203.07852v3.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":"block-recurrent-transformers","repo_url":"https://github.com/google-research/meliad","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"jax","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"block-recurrent-transformers","repo_url":"https://github.com/dashstander/block-recurrent-transformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"block-recurrent-transformers","repo_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch","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":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"lstm","method_name":"LSTM"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"sigmoid-activation","method_name":"Sigmoid Activation"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"tanh-activation","method_name":"Tanh Activation"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2203.07852","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2203.07852"}},"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/dashstander/block-recurrent-transformer","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/google-research/meliad","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran_draft_wrong":8,"ran":4,"ran_violates":3,"ran_honours":2,"ran_fixture":1,"unverified":5},"by_repo_kind":{"listed":{"samples":19,"ran":14,"repositories":2}},"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":4,"samples":[{"code_sha256_prefix":"039ac61b2d11642b","entry":"is_empty","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":2,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"039ac61b2d11642b"}},{"code_sha256_prefix":"b0bf82c667f91301","entry":"FeedForward","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b0bf82c667f91301"}},{"code_sha256_prefix":"c5c74119405bfc64","entry":"GEGLU","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c5c74119405bfc64"}},{"code_sha256_prefix":"f6fa422c7a33d41e","entry":"LayerNorm","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"f6fa422c7a33d41e"}},{"code_sha256_prefix":"778a8ddac6fbf372","entry":"MemoryManager","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"778a8ddac6fbf372"}},{"code_sha256_prefix":"c779f10c971c5655","entry":"RotaryEmbedding","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"c779f10c971c5655"}},{"code_sha256_prefix":"2b23ad0c970e5ae8","entry":"all_unique","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2b23ad0c970e5ae8"}},{"code_sha256_prefix":"a0a60756432aafb6","entry":"apply_rotary_pos_emb","repo":"dashstander/block-recurrent-transformer","repo_kind":"listed","path":"block_recurrent_transformer/transformer.py","file_url":"https://github.com/dashstander/block-recurrent-transformer/blob/HEAD/block_recurrent_transformer/transformer.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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a0a60756432aafb6"}},{"code_sha256_prefix":"a1f5fb7641bf7ce3","entry":"apply_rotary_pos_emb","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a1f5fb7641bf7ce3"}},{"code_sha256_prefix":"75e2de7f7799802d","entry":"cast_tuple","repo":"dashstander/block-recurrent-transformer","repo_kind":"listed","path":"block_recurrent_transformer/transformer.py","file_url":"https://github.com/dashstander/block-recurrent-transformer/blob/HEAD/block_recurrent_transformer/transformer.py","link_basis":"first_harvest_node","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":"75e2de7f7799802d"}},{"code_sha256_prefix":"c1b68cdd9e73316a","entry":"cast_tuple","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c1b68cdd9e73316a"}},{"code_sha256_prefix":"4a06bf1ac86f840a","entry":"compact","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"4a06bf1ac86f840a"}},{"code_sha256_prefix":"60fff7c3c400d7ff","entry":"default","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"60fff7c3c400d7ff"}},{"code_sha256_prefix":"5444a7d75d38878d","entry":"eval_decorator","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":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"5444a7d75d38878d"}},{"code_sha256_prefix":"aa5486a3650902d8","entry":"exists","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"aa5486a3650902d8"}},{"code_sha256_prefix":"41e347331d03a86c","entry":"gumbel_sample","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"41e347331d03a86c"}},{"code_sha256_prefix":"6b01a575e36ad18c","entry":"rotate_half","repo":"dashstander/block-recurrent-transformer","repo_kind":"listed","path":"block_recurrent_transformer/transformer.py","file_url":"https://github.com/dashstander/block-recurrent-transformer/blob/HEAD/block_recurrent_transformer/transformer.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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6b01a575e36ad18c"}},{"code_sha256_prefix":"39f3cec3c6be459f","entry":"top_k","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"39f3cec3c6be459f"}},{"code_sha256_prefix":"20f6b4952e3785e4","entry":"Attention","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"20f6b4952e3785e4"}},{"code_sha256_prefix":"46353ab6ce1236e2","entry":"AttentionBlock","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"46353ab6ce1236e2"}},{"code_sha256_prefix":"8c4ac9d79f99be7d","entry":"BlockRecurrentTransformer","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"8c4ac9d79f99be7d"}},{"code_sha256_prefix":"9278e73f426f6715","entry":"StateContainer","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"9278e73f426f6715"}},{"code_sha256_prefix":"54c65db65b0fbb51","entry":"safe_cat","repo":"lucidrains/block-recurrent-transformer-pytorch","repo_kind":"listed","path":"block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","file_url":"https://github.com/lucidrains/block-recurrent-transformer-pytorch/blob/HEAD/block_recurrent_transformer_pytorch/block_recurrent_transformer_pytorch.py","link_basis":"first_harvest_node","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":"54c65db65b0fbb51"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}