{"id":26280859,"url":"https://github.com/opensparsellms/mom","last_synced_at":"2025-05-07T05:10:30.087Z","repository":{"id":278306958,"uuid":"935180918","full_name":"OpenSparseLLMs/MoM","owner":"OpenSparseLLMs","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-21T06:35:10.000Z","size":1668,"stargazers_count":74,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-21T07:42:45.897Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenSparseLLMs.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,"zenodo":null}},"created_at":"2025-02-19T03:11:55.000Z","updated_at":"2025-04-21T06:35:14.000Z","dependencies_parsed_at":"2025-04-13T03:01:16.128Z","dependency_job_id":"6736d742-913d-4402-bc79-94efe7b4bd60","html_url":"https://github.com/OpenSparseLLMs/MoM","commit_stats":null,"previous_names":["opensparsellms/mom"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenSparseLLMs%2FMoM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenSparseLLMs%2FMoM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenSparseLLMs%2FMoM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenSparseLLMs%2FMoM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenSparseLLMs","download_url":"https://codeload.github.com/OpenSparseLLMs/MoM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252817631,"owners_count":21808706,"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":"2025-03-14T15:18:10.701Z","updated_at":"2025-05-07T05:10:30.080Z","avatar_url":"https://github.com/OpenSparseLLMs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# MoM: Mixture-of-Memories\n[![arXiv](https://img.shields.io/badge/Arxiv-2502.13685-b31b1b.svg?logo=arXiv)](https://arxiv.org/abs/2502.13685)\n[![huggingface weights](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Weights-ffc107?color=ffc107\u0026logoColor=white)](https://huggingface.co/linear-moe-hub)\n[![zhihu](https://img.shields.io/badge/Zhihu-Intro-blue?logo=zhihu)](https://zhuanlan.zhihu.com/p/25066090353)\n[![stars](https://img.shields.io/github/stars/OpenSparseLLMs/MoM)](https://github.com/OpenSparseLLMs/MoM/stargazers)\n\n\u003c/div\u003e\n\nWelcome to MoM! This repository provides the implementation of [MoM: Linear Sequence Modeling with Mixture-of-Memories](https://arxiv.org/abs/2502.13685), on huggingface eco-system. MoM is compatible with all kinds of linear sequence modeling methods like: linear attention, SSM, linear RNN, etc. **Here is an introductory artical about MoM (in Chinese) on [Zhihu](https://zhuanlan.zhihu.com/p/25066090353)**.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/mom_fig1.png\" width=\"65%\" /\u003e\n\u003c/p\u003e\n\u003cdiv align=\"center\"\u003e\nMoM Architecture\n\u003c/div\u003e\n\n## Installation\n\nThe following requirements should be satisfied:\n- [PyTorch](https://pytorch.org/) \u003e= 2.5\n- [Triton](https://github.com/openai/triton) \u003e=3.0\n- [einops](https://einops.rocks/)\n- [transformers](https://github.com/huggingface/transformers) \u003e=4.45.0\n- [datasets](https://github.com/huggingface/datasets) \u003e=3.3.0\n- [causal-conv1d](https://github.com/Dao-AILab/causal-conv1d) \u003e=1.4.0\n\nInstall the package from source:\n```bash\npip install -e .\n```\n\n## Getting Started\n\n### Data Preparation\nBefore training, make sure to preprocess your data by following the steps outlined in [training/README.md](training/README.md).\n\n### Training From Scratch\n\nTo start training with default setup, simply run:\n```bash\ncd training\n\nbash train.sh \\\n  nodes=4 \\\n  gpus=8 \\\n  type=mom \\\n  lr=3e-4 \\\n  steps=30720 \\\n  batch=8 \\\n  update=1 \\\n  warmup=1024 \\\n  context=2048 \\\n  path=SlimPajama/mom-15B \\\n  project=SlimPajama \\\n  model=configs/mom_340M.json \\\n  tokenizer=fla-hub/gla-1.3B-100B \\\n  data=SlimPajama-627B \\\n  cache=data/chunk1/train\n```\n\nYou can also\n- Modify the script to adjust the modeling and training settings.\n- e.g., modify [examples/configs/mom_340M.json](examples/configs/mom_340M.json) to adjust the MoM model structure.\n\n### Evaluation\n\nTo evaluate model checkpoints on **commonsense reasoning benchmarks**, we recommend you to run:\n```bash\nMODEL_PATH=training/SlimPajama/mom-15B/checkpoint-30720\n\naccelerate launch --multi_gpu evals/harness.py --model hf \\\n    --model_args pretrained=$MODEL_PATH,dtype=bfloat16 \\\n    --tasks arc_easy,arc_challenge,hellaswag,lambada_standard,piqa,winogrande,wikitext \\\n    --output_path eval_results \\\n    --batch_size 32 \\\n    --device cuda\n```\n\nTo evaluate model checkpoints on **recall-intensive tasks**, we recommend you to run:\n1. Install lm_eval\n```bash\ncd lm-eval-harness\npip install -e .\n```\n2. Run the script:\n```bash\nMODEL_PATH=../training/SlimPajama/mom-15B/checkpoint-30720\n\nCUDA_VISIBLE_DEVICES=0,1,2,3,4 python launch_local.py \\\n    --batch-size 32 \\\n    -t based_squad \\\n    -t based_swde \\\n    -t based_fda \\\n    -t based_drop \\\n    -t based_triviaqa \\\n    -t based_nq_2048 \\\n    -m $MODEL_PATH \\\n    --context_length 2048 \\\n    --answer_length 48 \\\n    --cutting_context \\\n    --limit -1 \\\n    -p\n```\n\n## Acknowledgement\nThis repo builds upon the open-source [flash-linear-attention](https://github.com/fla-org/flash-linear-attention) and the evaluation code is based on [prefix-linear-attention](https://github.com/HazyResearch/prefix-linear-attention). Happy experimenting! 🔥🚀🔥\n\n## Citation\nIf you find this repo useful, please consider citing our paper:\n```bib\n@article{du2025mom,\n  title={MoM: Linear Sequence Modeling with Mixture-of-Memories},\n  author={Du, Jusen and Sun, Weigao and Lan, Disen and Hu, Jiaxi and Cheng, Yu},\n  journal={arXiv preprint arXiv:2502.13685},\n  year={2025}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensparsellms%2Fmom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopensparsellms%2Fmom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopensparsellms%2Fmom/lists"}