{"id":23412523,"url":"https://github.com/beomi/infinitransformer","last_synced_at":"2025-04-06T01:09:03.266Z","repository":{"id":233091023,"uuid":"785617449","full_name":"Beomi/InfiniTransformer","owner":"Beomi","description":"Unofficial PyTorch/🤗Transformers(Gemma/Llama3) implementation of Leave No Context Behind: Efficient Infinite Context Transformers with Infini-attention","archived":false,"fork":false,"pushed_at":"2024-04-23T07:25:49.000Z","size":122,"stargazers_count":350,"open_issues_count":11,"forks_count":31,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-12-22T11:46:00.541Z","etag":null,"topics":["gemma","huggingface","infinitransformer","llama","llama3","pytorch","transformers"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2404.07143","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Beomi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-12T08:55:57.000Z","updated_at":"2024-12-18T09:53:48.000Z","dependencies_parsed_at":"2024-04-13T20:05:27.558Z","dependency_job_id":"df97220d-5b5b-4577-939b-1274d63afc13","html_url":"https://github.com/Beomi/InfiniTransformer","commit_stats":null,"previous_names":["beomi/infinitransformer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beomi%2FInfiniTransformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beomi%2FInfiniTransformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beomi%2FInfiniTransformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beomi%2FInfiniTransformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Beomi","download_url":"https://codeload.github.com/Beomi/InfiniTransformer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"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":["gemma","huggingface","infinitransformer","llama","llama3","pytorch","transformers"],"created_at":"2024-12-22T18:16:15.204Z","updated_at":"2025-04-06T01:09:03.252Z","avatar_url":"https://github.com/Beomi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InfiniTransformer\n\nUnofficial PyTorch/🤗Transformers implementation of Leave No Context Behind: Efficient Infinite Context Transformers with Infini-attention,\nwith Llama3 and Gemma model supported. (Llama 2 and 1 is also supported)\n\n- Paper Link: https://arxiv.org/abs/2404.07143\n\n## Two types of Implementation for Infini-Attention\n\n**Type I. Infini Attention in Model-wise, Trainer-wise**\n\n- Overrides modeling and config python files.\n- Full edit, Not compatible with basic HF trainer.\n- Need custom training code\n- Memory usage is **much lower** than SDPA(default) attention\n  - can train Gemma-2B with 32768 seq len(2048*16) on 2x H100 80G (with AdamW optimizer, No gradient checkpointing)\n  - can train Llama-3-8B with 1M seq len(2048*512) on 2x H100 80G (with Adafactor optimizer, no grad checkpointing)\n- Can train 'infinite' context -- check `train.gemma.infini.noclm.1Mseq.sh` with 1x H100 80G (with AdamW optimizer, No gradient checkpointing)\n\n**Type II. Infini Attention in Attention-Layer only**\n\n- Overrides modeling python file only, especially Attention layer only.\n- Minimal edit, fully compatible with HF(Trainer, etc)\n- Memory usage is ~eq with SDPA(default) attention\n  - can train Gemma-2B with 8192 seq len(128*64) on 2x H100 80G (with Adafactor Optimizer + Gradient Checkpointing)\n\n## How to use Type I. Infini Attention in Model-wise, Trainer-wise.\n\n### 1. Clone this repository\n\n```bash\ngit clone https://github.com/Beomi/InfiniTransformer\n```\n\n### 2. Install dependencies\n\n\u003e We need to install the latest version(`b109257f4f`) of 🤗Transformers from the source code.\n\n```bash\npip install -r requirements.txt\npip install -e git+https://github.com/huggingface/transformers.git@b109257f4f#egg=transformers\n# or just pip install transformers\n```\n\n### 3. Run the example(Inference, simple forward/backward test)\n\n```bash\npython test_basic.infini.py\n```\n\n### 4. Train with your data\n\nTrain Llama-3 1M seq len with 2K segment size, with [MiniPile Dataset](https://huggingface.co/datasets/JeanKaddour/minipile)\n\n```bash\n./train.llama.infini.noclm.1Mseq.sh\n```\n\nor\n\nTrain Gemma-2B 32K seq len with 2K segment size, with [WikiText2 Dataset](https://huggingface.co/datasets/wikitext)\n\n```bash\n./train.gemma.infini.noclm.sh\n```\n\nor\n\nTrain Gemma-2B  1M seq len with 2K segment size, with [MiniPile Dataset](https://huggingface.co/datasets/JeanKaddour/minipile)\n\n```bash\n./train.gemma.infini.noclm.1Mseq.sh\n```\n\n## How to use Type II. Infini Attention in Attention-Layer only\n\n### 1. Clone this repository\n\n```bash\ngit clone https://github.com/Beomi/InfiniTransformer\n```\n\n### 2. Install dependencies\n\n\u003e We need to install the latest version(`b109257f4f`) of 🤗Transformers from the source code.\n\n```bash\npip install -r requirements.txt\npip install -e git+https://github.com/huggingface/transformers.git@b109257f4f#egg=transformers\n```\n\n### 3. Remove original `modeling_gemma.py`, make a symbolic link with new `modeling_gemma.py`\n\n```bash\npython test_basic.infini.py\n```\n\n### 4. Run the example(Inference, simple forward/backward test)\n\n```bash\npython test_basic.py\n```\n\n### 5. Train with your data\n\n```bash\npython test_train.small.gemma.py\n```\n\n\u003cimg width=\"808\" alt=\"image\" src=\"https://github.com/Beomi/InfiniTransformer/assets/11323660/c3cb7b1e-531c-4652-a5de-fcf36b1c03bc\"\u003e\n\nExample code used wikitext-2-raw-v1 from https://huggingface.co/datasets/wikitext\n\nHere's the test wandb log here -\u003e https://api.wandb.ai/links/beomi2/1rsqrkfn\n\n### 6. Inference\n\n```bash\npython test_basic.trained.py\n```\n\n**Sample Generation w/ 1-epoch Trained Model on WikiText2**\n\nInput:\n\n\u003e This work introduces an efficient method to scale Transformer-based\n\nOutput1:\n\n\u003e models for denoising , denoising denoising , and deep denoising of images of the U2 EPK model , using a coefficient that is a function of the depth of the image resolution . The paper experiments with image denoising by Turbo @-@ based filtering , denoising by generative adversarial networks , and video denoising by denoising each of the three elements of the video ( color of the pixels / frames ) . The results are considered fair . The video is not discussed . The paper is not considering an actual application in an industrial context ,  line is probably a 1 . It is built in the Nohmi…\n\nOutput2:\n\n\u003e vision models across platforms using a custom architecture optimized for both vision ( 3D / 2D ) and vision and language . In other words , a single model can run on different types of devices , a feature that is critical for the development of general @-@ purpose and large-scale AI ( see also : The One @-@ Model @-@ for @-@ All @-@ Things @-@ AI Problem ) . The model is the first to reach a global scale ( 200 GPU + ) on a single GPU using the Transformer and its variants . The model can run at the end of 1967 . He had his family relocated to a house in a nearby neighborhood , where they lived for five years , before returning to their primary residence in St. Petersburg . Later comments of 1968 made by his fellow musician Bruce Hornsby made it clear that he had gone through a lot , both personally and professionally .\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeomi%2Finfinitransformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeomi%2Finfinitransformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeomi%2Finfinitransformer/lists"}