{"id":16328672,"url":"https://github.com/Victorwz/LongMem","last_synced_at":"2025-10-25T21:30:38.491Z","repository":{"id":174962961,"uuid":"652523482","full_name":"Victorwz/LongMem","owner":"Victorwz","description":"Official implementation of our NeurIPS 2023 paper \"Augmenting Language Models with Long-Term Memory\". ","archived":false,"fork":false,"pushed_at":"2024-03-30T22:24:38.000Z","size":16181,"stargazers_count":760,"open_issues_count":12,"forks_count":68,"subscribers_count":24,"default_branch":"main","last_synced_at":"2024-10-11T23:15:29.020Z","etag":null,"topics":["large-language-models","long-context-modeling","long-term-memory"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2306.07174","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Victorwz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-06-12T08:44:19.000Z","updated_at":"2024-10-10T07:33:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"dc506ccb-7495-4cba-9a03-d4ca06c59963","html_url":"https://github.com/Victorwz/LongMem","commit_stats":null,"previous_names":["victorwz/longmem"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorwz%2FLongMem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorwz%2FLongMem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorwz%2FLongMem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorwz%2FLongMem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Victorwz","download_url":"https://codeload.github.com/Victorwz/LongMem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238212319,"owners_count":19434942,"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":["large-language-models","long-context-modeling","long-term-memory"],"created_at":"2024-10-10T23:14:27.577Z","updated_at":"2025-10-25T21:30:36.018Z","avatar_url":"https://github.com/Victorwz.png","language":"Python","funding_links":[],"categories":["Python","🔢 Papers - Parametric Memory"],"sub_categories":["🎥 Multimodal Memory (for Generation)"],"readme":"# LongMem\n\nOfficial implementation of our paper \"[Augmenting Language Models with Long-Term Memory](https://arxiv.org/abs//2306.07174)\".\n\nPlease cite our paper if you find this repository interesting or helpful:\n```bibtex\n@article{LongMem,\n  title={Augmenting Language Models with Long-Term Memory},\n  author={Wang, Weizhi and Dong, Li and Cheng, Hao and Liu, Xiaodong and Yan, Xifeng and Gao, Jianfeng and Wei, Furu},\n  journal={arXiv preprint arXiv:2306.07174},\n  year={2023}\n}\n```\n\n## Environment Setup \n* torch: Please follow [torch official installation guide](https://pytorch.org/get-started/previous-versions/). We recommend torch\u003e=1.8.0. Please select the torch-gpu version which is consistent with your cuda driver version.\n\n* Faiss-GPU: For Nvidia V100 GPUs, simply install via ``pip install faiss-gpu``. For Nvidia A100, A6000 GPUs, please run ``conda install faiss-gpu cudatoolkit=11.0 -c pytorch``. The A100 GPU is not officially supported by faiss-gpu, sometimes it will lead to errors, you can refer to this git [issue](https://github.com/facebookresearch/faiss/issues/2064) of faiss for help.\n\n* fairseq: ``pip install --editable ./fairseq`` Then the revised `fairseq` and dependency packages will be installed. We strongly recommend you to use python 3.8 for stability.\n\n* other packages: ``pip install -r requirements.txt``\n\n## Project Structure\n* Pre-trained LLM Class (L24, E1024, Alibi positional embedding): [`fairseq/fairseq/models/newgpt.py`](fairseq/fairseq/models/newgpt.py)\n\n* Transformer Decoder with SideNetwork (L12, E1024): [`fairseq/fairseq/models/sidenet/transformer_decoder_sidenet.py`](fairseq/fairseq/models/sidenet/transformer_decoder_sidenet.py)\n\n* Transformer Language Model with SideNetwork Class: [`fairseq/fairseq/models/transformer_lm_sidenet.py`](fairseq/fairseq/models/transformer_lm_sidenet.py)\n\n* Memory Bank and Retrieval: [`fairseq/fairseq/modules/dynamic_memory_with_chunk.py`](fairseq/fairseq/modules/dynamic_memory_with_chunk.py)\n\n* Joint Attention for Memory Fusion: [`fairseq/fairseq/modules/joint_multihead_attention_sum.py`](fairseq/fairseq/modules/joint_multihead_attention_sum.py)\n\n## Memory-Augmented Adaptation Training\n### Data collection and Preprocessing\nPlease download the Pile from [official release](https://pile.eleuther.ai/). Each sub-dataset in the Pile is organized as various jsonline splits. You can refer to [`preprocess/filter_shard_tnlg.py`](preprocess/filter_shard_tnlg.py) fpr how we sample the training set and binalize following standard fairseq preprocessing process.\n\nMemory-Augmented Adaptation Training:\n```\nbash train_scripts/train_longmem.sh\n```\n\n## Evaluation\nPlease firstly download the checkpoints for pre-trained [GPT2-medium model and LongMem model](https://huggingface.co/weizhiwang/LongMem-558M) to ``checkpoints/``.\n\n### Memory-Augmented In-Context Learning\n```\n# Evaluate gpt2 baseline\npython eval_scripts/eval_longmem_icl.py --path /path/to/gpt2_pretrained_model\n# Evaluate LongMem model\npython eval_scripts/eval_longmem_icl.py --path /path/to/longmem_model --pretrained-model-path /path/to/gpt2_pretrained_model\n```\n\n## Credits\nLongMem is developed based on [fairseq](https://github.com/facebookresearch/fairseq). Thanks to the team from eleuther.ai who constructed the largest high-quality corpora, the Pile.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorwz%2FLongMem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVictorwz%2FLongMem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorwz%2FLongMem/lists"}