{"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/190410509","title":"Generating Long Sequences with Sparse Transformers","arxiv_id":"1904.10509","date":"2019-04-23","proceeding":"Preprint 2019 4","authors":["Rewon Child","Scott Gray","Alec Radford","Ilya Sutskever"],"abstract":"Transformers are powerful sequence models, but require time and memory that\ngrows quadratically with the sequence length. In this paper we introduce sparse\nfactorizations of the attention matrix which reduce this to $O(n \\sqrt{n})$. We\nalso introduce a) a variation on architecture and initialization to train\ndeeper networks, b) the recomputation of attention matrices to save memory, and\nc) fast attention kernels for training. We call networks with these changes\nSparse Transformers, and show they can model sequences tens of thousands of\ntimesteps long using hundreds of layers. We use the same architecture to model\nimages, audio, and text from raw bytes, setting a new state of the art for\ndensity modeling of Enwik8, CIFAR-10, and ImageNet-64. We generate\nunconditional samples that demonstrate global coherence and great diversity,\nand show it is possible in principle to use self-attention to model sequences\nof length one million or more.","url_abs":"http://arxiv.org/abs/1904.10509v1","url_pdf":"http://arxiv.org/pdf/1904.10509v1.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":"190410509","repo_url":"https://github.com/openai/sparse_attention","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok"}},{"paper_slug":"190410509","repo_url":"https://github.com/han-shi/SparseBERT","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"190410509","repo_url":"https://github.com/jonahwinninghoff/Text-Summarization","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"unanswered"}},{"paper_slug":"190410509","repo_url":"https://github.com/mistralai/mistral-src","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}},{"paper_slug":"190410509","repo_url":"https://github.com/ptillet/torch-blocksparse","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"190410509","repo_url":"https://github.com/wilson1yan/VideoGPT","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"190410509","repo_url":"https://github.com/MindCode-4/code-11/tree/main/factorized-attention","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"mindspore","reach":null}],"tasks":[{"task_slug":"diversity","task_name":"Diversity"},{"task_slug":"image-generation","task_name":"Image Generation"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"open-domain-question-answering","task_name":"Open-Domain Question Answering"},{"task_slug":"question-answering","task_name":"Question Answering"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"cosine-annealing","method_name":"Cosine Annealing"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-cosine-annealing","method_name":"Linear Warmup With Cosine Annealing"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"sparse-transformer","method_name":"Sparse Transformer"},{"method_slug":"weight-decay","method_name":"Weight Decay"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/audio-generation-on-classical-music-5-seconds","task":"Audio Generation","dataset":"Classical music, 5 seconds at 12 kHz","model":"Sparse Transformer 152M (strided)","rank_in_archive_order":1,"of":2,"metrics":{"Bits per byte":"1.97"},"uses_additional_data":false},{"leaderboard":"/sota/image-generation-on-imagenet-64x64","task":"Image Generation","dataset":"ImageNet 64x64","model":"Sparse Transformer 59M (strided)","rank_in_archive_order":43,"of":65,"metrics":{"Bits per dim":"3.44"},"uses_additional_data":false},{"leaderboard":"/sota/language-modelling-on-enwiki8","task":"Language Modelling","dataset":"enwik8","model":"Sparse Transformer (30 layers, fixed attn)","rank_in_archive_order":14,"of":42,"metrics":{"Bit per Character (BPC)":"0.99","Number of params":"95M"},"uses_additional_data":false},{"leaderboard":"/sota/open-domain-question-answering-on-searchqa","task":"Open-Domain Question Answering","dataset":"SearchQA","model":"Sparse Attention","rank_in_archive_order":4,"of":14,"metrics":{"EM":"64.7"},"uses_additional_data":false},{"leaderboard":"/sota/question-answering-on-natural-questions-long","task":"Question Answering","dataset":"Natural Questions (long)","model":"Sparse Attention","rank_in_archive_order":4,"of":13,"metrics":{"F1":"74.5"},"uses_additional_data":false},{"leaderboard":"/sota/question-answering-on-quasart-t","task":"Question Answering","dataset":"Quasart-T","model":"Sparse Attention","rank_in_archive_order":3,"of":7,"metrics":{"EM":"52.1"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=1904.10509","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"1904.10509"}},"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/han-shi/SparseBERT","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/mistralai/mistral-src","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ptillet/torch-blocksparse","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/wilson1yan/VideoGPT","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/MindCode-4/code-11/tree/main/factorized-attention","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/jonahwinninghoff/Text-Summarization","reach":{"status":"unanswered"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/openai/sparse_attention","reach":{"status":"ok"}}],"summary":{"ran":4,"ran_draft_wrong":1,"unverified":1},"by_repo_kind":{"listed":{"samples":6,"ran":5,"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":0,"samples":[{"code_sha256_prefix":"cc4d4565045cf844","entry":"DeepSpeedSparseSelfAttention","repo":"ptillet/torch-blocksparse","repo_kind":"listed","path":"torch_blocksparse/deepspeedsparseselfattention.py","file_url":"https://github.com/ptillet/torch-blocksparse/blob/HEAD/torch_blocksparse/deepspeedsparseselfattention.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":"cc4d4565045cf844"}},{"code_sha256_prefix":"21937d73418cc532","entry":"SparseAttention","repo":"wilson1yan/VideoGPT","repo_kind":"listed","path":"videogpt/attention.py","file_url":"https://github.com/wilson1yan/VideoGPT/blob/HEAD/videogpt/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"21937d73418cc532"}},{"code_sha256_prefix":"23a25a6d256367d8","entry":"SparsityConfig","repo":"ptillet/torch-blocksparse","repo_kind":"listed","path":"torch_blocksparse/deepspeedsparseselfattention.py","file_url":"https://github.com/ptillet/torch-blocksparse/blob/HEAD/torch_blocksparse/deepspeedsparseselfattention.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":"23a25a6d256367d8"}},{"code_sha256_prefix":"b5ef9bf53e62eab3","entry":"StridedSparsityConfig","repo":"wilson1yan/VideoGPT","repo_kind":"listed","path":"videogpt/attention.py","file_url":"https://github.com/wilson1yan/VideoGPT/blob/HEAD/videogpt/attention.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":"b5ef9bf53e62eab3"}},{"code_sha256_prefix":"9d35276799c65577","entry":"scaled_dot_product_attention","repo":"wilson1yan/VideoGPT","repo_kind":"listed","path":"videogpt/attention.py","file_url":"https://github.com/wilson1yan/VideoGPT/blob/HEAD/videogpt/attention.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9d35276799c65577"}},{"code_sha256_prefix":"9f28796c8276d371","entry":"view_range","repo":"wilson1yan/VideoGPT","repo_kind":"listed","path":"videogpt/attention.py","file_url":"https://github.com/wilson1yan/VideoGPT/blob/HEAD/videogpt/attention.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":"9f28796c8276d371"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}