{"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/hydra-bidirectional-state-space-models","title":"Hydra: Bidirectional State Space Models Through Generalized Matrix Mixers","arxiv_id":"2407.09941","date":"2024-07-13","proceeding":null,"authors":["Sukjun Hwang","Aakash Lahoti","Tri Dao","Albert Gu"],"abstract":"A wide array of sequence models are built on a framework modeled after Transformers, comprising alternating sequence mixer and channel mixer layers. This paper studies a unifying matrix mixer view of sequence mixers that can be conceptualized as a linear map on the input sequence. This framework encompasses a broad range of well-known sequence models, including the self-attention of Transformers as well as recent strong alternatives such as structured state space models (SSMs), and allows understanding downstream characteristics such as efficiency and expressivity through properties of their structured matrix class. We identify a key axis of matrix parameterizations termed sequence alignment, which increases the flexibility and performance of matrix mixers, providing insights into the strong performance of Transformers and recent SSMs such as Mamba. Furthermore, the matrix mixer framework offers a systematic approach to developing sequence mixers with desired properties, allowing us to develop several new sub-quadratic sequence models. In particular, we propose a natural bidirectional extension of the Mamba model (Hydra), parameterized as a quasiseparable matrix mixer, which demonstrates superior performance over other sequence models including Transformers on non-causal tasks. As a drop-in replacement for attention layers, Hydra outperforms BERT by 0.8 points on the GLUE benchmark and ViT by 2% Top-1 accuracy on ImageNet.","url_abs":"https://arxiv.org/abs/2407.09941v1","url_pdf":"https://arxiv.org/pdf/2407.09941v1.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":"hydra-bidirectional-state-space-models","repo_url":"https://github.com/goombalab/hydra","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"mamba","task_name":"Mamba"},{"task_slug":"state-space-models","task_name":"State Space Models"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bert","method_name":"BERT"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"hydra","method_name":"Hydra"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-linear-decay","method_name":"Linear Warmup With Linear Decay"},{"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":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2407.09941","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2407.09941"}},"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/goombalab/hydra","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":4,"unverified":6},"by_repo_kind":{"official":{"samples":10,"ran":4,"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":0,"samples":[{"code_sha256_prefix":"9d30f2c46fd5058c","entry":"build_tokenizer","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/text_data.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/text_data.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":"9d30f2c46fd5058c"}},{"code_sha256_prefix":"cf5a3cf27216350f","entry":"chunk_flip_join","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/modules/ops.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/modules/ops.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":"cf5a3cf27216350f"}},{"code_sha256_prefix":"0f0e92d1bd67e314","entry":"flip","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/modules/ops.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/modules/ops.py","link_basis":"first_harvest_node","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":"0f0e92d1bd67e314"}},{"code_sha256_prefix":"1586b639a5abd0b0","entry":"init_to_zero","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/flash_attn_triton.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/flash_attn_triton.py","link_basis":"plan_row","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":"1586b639a5abd0b0"}},{"code_sha256_prefix":"eb04bca046263ad3","entry":"build_dataloader","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/convert_dataset.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/convert_dataset.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":"eb04bca046263ad3"}},{"code_sha256_prefix":"926142a87d625531","entry":"build_hf_dataset","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/convert_dataset.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/convert_dataset.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":"926142a87d625531"}},{"code_sha256_prefix":"835f9b2b7b3d246e","entry":"dwconv","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/modules/ops.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/modules/ops.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":"835f9b2b7b3d246e"}},{"code_sha256_prefix":"b166dc11d0f54137","entry":"pad_input","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/bert_padding.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/bert_padding.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":"b166dc11d0f54137"}},{"code_sha256_prefix":"ee341a843ab02d5f","entry":"unpad_input","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/bert_padding.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/bert_padding.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":"ee341a843ab02d5f"}},{"code_sha256_prefix":"e7df9e4a71a03583","entry":"unpad_input_only","repo":"goombalab/hydra","repo_kind":"official","path":"hydra/bert/src/bert_padding.py","file_url":"https://github.com/goombalab/hydra/blob/HEAD/hydra/bert/src/bert_padding.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":"e7df9e4a71a03583"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}