{"id":18439488,"url":"https://github.com/idiap/hypermixing","last_synced_at":"2025-04-15T03:42:35.986Z","repository":{"id":181504846,"uuid":"652500271","full_name":"idiap/hypermixing","owner":"idiap","description":"PyTorch implementation for HyperMixing, a linear-time token-mixing technique used in HyperMixer architecture","archived":false,"fork":false,"pushed_at":"2023-06-12T07:47:13.000Z","size":23,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-15T03:42:23.072Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSES/MIT.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-06-12T07:45:39.000Z","updated_at":"2025-02-11T18:17:32.000Z","dependencies_parsed_at":"2023-07-15T22:38:38.174Z","dependency_job_id":null,"html_url":"https://github.com/idiap/hypermixing","commit_stats":null,"previous_names":["idiap/hypermixing"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fhypermixing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fhypermixing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fhypermixing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fhypermixing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiap","download_url":"https://codeload.github.com/idiap/hypermixing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003936,"owners_count":21196794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T06:24:57.546Z","updated_at":"2025-04-15T03:42:35.968Z","avatar_url":"https://github.com/idiap.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nCopyright © \u003c2023\u003e Idiap Research Institute \u003ccontact@idiap.ch\u003e\n\nSPDX-FileContributor: Florian MAI \u003cflorian.ren.mai@googlemail.com\u003e\nSPDX-FileContributor: Arnaud Pannatier \u003carnaud.pannatier@idiap.ch\u003e\nSPDX-FileContributor: Fabio Fehr \u003cfabio.fehr@idiap.ch\u003e\nSPDX-FileContributor: Juan Pablo Zuluaga \u003cjuan-pablo.zuluaga@idiap.ch\u003e\n\nSPDX-License-Identifier: MIT\n--\u003e\n# HyperMixing\nHyperMixing is a token-mixing techniques to be used as linear-time alternative to attention, for example in Transformer-like architecture like [HyperMixer](https://arxiv.org/abs/2203.03691).\n\nThis repository serves as the unified PyTorch implementation for both [single-head hypermixing](https://arxiv.org/abs/2203.03691) and [multi-head-hypermixing](arxiv.org/abs/123).\n\n![Alt text](figures/hypermixing.png?raw=true \"HyperMixing Overview\")\n\n# Requirements\nCode was tested with:\n* Python 3.10\n* PyTorch 2.0\n\nYou can create an environment with the required dependencies by running\n\n```bash\nconda env create -f environment.yml\n```\n\n# Installation\n```bash\ncd hypermixing\npip install .\n```\n\n# Usage\n```python3\nimport torch\nfrom hypermixing import HyperMixing\n\ninput_dim = 128\nhypernet_size = 512\ntied = False\nnum_heads = 2\nmax_length = 3000\ntoken_mixer = HyperMixing(input_output_dim=input_dim,\n        hypernet_size=hypernet_size,\n        tied=tied,\n        num_heads=num_heads,\n        max_length=max_length)\n\nqueries = torch.randn((64, 50, 128)) # [bsize, num_queries, emb_dim]\nkeys = torch.randn((64, 25, 128)) # [bsize, num_keys, emb_dim]\nvalues = torch.randn((64, 25, 128)) # [bsize, num_keys, emb_dim]\nout = token_mixer(queries, keys, values) # [bsize, num_queries, emb_dim]\nassert out.size() == queries.size()\n```\n\n# Citation\nIf you use or build on HyperMixer, please cite the following papers:\n\n```latex\n@inproceedings{mai2023hypermixer,\n    author = {Mai, F. and Pannatier, A. and Fehr, F. and Chen, H. and Marelli, F. and Fleuret, F. and Henderson, J.},\n    title = {HyperMixer: An MLP-based Low Cost Alternative to Transformers},\n    booktitle = {Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},\n    year = {2023}\n}\n\n@article{mai2023multihead-hypermixer,\n    author={Mai, F. and Zuluaga-Gomez, J. and Parcollet, T. and Motlicek, P.},\n    title={HyperConformer: Multi-head HyperMixer for Efficient Speech Recognition},\n    booktitle = {Proc. Interspeech 2023},\n    year={2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiap%2Fhypermixing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiap%2Fhypermixing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiap%2Fhypermixing/lists"}